diff options
Diffstat (limited to 'docs/source/examples/greeter.py')
-rwxr-xr-x | docs/source/examples/greeter.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/source/examples/greeter.py b/docs/source/examples/greeter.py index 5a978f4..32d739f 100755 --- a/docs/source/examples/greeter.py +++ b/docs/source/examples/greeter.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import hazwaz +import hazwaz.unittest class World(hazwaz.Command): @@ -26,6 +27,27 @@ class Individual(hazwaz.Command): print("Hello {}".format(self.args.gretee)) +class TestGreeter(hazwaz.unittest.HazwazTestCase): + def test_greet_world(self): + cmd = Greet() + stream = self.run_with_argv(cmd, [ + "./greeter.py", + "world", + ]) + + self.assertEqual(stream["stdout"].getvalue(), "Hello world!\n") + + def test_greet_individual(self): + cmd = Greet() + stream = self.run_with_argv(cmd, [ + "./greeter.py", + "individual", + "Bob", + ]) + + self.assertEqual(stream["stdout"].getvalue(), "Hello Bob\n") + + class Greet(hazwaz.MainCommand): """ Greet people in different ways. @@ -33,6 +55,7 @@ class Greet(hazwaz.MainCommand): commands = ( World(), Individual(), + hazwaz.unittest.TestCommand([TestGreeter]), ) |