Skip to content

Commit 51ca4cd

Browse files
committed
Rewrite commented directive test without YAML
Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent 5266702 commit 51ca4cd

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

tests/commented_directive/commented_directive.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 45 additions & 10 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 finder
79
from codebasin.walkers.platform_mapper import PlatformMapper
810

911

10-
class TestExampleFile(unittest.TestCase):
12+
class TestCommentedDirective(unittest.TestCase):
1113
"""
1214
Simple test of ability to recognize #commented_directive directives
1315
within files.
@@ -17,7 +19,7 @@ def setUp(self):
1719
self.rootdir = "./tests/commented_directive/"
1820
logging.getLogger("codebasin").disabled = True
1921

20-
self.expected_setmap = {frozenset(['CPU', 'GPU']): 5}
22+
self.expected_setmap = {frozenset(["CPU", "GPU"]): 5}
2123

2224
def count_children_nodes(self, node):
2325
my_count = 0
@@ -28,8 +30,33 @@ def count_children_nodes(self, node):
2830

2931
def test_yaml(self):
3032
"""commented_directive/commented_directive.yaml"""
31-
codebase, configuration = config.load(
32-
"./tests/commented_directive/commented_directive.yaml", self.rootdir)
33+
codebase = {
34+
"files": [
35+
os.path.realpath(os.path.join(self.rootdir, "main.cpp")),
36+
],
37+
"platforms": ["CPU", "GPU"],
38+
"exclude_files": set(),
39+
"exclude_patterns": [],
40+
"rootdir": self.rootdir,
41+
}
42+
configuration = {
43+
"CPU": [
44+
{
45+
"file": codebase["files"][0],
46+
"defines": ["CPU"],
47+
"include_paths": [],
48+
"include_files": [],
49+
},
50+
],
51+
"GPU": [
52+
{
53+
"file": codebase["files"][0],
54+
"defines": ["GPU"],
55+
"include_paths": [],
56+
"include_files": [],
57+
},
58+
],
59+
}
3360
state = finder.find(self.rootdir, codebase, configuration)
3461
mapper = PlatformMapper(codebase)
3562
setmap = mapper.walk(state)
@@ -38,9 +65,17 @@ def test_yaml(self):
3865
for fn in state.get_filenames():
3966
node_count += self.count_children_nodes(state.get_tree(fn).root)
4067

41-
self.assertDictEqual(setmap, self.expected_setmap, "Mismatch in setmap")
42-
self.assertEqual(node_count, 6, "Incorrect number of nodes in tree: {}".format(node_count))
68+
self.assertDictEqual(
69+
setmap,
70+
self.expected_setmap,
71+
"Mismatch in setmap",
72+
)
73+
self.assertEqual(
74+
node_count,
75+
6,
76+
f"Incorrect number of nodes in tree: {node_count}",
77+
)
4378

4479

45-
if __name__ == '__main__':
80+
if __name__ == "__main__":
4681
unittest.main()

0 commit comments

Comments
 (0)