exercism.org/python/hello-world/hello_world_test.py

31 lines
1.1 KiB
Python
Raw Normal View History

2024-03-24 18:34:11 +01:00
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/hello-world/canonical-data.json
# File last updated on 2023-07-19
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)