summaryrefslogtreecommitdiff
path: root/docs/source/examples/greeter.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2022-08-01 17:06:17 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2022-08-01 17:06:17 +0200
commitab3de8a911beac7b671f8a6681bc0b63711c11e7 (patch)
treebe816f7c531c297ff2f5255ef50fc4130b0a1a44 /docs/source/examples/greeter.py
parent0466c3406b2dc1e41fc32bfd77f1b8af22a5c69f (diff)
Document the testing helpers
Diffstat (limited to 'docs/source/examples/greeter.py')
-rwxr-xr-xdocs/source/examples/greeter.py23
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]),
)