Skip to content

Commit e0c8515

Browse files
committed
Rewrite operators test without YAML
Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent 18477d7 commit e0c8515

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

tests/operators/operators.yaml

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

tests/operators/test_operators.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +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, preprocessor, platform
5+
import os
6+
import unittest
7+
8+
from codebasin import finder, platform, preprocessor
79
from codebasin.walkers.platform_mapper import PlatformMapper
810

9-
class TestExampleFile(unittest.TestCase):
11+
12+
class TestOperators(unittest.TestCase):
1013
"""
1114
Simple test of ability to recognize different operators when used
1215
within directives
@@ -16,23 +19,54 @@ def setUp(self):
1619
self.rootdir = "./tests/operators/"
1720
logging.getLogger("codebasin").disabled = True
1821

19-
self.expected_setmap = {frozenset(['CPU', 'GPU']): 32}
22+
self.expected_setmap = {frozenset(["CPU", "GPU"]): 32}
2023

21-
def test_yaml(self):
24+
def test_operators(self):
2225
"""operators/operators.yaml"""
23-
codebase, configuration = config.load("./tests/operators/operators.yaml", self.rootdir)
26+
codebase = {
27+
"files": [
28+
os.path.realpath(os.path.join(self.rootdir, "main.cpp")),
29+
],
30+
"platforms": ["CPU", "GPU"],
31+
"exclude_files": set(),
32+
"exclude_patterns": [],
33+
"rootdir": self.rootdir,
34+
}
35+
configuration = {
36+
"CPU": [
37+
{
38+
"file": codebase["files"][0],
39+
"defines": ["CPU"],
40+
"include_paths": [],
41+
"include_files": [],
42+
},
43+
],
44+
"GPU": [
45+
{
46+
"file": codebase["files"][0],
47+
"defines": ["GPU"],
48+
"include_paths": [],
49+
"include_files": [],
50+
},
51+
],
52+
}
2453
state = finder.find(self.rootdir, codebase, configuration)
2554
mapper = PlatformMapper(codebase)
2655
setmap = mapper.walk(state)
27-
self.assertDictEqual(setmap, self.expected_setmap, "Mismatch in setmap")
56+
self.assertDictEqual(
57+
setmap,
58+
self.expected_setmap,
59+
"Mismatch in setmap",
60+
)
2861

2962
def test_paths(self):
30-
input_str = r'FUNCTION(looks/2like/a/path/with_/bad%%identifiers)'
63+
input_str = r"FUNCTION(looks/2like/a/path/with_/bad%%identifiers)"
3164
tokens = preprocessor.Lexer(input_str).tokenize()
3265
p = platform.Platform("Test", self.rootdir)
3366
macro = preprocessor.macro_from_definition_string("FUNCTION(x)=#x")
34-
p._definitions = {macro.name : macro }
35-
exp = preprocessor.MacroExpander(p).expand(tokens)
67+
p._definitions = {macro.name: macro}
68+
_ = preprocessor.MacroExpander(p).expand(tokens)
69+
3670

37-
if __name__ == '__main__':
71+
if __name__ == "__main__":
3872
unittest.main()

0 commit comments

Comments
 (0)