-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new goldenfile tests for lasagna import errors.
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
test/example-lasagna-constant-import-error/example_lasagna_constant_import_error.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
26 changes: 26 additions & 0 deletions
26
test/example-lasagna-constant-import-error/example_lasagna_constant_import_error_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} |
23 changes: 23 additions & 0 deletions
23
test/example-lasagna-function-import-error/example_lasagna_function_import_error.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
26 changes: 26 additions & 0 deletions
26
test/example-lasagna-function-import-error/example_lasagna_function_import_error_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} |