Skip to content

Commit c7677cd

Browse files
committed
Added hello world import error test.
1 parent 195b0b5 commit c7677cd

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print("Hello, World!")
2+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import unittest
2+
3+
try:
4+
from hello_world import (
5+
hello,
6+
)
7+
8+
except ImportError as import_fail:
9+
message = import_fail.args[0].split("(", maxsplit=1)
10+
item_name = import_fail.args[0].split()[3]
11+
12+
item_name = item_name[:-1] + "()'"
13+
14+
# pylint: disable=raise-missing-from
15+
raise ImportError(
16+
"\n\nMISSING FUNCTION --> In your 'hello_world.py' file, we can not find or import the"
17+
f" function named {item_name}. \nThe tests for this first exercise expect a function that"
18+
f' returns the string "Hello, World!"'
19+
f'\n\nDid you use print("Hello, World!") instead?'
20+
) from None
21+
22+
23+
class HelloWorldTest(unittest.TestCase):
24+
def test_say_hi(self):
25+
msg = "\n\nThis test expects a return of the string 'Hello, World!' \nDid you use print('Hello, World!') by mistake?"
26+
self.assertEqual(hello(), "Hello, World!", msg=msg)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": 3,
3+
"status": "error",
4+
"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?",
5+
"tests": []
6+
}

0 commit comments

Comments
 (0)