Skip to content

Commit 5e8951a

Browse files
committed
Addressed issues 3181 and 3161 for lasagna test file.
1 parent c896707 commit 5e8951a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

exercises/concept/guidos-gorgeous-lasagna/lasagna_test.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
import unittest
22
import pytest
33

4-
4+
# For this first exercise, it is really important to be clear about how we are importing names for tests.
5+
# To that end, we are putting a try/catch around imports and throwing specific messages to help students
6+
# decode that they need to create and title their constants and functions in a specific way.
57
try:
68
from lasagna import (EXPECTED_BAKE_TIME,
79
bake_time_remaining,
810
preparation_time_in_minutes,
911
elapsed_time_in_minutes)
1012

11-
13+
# Here, we are separating the constant import errors from the function name import errors
1214
except ImportError as import_fail:
1315
message = import_fail.args[0].split('(', maxsplit=1)
1416
item_name = import_fail.args[0].split()[3]
1517

16-
if 'EXPECTED_BAKE_TIME' in message:
18+
if 'EXPECTED_BAKE_TIME' in item_name:
1719
# pylint: disable=raise-missing-from
18-
raise ImportError(f'We can not find or import the constant {item_name} in your'
19-
" 'lasagna.py' file. Did you mis-name or forget to define it?")
20+
raise ImportError(f'\n\nMISSING CONSTANT --> \nWe can not find or import the constant {item_name} in your'
21+
" 'lasagna.py' file.\nDid you mis-name or forget to define it?") from None
2022
else:
2123
item_name = item_name[:-1] + "()'"
2224
# pylint: disable=raise-missing-from
23-
raise ImportError("In your 'lasagna.py' file, we can not find or import the"
24-
f' function named {item_name}. Did you mis-name or forget to define it?')
25+
raise ImportError("\n\nMISSING FUNCTION --> In your 'lasagna.py' file, we can not find or import the"
26+
f' function named {item_name}. \nDid you mis-name or forget to define it?') from None
2527

2628

29+
# Here begins the formal test cases for the exercise.
2730
class LasagnaTest(unittest.TestCase):
2831

2932
@pytest.mark.task(taskno=1)
@@ -64,9 +67,16 @@ def test_elapsed_time_in_minutes(self):
6467

6568
@pytest.mark.task(taskno=5)
6669
def test_docstrings_were_written(self):
70+
"""Validate function.__doc__ exists for each function.
71+
Check the attribute dictionary of each listed function
72+
for the presence of a __doc__ key.
73+
74+
:return: unexpectedly None error when __doc__ key is missing.
75+
"""
6776
functions = [bake_time_remaining, preparation_time_in_minutes, elapsed_time_in_minutes]
6877

6978
for variant, function in enumerate(functions, start=1):
7079
with self.subTest(f'variation #{variant}', function=function):
7180
failure_msg = f'Expected a docstring for `{function.__name__}`, but received `None` instead.'
81+
# Check that the __doc__ key is populated for the function.
7282
self.assertIsNotNone(function.__doc__, msg=failure_msg)

0 commit comments

Comments
 (0)