Python: more tests and comments

This commit is contained in:
Rasmus Lerchedahl Petersen
2021-09-08 14:44:36 +02:00
parent 9b198c6d0a
commit a9c409403c
5 changed files with 112 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
from testlib import *
# These are defined so that we can evaluate the test code.
NONSOURCE = "not a source"
SOURCE = "source"
def is_source(x):
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
def SINK(x):
if is_source(x):
print("OK")
else:
print("Unexpected flow", x)
def SINK_F(x):
if is_source(x):
print("Unexpected flow", x)
else:
print("OK")
def set_foo():
global foo
print(foo)
foo = SOURCE
foo = NONSOURCE
set_foo()
@expects(2)
def test_phases():
global foo
SINK(foo)
foo = NONSOURCE
set_foo()
SINK(foo)