rev: c8a7030a105a6d8d39072e63a80639f417d86542 poole/tests/run.py -rwxr-xr-x 1.3 KiB View raw Log this file
c8a7030a105a — Edd Barrett Use the same Python for tests as the test runner was invoked with. 11 months ago
                                                                                
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
57
58
59
60
#!/usr/bin/env python

import os
import shutil
import subprocess
import sys
import glob

HERE = os.path.dirname(__file__)
POOLE = [
    os.path.join(HERE, "..", "env", "bin", sys.executable),
    os.path.join(HERE, "..", "poole.py"),
]
ACTUAL = os.path.join(HERE, "actual")
EXPECTED = os.path.join(HERE, "expected")
ERRORS = os.path.join(HERE, "errors.diff")

EX_OK = getattr(os, "EX_OK", 0)

if os.path.exists(ACTUAL):
    shutil.rmtree(ACTUAL)

if os.path.exists(ERRORS):
    os.remove(ERRORS)

cmd_init = POOLE + [ACTUAL, "--init"]
cmd_build_dry_run = POOLE + [ACTUAL, "--build", "--dry-run"]
cmd_build = POOLE + [ACTUAL, "--build"]
cmd_diff = ["diff", "-Naur", EXPECTED, ACTUAL]

r = subprocess.call(cmd_init, stdout=subprocess.PIPE)
if r != EX_OK:
    sys.exit(1)

r = subprocess.call(cmd_build_dry_run, stdout=subprocess.PIPE)
if r != EX_OK:
    sys.exit(1)

generated = glob.glob(os.path.join(ACTUAL, "output", "*"))
if generated != []:
    sys.exit(1)

r = subprocess.call(cmd_build, stdout=subprocess.PIPE)
if r != EX_OK:
    sys.exit(1)

generated = glob.glob(os.path.join(ACTUAL, "output", "*"))
if generated == []:
    sys.exit(1)

p = subprocess.Popen(cmd_diff, stdout=subprocess.PIPE)
diff = p.communicate()[0]
if diff:
    with open(ERRORS, 'wb') as fp:
        fp.write(diff)
    print("failed - see %s for details" % ERRORS)
    sys.exit(1)

print("passed")