Skip to content

Commit 26fe365

Browse files
committed
Rewrite literals test without YAML
Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent 0bfa42f commit 26fe365

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

tests/literals/literals.yaml

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

tests/literals/test_literals.py

Lines changed: 49 additions & 10 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
5+
import os
6+
import unittest
7+
8+
from codebasin import finder, preprocessor
79
from codebasin.walkers.platform_mapper import PlatformMapper
810

9-
class TestExampleFile(unittest.TestCase):
11+
12+
class TestLiterals(unittest.TestCase):
1013
"""
1114
Simple test of C-style literal handling.
1215
e.g. 0x0ULL, 0b11
@@ -16,21 +19,57 @@ def setUp(self):
1619
self.rootdir = "./tests/literals/"
1720
logging.getLogger("codebasin").disabled = True
1821

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

21-
def test_yaml(self):
24+
def test_literals(self):
2225
"""literals/literals.yaml"""
23-
codebase, configuration = config.load("./tests/literals/literals.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": ["USE_CPU"],
40+
"include_paths": [],
41+
"include_files": [],
42+
},
43+
],
44+
"GPU": [
45+
{
46+
"file": codebase["files"][0],
47+
"defines": ["USE_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_strings(self):
3063
expected_str = r'"L + 2-2 \"\\\" \\n\""'
3164
tokens = preprocessor.Lexer(expected_str).tokenize()
32-
expected = preprocessor.StringConstant('Unknown', 'Unknown', False, r'L + 2-2 \"\\\" \\n\"')
65+
expected = preprocessor.StringConstant(
66+
"Unknown",
67+
"Unknown",
68+
False,
69+
r"L + 2-2 \"\\\" \\n\"",
70+
)
3371
self.assertEqual(tokens[0].token, expected.token)
3472

35-
if __name__ == '__main__':
73+
74+
if __name__ == "__main__":
3675
unittest.main()

0 commit comments

Comments
 (0)