Created
March 5, 2017 11:58
-
-
Save Nikitaw99/f35d7944aedfc13ab39821592a97ede4 to your computer and use it in GitHub Desktop.
testing `unittest`
This file contains hidden or 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
def say_hi(name='World'): | |
if name == None or name == '': | |
name = "World" | |
if type(name) != str: | |
name = str(name) | |
return f"Hello, {name}!" |
This file contains hidden or 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
import unittest | |
import test | |
class HelloTest(unittest.TestCase): | |
def test_no_arg(self): | |
self.assertEqual(test.say_hi(), "Hello, World!") | |
def test_none(self): | |
self.assertEqual(test.say_hi(None), "Hello, World!") | |
def test_number(self): | |
self.assertEqual(test.say_hi(413), "Hello, 413!") | |
def test_bool(self): | |
self.assertEqual(test.say_hi(True), "Hello, True!") | |
def test_alice(self): | |
self.assertEqual(test.say_hi("Alice"), "Hello, Alice!") | |
def test_empty(self): | |
self.assertEqual(test.say_hi(''), "Hello, World!") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment