diff --git a/runner/__init__.py b/runner/__init__.py index 678fd36..d82c2de 100644 --- a/runner/__init__.py +++ b/runner/__init__.py @@ -146,7 +146,7 @@ def pytest_exception_interact(self, node, call, report): err = excinfo.getrepr(style="no", abspath=False) # trim off full traceback for first exercise to be friendlier and clearer - if 'Lasagna' in node.name and 'ImportError' in str(err.chain[0]): + if 'lasagna' in node.name and 'ImportError' in str(err.chain[0]): trace = err.chain[-2][0] else: trace = err.chain[-1][0] diff --git a/test/example-lasagna-constant-import-error/example_lasagna_constant_import_error.py b/test/example-lasagna-constant-import-error/example_lasagna_constant_import_error.py new file mode 100644 index 0000000..b08e1a7 --- /dev/null +++ b/test/example-lasagna-constant-import-error/example_lasagna_constant_import_error.py @@ -0,0 +1,30 @@ +"""Functions used in preparing Guido's gorgeous lasagna. + +Learn about Guido, the creator of the Python language: https://en.wikipedia.org/wiki/Guido_van_Rossum +""" + +# TODO: define the 'EXPECTED_BAKE_TIME' constant +# TODO: consider defining the 'PREPARATION_TIME' constant +# equal to the time it takes to prepare a single layer + + +# TODO: define the 'bake_time_remaining()' function +def bake_time_remaining(): + """Calculate the bake time remaining. + + :param elapsed_bake_time: int - baking time already elapsed. + :return: int - remaining bake time (in minutes) derived from 'EXPECTED_BAKE_TIME'. + + Function that takes the actual minutes the lasagna has been in the oven as + an argument and returns how many minutes the lasagna still needs to bake + based on the `EXPECTED_BAKE_TIME`. + """ + + pass + + +# TODO: define the 'preparation_time_in_minutes()' function +# and consider using 'PREPARATION_TIME' here + + +# TODO: define the 'elapsed_time_in_minutes()' function diff --git a/test/example-lasagna-constant-import-error/example_lasagna_constant_import_error_test.py b/test/example-lasagna-constant-import-error/example_lasagna_constant_import_error_test.py new file mode 100644 index 0000000..2a3b326 --- /dev/null +++ b/test/example-lasagna-constant-import-error/example_lasagna_constant_import_error_test.py @@ -0,0 +1,26 @@ +import unittest +import pytest + +# For this first exercise, it is really important to be clear about how we are importing names for tests. +# To that end, we are putting a try/catch around imports and throwing specific messages to help students +# decode that they need to create and title their constants and functions in a specific way. +try: + from example_lasagna_constant_import_error import (EXPECTED_BAKE_TIME, + bake_time_remaining, + preparation_time_in_minutes, + elapsed_time_in_minutes) + +# Here, we are separating the constant import errors from the function name import errors +except ImportError as import_fail: + message = import_fail.args[0].split('(', maxsplit=1) + item_name = import_fail.args[0].split()[3] + + if 'EXPECTED_BAKE_TIME' in item_name: + # pylint: disable=raise-missing-from + raise ImportError(f'\n\nMISSING CONSTANT --> \nWe can not find or import the constant {item_name} in your' + " 'lasagna.py' file.\nDid you misname or forget to define it?") from None + else: + item_name = item_name[:-1] + "()'" + # pylint: disable=raise-missing-from + raise ImportError("\n\nMISSING FUNCTION --> In your 'lasagna.py' file, we can not find or import the" + f' function named {item_name}. \nDid you misname or forget to define it?') from None diff --git a/test/example-lasagna-constant-import-error/results.json b/test/example-lasagna-constant-import-error/results.json new file mode 100644 index 0000000..6e9344b --- /dev/null +++ b/test/example-lasagna-constant-import-error/results.json @@ -0,0 +1,6 @@ +{ + "version": 3, + "status": "error", + "message": "ImportError: \n\nMISSING CONSTANT --> \nWe can not find or import the constant 'EXPECTED_BAKE_TIME' in your 'lasagna.py' file.\nDid you misname or forget to define it?", + "tests": [] +} \ No newline at end of file diff --git a/test/example-lasagna-function-import-error/example_lasagna_function_import_error.py b/test/example-lasagna-function-import-error/example_lasagna_function_import_error.py new file mode 100644 index 0000000..82bf29e --- /dev/null +++ b/test/example-lasagna-function-import-error/example_lasagna_function_import_error.py @@ -0,0 +1,23 @@ +"""Functions used in preparing Guido's gorgeous lasagna. + +Learn about Guido, the creator of the Python language: https://en.wikipedia.org/wiki/Guido_van_Rossum +""" + + +EXPECTED_BAKE_TIME = 40 +PREPARATION_TIME = 2 + + +# TODO: define the 'bake_time_remaining()' function (misspelled here on purpose) +def bake_time(): + """Calculate the bake time remaining. + + :param elapsed_bake_time: int - baking time already elapsed. + :return: int - remaining bake time (in minutes) derived from 'EXPECTED_BAKE_TIME'. + + Function that takes the actual minutes the lasagna has been in the oven as + an argument and returns how many minutes the lasagna still needs to bake + based on the `EXPECTED_BAKE_TIME`. + """ + + pass diff --git a/test/example-lasagna-function-import-error/example_lasagna_function_import_error_test.py b/test/example-lasagna-function-import-error/example_lasagna_function_import_error_test.py new file mode 100644 index 0000000..81d6bfb --- /dev/null +++ b/test/example-lasagna-function-import-error/example_lasagna_function_import_error_test.py @@ -0,0 +1,26 @@ +import unittest +import pytest + +# For this first exercise, it is really important to be clear about how we are importing names for tests. +# To that end, we are putting a try/catch around imports and throwing specific messages to help students +# decode that they need to create and title their constants and functions in a specific way. +try: + from example_lasagna_function_import_error import (EXPECTED_BAKE_TIME, + bake_time_remaining, + preparation_time_in_minutes, + elapsed_time_in_minutes) + +# Here, we are separating the constant import errors from the function name import errors +except ImportError as import_fail: + message = import_fail.args[0].split('(', maxsplit=1) + item_name = import_fail.args[0].split()[3] + + if 'EXPECTED_BAKE_TIME' in item_name: + # pylint: disable=raise-missing-from + raise ImportError(f'\n\nMISSING CONSTANT --> \nWe can not find or import the constant {item_name} in your' + " 'lasagna.py' file.\nDid you misname or forget to define it?") from None + else: + item_name = item_name[:-1] + "()'" + # pylint: disable=raise-missing-from + raise ImportError("\n\nMISSING FUNCTION --> In your 'lasagna.py' file, we can not find or import the" + f' function named {item_name}. \nDid you misname or forget to define it?') from None diff --git a/test/example-lasagna-function-import-error/results.json b/test/example-lasagna-function-import-error/results.json new file mode 100644 index 0000000..8883165 --- /dev/null +++ b/test/example-lasagna-function-import-error/results.json @@ -0,0 +1,6 @@ +{ + "version": 3, + "status": "error", + "message": "ImportError: \n\nMISSING FUNCTION --> In your 'lasagna.py' file, we can not find or import the function named 'bake_time_remaining()'. \nDid you misname or forget to define it?", + "tests": [] +} \ No newline at end of file