73 lines
1.6 KiB
Python
Executable file
73 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env -S python
|
|
|
|
from os.path import dirname, join
|
|
import sys
|
|
sys.path.append(join(dirname(dirname(__file__)), "src"))
|
|
from okipy import Suite, Ctx
|
|
|
|
|
|
def main():
|
|
suite = Suite()
|
|
|
|
@suite.test()
|
|
def adds_correctly(ctx: Ctx):
|
|
assert 2 + 2 == 4
|
|
|
|
@suite.test()
|
|
def adds_incorrectly(ctx: Ctx):
|
|
print("this must work")
|
|
assert 2 + 2 == 5
|
|
|
|
@suite.test()
|
|
def it_doesnt_fail(ctx: Ctx):
|
|
print("hope this doesnt fail ...")
|
|
print("oh, this will fail", file=sys.stderr)
|
|
raise Exception("Expected failure.")
|
|
|
|
@suite.test()
|
|
def it_fails(ctx: Ctx):
|
|
with ctx.assert_raises():
|
|
raise Exception("Expected failure.")
|
|
|
|
suite.run(sys.argv[1:])
|
|
|
|
|
|
if __name__ == "__main__": main()
|
|
|
|
|
|
"""
|
|
prints the following :
|
|
|
|
|
|
Running 4 / 4 tests
|
|
|
|
Ok adds_correctly
|
|
Err adds_incorrectly
|
|
Err it_doesnt_fail
|
|
Ok it_fails
|
|
Failed 2 / 4 tests
|
|
|
|
Fail 1 adds_incorrectly
|
|
Traceback (most recent call last):
|
|
File "/media/hdd0/Projects/okipy/./src/okipy/lib.py", line 46, in run
|
|
self.procedure(Ctx(self))
|
|
File "/media/hdd0/Projects/okipy/./example/tests.py", line 19, in adds_incorrectly
|
|
assert 2 + 2 == 5
|
|
AssertionError
|
|
Stdout 1 lines
|
|
this must work
|
|
|
|
|
|
Fail 2 it_doesnt_fail
|
|
Traceback (most recent call last):
|
|
File "/media/hdd0/Projects/okipy/./src/okipy/lib.py", line 46, in run
|
|
self.procedure(Ctx(self))
|
|
File "/media/hdd0/Projects/okipy/./example/tests.py", line 25, in it_doesnt_fail
|
|
raise Exception("Expected failure.")
|
|
Exception: Expected failure.
|
|
Stdout 1 lines
|
|
hope this doesnt fail ...
|
|
Stderr 1 lines
|
|
oh, this will fail
|
|
|
|
"""
|