-
-
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 hello world import error test.
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
test/example-hello-world-function-import-error/example_hello_world_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,2 @@ | ||
print("Hello, World!") | ||
|
26 changes: 26 additions & 0 deletions
26
...ample-hello-world-function-import-error/example_hello_world_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 | ||
|
||
try: | ||
from hello_world import ( | ||
hello, | ||
) | ||
|
||
except ImportError as import_fail: | ||
message = import_fail.args[0].split("(", maxsplit=1) | ||
item_name = import_fail.args[0].split()[3] | ||
|
||
item_name = item_name[:-1] + "()'" | ||
|
||
# pylint: disable=raise-missing-from | ||
raise ImportError( | ||
"\n\nMISSING FUNCTION --> In your 'hello_world.py' file, we can not find or import the" | ||
f" function named {item_name}. \nThe tests for this first exercise expect a function that" | ||
f' returns the string "Hello, World!"' | ||
f'\n\nDid you use print("Hello, World!") instead?' | ||
) from None | ||
|
||
|
||
class HelloWorldTest(unittest.TestCase): | ||
def test_say_hi(self): | ||
msg = "\n\nThis test expects a return of the string 'Hello, World!' \nDid you use print('Hello, World!') by mistake?" | ||
self.assertEqual(hello(), "Hello, World!", msg=msg) |
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 'hello_world.py' file, we can not find or import the function named 'hello_world()'. \nThe tests for this first exercise expect a function that returns the string \"Hello, World!\"\n\nDid you use print(\"Hello, World!\") instead?", | ||
"tests": [] | ||
} |