6
6
import sys
7
7
import unittest
8
8
from pathlib import Path
9
- from threading import Lock
10
9
11
10
from autosync .Helper import get_path , test_only_overwrite_path_var
12
11
from autosync .MCUpdater import MCUpdater
@@ -21,117 +20,112 @@ def setUpClass(cls):
21
20
format = "%(levelname)-5s - %(message)s" ,
22
21
force = True ,
23
22
)
24
- cls .mutex = Lock ()
25
23
26
- def test_unified_test_cases (self ):
27
- with self .mutex :
28
- out_dir = Path (
29
- get_path ("{MCUPDATER_TEST_OUT_DIR}" )
30
- .joinpath ("merged" )
31
- .joinpath ("unified" )
32
- )
33
- if not out_dir .exists ():
34
- out_dir .mkdir (parents = True )
35
- for file in out_dir .iterdir ():
36
- logging .debug (f"Delete old file: { file } " )
37
- os .remove (file )
38
- test_only_overwrite_path_var (
39
- "{MCUPDATER_OUT_DIR}" ,
40
- out_dir ,
41
- )
42
- self .updater = MCUpdater (
43
- "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], True
44
- )
45
- self .updater .gen_all ()
46
- self .assertTrue (
47
- self .compare_files (out_dir , ["test_a.txt.yaml" , "test_b.txt.yaml" ])
48
- )
24
+ def test_test_case_gen (self ):
25
+ """
26
+ To enforce sequential execution of the tests, we execute them in here.
27
+ And don't make them a separated test.
28
+ """
29
+ self .assertTrue (self .unified_test_cases (), "Failed: unified_test_cases" )
30
+ self .assertTrue (self .separated_test_cases (), "Failed: separated_test_cases" )
31
+ self .assertTrue (
32
+ self .multi_mode_unified_test_cases (),
33
+ "Failed: multi_mode_unified_test_cases" ,
34
+ )
35
+ self .assertTrue (
36
+ self .multi_mode_separated_test_cases (),
37
+ "Failed: multi_mode_separated_test_cases" ,
38
+ )
39
+
40
+ def unified_test_cases (self ):
41
+ out_dir = Path (
42
+ get_path ("{MCUPDATER_TEST_OUT_DIR}" ).joinpath ("merged" ).joinpath ("unified" )
43
+ )
44
+ if not out_dir .exists ():
45
+ out_dir .mkdir (parents = True )
46
+ for file in out_dir .iterdir ():
47
+ logging .debug (f"Delete old file: { file } " )
48
+ os .remove (file )
49
+ test_only_overwrite_path_var (
50
+ "{MCUPDATER_OUT_DIR}" ,
51
+ out_dir ,
52
+ )
53
+ self .updater = MCUpdater ("ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], True )
54
+ self .updater .gen_all ()
55
+ return self .compare_files (out_dir , ["test_a.txt.yaml" , "test_b.txt.yaml" ])
49
56
50
- def test_separated_test_cases (self ):
51
- with self .mutex :
52
- out_dir = Path (
53
- get_path ("{MCUPDATER_TEST_OUT_DIR}" )
54
- .joinpath ("merged" )
55
- .joinpath ("separated" )
56
- )
57
- if not out_dir .exists ():
58
- out_dir .mkdir (parents = True )
59
- for file in out_dir .iterdir ():
60
- logging .debug (f"Delete old file: { file } " )
61
- os .remove (file )
62
- test_only_overwrite_path_var (
63
- "{MCUPDATER_OUT_DIR}" ,
64
- out_dir ,
65
- )
66
- self .updater = MCUpdater (
67
- "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], False
68
- )
69
- self .updater .gen_all ()
70
- self .assertTrue (
71
- self .compare_files (out_dir , ["test_a.txt.yaml" , "test_b.txt.yaml" ])
72
- )
57
+ def separated_test_cases (self ):
58
+ out_dir = Path (
59
+ get_path ("{MCUPDATER_TEST_OUT_DIR}" )
60
+ .joinpath ("merged" )
61
+ .joinpath ("separated" )
62
+ )
63
+ if not out_dir .exists ():
64
+ out_dir .mkdir (parents = True )
65
+ for file in out_dir .iterdir ():
66
+ logging .debug (f"Delete old file: { file } " )
67
+ os .remove (file )
68
+ test_only_overwrite_path_var (
69
+ "{MCUPDATER_OUT_DIR}" ,
70
+ out_dir ,
71
+ )
72
+ self .updater = MCUpdater (
73
+ "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], False
74
+ )
75
+ self .updater .gen_all ()
76
+ return self .compare_files (out_dir , ["test_a.txt.yaml" , "test_b.txt.yaml" ])
73
77
74
- def test_multi_mode_unified_test_cases (self ):
75
- with self .mutex :
76
- out_dir = Path (
77
- get_path ("{MCUPDATER_TEST_OUT_DIR}" )
78
- .joinpath ("multi" )
79
- .joinpath ("unified" )
80
- )
81
- if not out_dir .exists ():
82
- out_dir .mkdir (parents = True )
83
- for file in out_dir .iterdir ():
84
- logging .debug (f"Delete old file: { file } " )
85
- os .remove (file )
86
- test_only_overwrite_path_var (
87
- "{MCUPDATER_OUT_DIR}" ,
88
- out_dir ,
89
- )
90
- self .updater = MCUpdater (
91
- "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], True , multi_mode = True
92
- )
93
- self .updater .gen_all ()
94
- self .assertTrue (
95
- self .compare_files (
96
- out_dir ,
97
- [
98
- "test_a_aarch64_v8a__fp_armv8.txt.yaml" ,
99
- "test_a_arm64_v8.2a.txt.yaml" ,
100
- "test_b_arm64.txt.yaml" ,
101
- ],
102
- )
103
- )
78
+ def multi_mode_unified_test_cases (self ):
79
+ out_dir = Path (
80
+ get_path ("{MCUPDATER_TEST_OUT_DIR}" ).joinpath ("multi" ).joinpath ("unified" )
81
+ )
82
+ if not out_dir .exists ():
83
+ out_dir .mkdir (parents = True )
84
+ for file in out_dir .iterdir ():
85
+ logging .debug (f"Delete old file: { file } " )
86
+ os .remove (file )
87
+ test_only_overwrite_path_var (
88
+ "{MCUPDATER_OUT_DIR}" ,
89
+ out_dir ,
90
+ )
91
+ self .updater = MCUpdater (
92
+ "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], True , multi_mode = True
93
+ )
94
+ self .updater .gen_all ()
95
+ return self .compare_files (
96
+ out_dir ,
97
+ [
98
+ "test_a_aarch64_v8a__fp_armv8.txt.yaml" ,
99
+ "test_a_arm64_v8.2a.txt.yaml" ,
100
+ "test_b_arm64.txt.yaml" ,
101
+ ],
102
+ )
104
103
105
- def test_multi_mode_separated_test_cases (self ):
106
- with self .mutex :
107
- out_dir = Path (
108
- get_path ("{MCUPDATER_TEST_OUT_DIR}" )
109
- .joinpath ("multi" )
110
- .joinpath ("separated" )
111
- )
112
- if not out_dir .exists ():
113
- out_dir .mkdir (parents = True )
114
- for file in out_dir .iterdir ():
115
- logging .debug (f"Delete old file: { file } " )
116
- os .remove (file )
117
- test_only_overwrite_path_var (
118
- "{MCUPDATER_OUT_DIR}" ,
119
- out_dir ,
120
- )
121
- self .updater = MCUpdater (
122
- "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], False , multi_mode = True
123
- )
124
- self .updater .gen_all ()
125
- self .assertTrue (
126
- self .compare_files (
127
- out_dir ,
128
- [
129
- "test_a_aarch64_v8a__fp_armv8.txt.yaml" ,
130
- "test_a_arm64_v8.2a.txt.yaml" ,
131
- "test_b_arm64.txt.yaml" ,
132
- ],
133
- )
134
- )
104
+ def multi_mode_separated_test_cases (self ):
105
+ out_dir = Path (
106
+ get_path ("{MCUPDATER_TEST_OUT_DIR}" ).joinpath ("multi" ).joinpath ("separated" )
107
+ )
108
+ if not out_dir .exists ():
109
+ out_dir .mkdir (parents = True )
110
+ for file in out_dir .iterdir ():
111
+ logging .debug (f"Delete old file: { file } " )
112
+ os .remove (file )
113
+ test_only_overwrite_path_var (
114
+ "{MCUPDATER_OUT_DIR}" ,
115
+ out_dir ,
116
+ )
117
+ self .updater = MCUpdater (
118
+ "ARCH" , get_path ("{MCUPDATER_TEST_DIR}" ), [], [], False , multi_mode = True
119
+ )
120
+ self .updater .gen_all ()
121
+ return self .compare_files (
122
+ out_dir ,
123
+ [
124
+ "test_a_aarch64_v8a__fp_armv8.txt.yaml" ,
125
+ "test_a_arm64_v8.2a.txt.yaml" ,
126
+ "test_b_arm64.txt.yaml" ,
127
+ ],
128
+ )
135
129
136
130
def compare_files (self , out_dir : Path , filenames : list [str ]) -> bool :
137
131
if not out_dir .is_dir ():
@@ -153,16 +147,20 @@ def compare_files(self, out_dir: Path, filenames: list[str]) -> bool:
153
147
logging .error (f"{ efile } does not exist" )
154
148
return False
155
149
with open (efile ) as f :
150
+ logging .debug (f"Read { efile } " )
156
151
expected = f .read ()
157
152
158
153
afile = out_dir .joinpath (file )
159
154
if not afile .exists ():
160
155
logging .error (f"{ afile } does not exist" )
161
156
return False
162
157
with open (afile ) as f :
158
+ logging .debug (f"Read { afile } " )
163
159
actual = f .read ()
164
160
if expected != actual :
165
161
logging .error ("Files mismatch" )
162
+ print (f"Expected: { efile } " )
163
+ print (f"Actual: { afile } \n " )
166
164
print (f"Expected:\n \n { expected } \n " )
167
165
print (f"Actual:\n \n { actual } \n " )
168
166
return False
0 commit comments