Skip to content

Commit 0bfa42f

Browse files
committed
Rewrite include tests without YAML
Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent c561e6b commit 0bfa42f

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

tests/include/include-db.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/include/include.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/include/test_include.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# Copyright (C) 2019 Intel Corporation
1+
# Copyright (C) 2019-2024 Intel Corporation
22
# SPDX-License-Identifier: BSD-3-Clause
33

4-
import unittest
54
import logging
6-
from codebasin import config, finder, walkers
5+
import os
6+
import unittest
7+
8+
from codebasin import config, finder
79
from codebasin.walkers.platform_mapper import PlatformMapper
810

911

10-
class TestExampleFile(unittest.TestCase):
12+
class TestInclude(unittest.TestCase):
1113
"""
1214
Simple test of ability to follow #include directives to additional
1315
files.
@@ -17,26 +19,42 @@ def setUp(self):
1719
self.rootdir = "./tests/include/"
1820
logging.getLogger("codebasin").disabled = True
1921

20-
self.expected_setmap = {frozenset(['CPU']): 11,
21-
frozenset(['GPU']): 12,
22-
frozenset(['CPU', 'GPU']): 16}
22+
self.expected_setmap = {
23+
frozenset(["CPU"]): 11,
24+
frozenset(["GPU"]): 12,
25+
frozenset(["CPU", "GPU"]): 16,
26+
}
2327

24-
def test_yaml(self):
28+
def test_include(self):
2529
"""include/include.yaml"""
26-
codebase, configuration = config.load("./tests/include/include.yaml", self.rootdir)
27-
state = finder.find(self.rootdir, codebase, configuration)
28-
mapper = PlatformMapper(codebase)
29-
setmap = mapper.walk(state)
30-
self.assertDictEqual(setmap, self.expected_setmap, "Mismatch in setmap")
30+
codebase = {
31+
"files": [],
32+
"platforms": ["CPU", "GPU"],
33+
"exclude_files": set(),
34+
"exclude_patterns": [],
35+
"rootdir": os.path.realpath(self.rootdir),
36+
}
37+
38+
cpu_path = os.path.realpath(
39+
os.path.join(self.rootdir, "cpu_commands.json"),
40+
)
41+
gpu_path = os.path.realpath(
42+
os.path.join(self.rootdir, "gpu_commands.json"),
43+
)
44+
configuration = {
45+
"CPU": config.load_database(cpu_path, self.rootdir),
46+
"GPU": config.load_database(gpu_path, self.rootdir),
47+
}
3148

32-
def test_db(self):
33-
"""include/include-db.yaml"""
34-
codebase, configuration = config.load("./tests/include/include-db.yaml", self.rootdir)
3549
state = finder.find(self.rootdir, codebase, configuration)
3650
mapper = PlatformMapper(codebase)
3751
setmap = mapper.walk(state)
38-
self.assertDictEqual(setmap, self.expected_setmap, "Mismatch in setmap")
52+
self.assertDictEqual(
53+
setmap,
54+
self.expected_setmap,
55+
"Mismatch in setmap",
56+
)
3957

4058

41-
if __name__ == '__main__':
59+
if __name__ == "__main__":
4260
unittest.main()

0 commit comments

Comments
 (0)