summaryrefslogtreecommitdiff
path: root/Omni/Bild/Example.py
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-05-22 13:53:08 -0400
committerBen Sima <ben@bsima.me>2025-05-22 13:53:08 -0400
commit202c8cf1112bf59ce8dbec886af02c226c0f4b3e (patch)
tree636eba5d4060c85ff72f3a3323b8ce4f3d641ad6 /Omni/Bild/Example.py
parent2bba78efc8a203785742355aa3f8852034e27e0d (diff)
Add TestCase to Omni.Test
Also improves the Example.py a bit with a real test case and example of how to use Omni.Test.
Diffstat (limited to 'Omni/Bild/Example.py')
-rwxr-xr-xOmni/Bild/Example.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/Omni/Bild/Example.py b/Omni/Bild/Example.py
index 58e941a..7d57890 100755
--- a/Omni/Bild/Example.py
+++ b/Omni/Bild/Example.py
@@ -8,8 +8,13 @@ Example Python file that also serves as a test case for bild.
# : out example
# : dep cryptography
import cryptography.fernet
+import Omni.App as App
+import Omni.Log as Log
+import Omni.Test as Test
import sys
+log = Log.setup()
+
def cryptic_hello(name: str) -> str:
"""
@@ -23,6 +28,7 @@ def cryptic_hello(name: str) -> str:
key = cryptography.fernet.Fernet.generate_key()
f = cryptography.fernet.Fernet(key)
token = f.encrypt(hello(name).encode("utf-8"))
+ log.info("attempting decryption")
ret = f.decrypt(token).decode("utf-8")
if ret != hello(name):
msg = "en/decryption failed!"
@@ -35,8 +41,16 @@ def hello(name: str) -> str:
return f"Hello {name}"
+class TestExample(Test.TestCase):
+ """Test the Example module."""
+
+ def test_hello(self) -> None:
+ """Test `hello` function."""
+ self.assertEqual("Hello Ben", hello("Ben"))
+
+
def main() -> None:
"""Entrypoint."""
if "test" in sys.argv:
- sys.stdout.write("testing success")
+ Test.run(App.Area.Test, [TestExample])
sys.stdout.write(cryptic_hello("world"))