blob: 7d57890a2b617e2178c74de559c849500eddd642 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/env run.sh
"""
Test that bild can build Python stuff.
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:
"""
Encrypt and decrypt `name`.
Example taken from `cryptography` docs.
Raises:
ValueError: if decryption fails
"""
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!"
raise ValueError(msg)
return ret
def hello(name: str) -> str:
"""Say hello."""
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:
Test.run(App.Area.Test, [TestExample])
sys.stdout.write(cryptic_hello("world"))
|