Skip to content

Instantly share code, notes, and snippets.

@Nikitaw99
Created March 5, 2017 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikitaw99/f35d7944aedfc13ab39821592a97ede4 to your computer and use it in GitHub Desktop.
Save Nikitaw99/f35d7944aedfc13ab39821592a97ede4 to your computer and use it in GitHub Desktop.
testing `unittest`
def say_hi(name='World'):
if name == None or name == '':
name = "World"
if type(name) != str:
name = str(name)
return f"Hello, {name}!"
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