-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconftest.py
63 lines (51 loc) · 1.65 KB
/
conftest.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
63
import pytest
import kratos
import os
import tempfile
def get_gold_dir():
return os.path.join(os.path.dirname(__file__), "tests", "gold")
def check_gold_fn(mod, gold_name, **kargs):
with tempfile.TemporaryDirectory() as tempdir:
filename = os.path.join(tempdir, "test.sv")
gold = os.path.join(get_gold_dir(), gold_name + ".sv")
if isinstance(mod, kratos.Generator):
kratos.verilog(mod, filename=filename, **kargs)
else:
with open(filename, "w+") as f:
f.write(mod)
assert os.path.isfile(gold)
assert os.path.isfile(filename)
# read them out to avoid \n and \r\n
with open(filename) as f:
filename_content = f.read()
with open(gold) as f:
gold_content = f.read()
if filename_content != gold_content:
with open(filename) as f:
print(f.read())
print("-" * 80)
with open(gold) as f:
print(f.read())
assert False
def check_file_fn(src_str, gold_filename):
gold = os.path.join(get_gold_dir(), gold_filename)
with open(gold) as f:
gold_text = f.read()
if os.path.isfile(src_str):
with open(src_str) as ff:
src_str = ff.read()
if src_str != gold_text:
print(src_str)
print("-" * 80)
print(gold_text)
assert False
@pytest.fixture(autouse=True)
def clear_kratos_context():
import kratos
kratos.Generator.clear_context()
@pytest.fixture
def check_gold():
return check_gold_fn
@pytest.fixture
def check_file():
return check_file_fn