- commit
- 90a623c154abd783f7f5bd3ed7383d1f23d0b014
- parent
- 3dda62754a0e50bfc17e448bef547846d68bd4fb
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2019-02-09 14:28
add some tests
Diffstat
| A | tests.py | 120 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 files changed, 120 insertions, 0 deletions
diff --git a/tests.py b/tests.py
@@ -0,0 +1,120 @@
-1 1 import assamtest
-1 2 from assamtest import expect
-1 3 from assamtest import decorators as _decorators
-1 4
-1 5 original_stack = None
-1 6 stack = None
-1 7
-1 8
-1 9 class TestReporter(assamtest.reporter.Reporter):
-1 10 def __init__(self):
-1 11 self.stats = {}
-1 12
-1 13 def test(self, name, err, status, level):
-1 14 self.stats.setdefault(status, 0)
-1 15 self.stats[status] += 1
-1 16
-1 17
-1 18 def expect_stats(**stats):
-1 19 reporter = TestReporter()
-1 20 assamtest.runner.run(stack[-1], reporter)
-1 21 expect.equal(reporter.stats, stats)
-1 22
-1 23
-1 24 @assamtest.before_each()
-1 25 def before_each():
-1 26 global original_stack, stack
-1 27 original_stack = assamtest._test.stack
-1 28 assamtest._test.stack = stack = [{'tests': [], 'suites': []}]
-1 29
-1 30
-1 31 @assamtest.after_each()
-1 32 def after_each():
-1 33 assamtest._test.stack = original_stack
-1 34
-1 35
-1 36 @assamtest.test()
-1 37 def test_simple():
-1 38 @assamtest.test(args=['+', 5])
-1 39 @assamtest.test(args=['*', 6])
-1 40 def my_test(op, value):
-1 41 expect.equal(eval('2 %s 3' % op), value)
-1 42
-1 43 expect_stats(passed=2)
-1 44
-1 45
-1 46 @assamtest.test()
-1 47 def suite_simple():
-1 48 @assamtest.suite()
-1 49 def my_suite():
-1 50 @assamtest.before_each()
-1 51 def _before_each():
-1 52 pass # do some setup here
-1 53
-1 54 @assamtest.test()
-1 55 def my_test():
-1 56 expect.equal(2 + 2, 4)
-1 57
-1 58 expect_stats(passed=1)
-1 59
-1 60 @assamtest.test()
-1 61 def suite_nonlocal():
-1 62 @assamtest.suite()
-1 63 def my_suite():
-1 64 a = None
-1 65
-1 66 @assamtest.test()
-1 67 def my_test1():
-1 68 expect.false(a)
-1 69
-1 70 @assamtest.test()
-1 71 def my_test2():
-1 72 nonlocal a
-1 73 a = True
-1 74 expect.true(a)
-1 75
-1 76 @assamtest.test()
-1 77 def my_test3():
-1 78 expect.true(a)
-1 79
-1 80 expect_stats(passed=3)
-1 81
-1 82 @assamtest.test()
-1 83 def expect_simple():
-1 84 expect.equal(2 + 2, 4)
-1 85 expect.not_equal(2 + 2, 5)
-1 86 expect._in(2, [1, 2, 3])
-1 87 with expect.raises(KeyError):
-1 88 {'foo': 0}['bar']
-1 89
-1 90
-1 91 @assamtest.suite()
-1 92 def decorators():
-1 93 @assamtest.test()
-1 94 def skip():
-1 95 @assamtest.test(decorators=[_decorators.skip])
-1 96 def my_test():
-1 97 expect.equal(2 + 2, 5)
-1 98
-1 99 expect_stats(skipped=1)
-1 100
-1 101 @assamtest.test()
-1 102 def fail():
-1 103 @assamtest.test(args=[4])
-1 104 @assamtest.test(args=[5], decorators=[_decorators.fail])
-1 105 def my_test(value):
-1 106 expect.equal(2 + 2, value)
-1 107
-1 108 expect_stats(passed=2)
-1 109
-1 110 @assamtest.test()
-1 111 def synchronize():
-1 112 import asyncio
-1 113
-1 114 @assamtest.test()
-1 115 @_decorators.synchronize
-1 116 async def my_test():
-1 117 await asyncio.sleep(0.1)
-1 118 expect.equal(2 + 2, 4)
-1 119
-1 120 expect_stats(passed=1)