Skip to content

Commit

Permalink
Added hello world import error test.
Browse files Browse the repository at this point in the history
  • Loading branch information
BethanyG committed Mar 3, 2023
1 parent 195b0b5 commit c7677cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print("Hello, World!")

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)
6 changes: 6 additions & 0 deletions test/example-hello-world-function-import-error/results.json
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": []
}

0 comments on commit c7677cd

Please sign in to comment.