-
Notifications
You must be signed in to change notification settings - Fork 22
/
tests.py
62 lines (37 loc) · 1.45 KB
/
tests.py
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
61
62
import nose.tools as nose
import os
import subprocess
ASSEMBLY_OUTPUT = "__test_output.obj"
SOURCE_DIR = "examples"
BINARY_DIR = "test_binaries"
def tearDownModule():
if os.path.exists(ASSEMBLY_OUTPUT):
os.remove(ASSEMBLY_OUTPUT)
def example(name):
return os.path.join(SOURCE_DIR, name + ".asm")
def check_path(assembler, path):
code = subprocess.call([assembler, path, ASSEMBLY_OUTPUT])
nose.assert_equal(code, 0, "Assembly of {0} failed!".format(path))
assert path.endswith(".asm")
binary = os.path.join(BINARY_DIR, os.path.basename(path)[:-4] + ".bin")
if os.path.exists(binary):
with open(ASSEMBLY_OUTPUT, "rb") as testing, open(binary, "rb") as tested:
nose.assert_equal(testing.read(), tested.read(), "Produced and tested binaries differ!")
# asm.py
def test_example_asm():
check_path("./asm.py", "example.asm")
def test_hello_asm():
check_path("./asm.py", example("hello"))
def test_hello2_asm():
check_path("./asm.py", example("hello2"))
def test_fibonacci_asm():
check_path("./asm.py", example("ique_fibonacci"))
# asm_pyparsing.py
def test_example_pyparsing():
check_path("./asm_pyparsing.py", "example.asm")
def test_hello_pyparsing():
check_path("./asm_pyparsing.py", example("hello"))
def test_hello2_pyparsing():
check_path("./asm_pyparsing.py", example("hello2"))
def test_fibonacci_pyparsing():
check_path("./asm_pyparsing.py", example("ique_fibonacci"))