summaryrefslogtreecommitdiff
path: root/test.py
blob: 101f8dcbc5ff21c2aab833ec9b0c8cf5debbedaa (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
"""
Some simple tests
"""

import os
import sys
import time
import doctest
from decorator import decorator
import documentation


@decorator
def identity(f, *a, **k):
    "do nothing decorator"
    return f(*a, **k)


@identity
def f1():
    "f1"


def getfname(func):
    fname = os.path.basename(func.__globals__['__file__'])
    return os.path.splitext(fname)[0] + '.py'


def test0():
    this = getfname(identity)
    assert this == 'test.py', this


def test1():
    this = getfname(f1)
    assert this == 'test.py', this


def test_long_running():
    f1 = documentation.long_running(1)
    f2 = documentation.long_running(2)
    assert f1.result() + f2.result() == 3

if __name__ == '__main__':
    t0 = time.time()
    for name, test in list(globals().items()):
        if name.startswith('test'):
            test()
    err = doctest.testmod(documentation)[0]
    t1 = time.time()
    print('Tests run in %s seconds' % (t1 - t0))
    sys.exit(err)