1
- # Copyright (C) 2019 Intel Corporation
1
+ # Copyright (C) 2019-2024 Intel Corporation
2
2
# SPDX-License-Identifier: BSD-3-Clause
3
3
4
- import unittest
5
4
import logging
6
- from codebasin import config , finder , walkers
5
+ import os
6
+ import unittest
7
+
8
+ from codebasin import finder
7
9
from codebasin .walkers .platform_mapper import PlatformMapper
8
10
9
11
10
- class TestExampleFile (unittest .TestCase ):
12
+ class TestCommentedDirective (unittest .TestCase ):
11
13
"""
12
14
Simple test of ability to recognize #commented_directive directives
13
15
within files.
@@ -17,7 +19,7 @@ def setUp(self):
17
19
self .rootdir = "./tests/commented_directive/"
18
20
logging .getLogger ("codebasin" ).disabled = True
19
21
20
- self .expected_setmap = {frozenset ([' CPU' , ' GPU' ]): 5 }
22
+ self .expected_setmap = {frozenset ([" CPU" , " GPU" ]): 5 }
21
23
22
24
def count_children_nodes (self , node ):
23
25
my_count = 0
@@ -28,8 +30,33 @@ def count_children_nodes(self, node):
28
30
29
31
def test_yaml (self ):
30
32
"""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
+ }
33
60
state = finder .find (self .rootdir , codebase , configuration )
34
61
mapper = PlatformMapper (codebase )
35
62
setmap = mapper .walk (state )
@@ -38,9 +65,17 @@ def test_yaml(self):
38
65
for fn in state .get_filenames ():
39
66
node_count += self .count_children_nodes (state .get_tree (fn ).root )
40
67
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
+ )
43
78
44
79
45
- if __name__ == ' __main__' :
80
+ if __name__ == " __main__" :
46
81
unittest .main ()
0 commit comments