24
24
from py_sonar_scanner .logger import ApplicationLogger
25
25
26
26
CURRENT_DIR = os .path .dirname (os .path .abspath (__file__ ))
27
- TEST_TOML_FILE = "test_toml_file.toml"
27
+ TEST_TOML_FILE_POETRY = "test_toml_file_poetry.toml"
28
+ TOML_NO_COMMON_PROPERTIES = "toml_no_common_properties.toml"
28
29
SAMPLE_SCANNER_PATH = "path/to/scanner/py-sonar-scanner"
29
30
30
31
@@ -129,40 +130,75 @@ def test_dict_with_valid_values(self, mock_sys):
129
130
@patch ("py_sonar_scanner.configuration.sys" )
130
131
def test_toml_with_valid_values (self , mock_sys ):
131
132
configuration = Configuration ()
132
- toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE )
133
+ toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE_POETRY )
133
134
mock_sys .argv = [SAMPLE_SCANNER_PATH , f"-Dtoml.path={ toml_file_path } " ]
134
135
configuration .setup ()
135
136
self .assertListEqual (
136
137
configuration .scan_arguments ,
137
138
[
138
- "-Dsonar.property1=value1 " ,
139
- "-Dsonar.property2=value2 " ,
139
+ "-Dsonar.project.name=overridden_name " ,
140
+ "-Dsonar.python.version=3.10 " ,
140
141
"-Dsonar.property_class.property1=value1" ,
141
- f"-Dtoml.path={ CURRENT_DIR } /resources/test_toml_file.toml" ,
142
+ f"-Dtoml.path={ CURRENT_DIR } /resources/{ TEST_TOML_FILE_POETRY } " ,
143
+ ],
144
+ )
145
+
146
+ @patch ("py_sonar_scanner.configuration.sys" )
147
+ def test_toml_overridden_common_properties (self , mock_sys ):
148
+ configuration = Configuration ()
149
+ toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE_POETRY )
150
+ mock_sys .argv = [SAMPLE_SCANNER_PATH , f"-Dtoml.path={ toml_file_path } " , "-read.project.config" ]
151
+ configuration .setup ()
152
+ self .assertListEqual (
153
+ configuration .scan_arguments ,
154
+ [
155
+ "-Dsonar.project.name=my_name" ,
156
+ "-Dsonar.project.version=0.0.1" ,
157
+ "-Dsonar.project.name=overridden_name" ,
158
+ "-Dsonar.python.version=3.10" ,
159
+ "-Dsonar.property_class.property1=value1" ,
160
+ f"-Dtoml.path={ CURRENT_DIR } /resources/{ TEST_TOML_FILE_POETRY } " ,
161
+ "-read.project.config" ,
162
+ ],
163
+ )
164
+
165
+ @patch ("py_sonar_scanner.configuration.sys" )
166
+ def test_toml_no_common_properties (self , mock_sys ):
167
+ configuration = Configuration ()
168
+ toml_file_path = os .path .join (CURRENT_DIR , "resources" , TOML_NO_COMMON_PROPERTIES )
169
+ mock_sys .argv = [SAMPLE_SCANNER_PATH , f"-Dtoml.path={ toml_file_path } " , "-read.project.config" ]
170
+ configuration .setup ()
171
+ self .assertListEqual (
172
+ configuration .scan_arguments ,
173
+ [
174
+ "-Dsonar.project.name=my_project_name" ,
175
+ "-Dsonar.python.version=3.10" ,
176
+ f"-Dtoml.path={ CURRENT_DIR } /resources/{ TOML_NO_COMMON_PROPERTIES } " ,
177
+ "-read.project.config" ,
142
178
],
143
179
)
144
180
145
181
@patch ("py_sonar_scanner.configuration.sys" )
146
182
def test_duplicate_values_toml_cli (self , mock_sys ):
147
183
configuration = Configuration ()
148
- toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE )
149
- mock_sys .argv = [SAMPLE_SCANNER_PATH , f"-Dtoml.path={ toml_file_path } " , "-Dsonar.property1=value1 " ]
184
+ toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE_POETRY )
185
+ mock_sys .argv = [SAMPLE_SCANNER_PATH , f"-Dtoml.path={ toml_file_path } " , "-Dsonar.project.name=second_override " ]
150
186
configuration .setup ()
151
187
self .assertListEqual (
152
188
configuration .scan_arguments ,
153
189
[
154
- "-Dsonar.property1=value1 " ,
155
- "-Dsonar.property2=value2 " ,
190
+ "-Dsonar.project.name=overridden_name " ,
191
+ "-Dsonar.python.version=3.10 " ,
156
192
"-Dsonar.property_class.property1=value1" ,
157
- f"-Dtoml.path={ CURRENT_DIR } /resources/test_toml_file.toml " ,
158
- "-Dsonar.property1=value1 " ,
193
+ f"-Dtoml.path={ CURRENT_DIR } /resources/{ TEST_TOML_FILE_POETRY } " ,
194
+ "-Dsonar.project.name=second_override " ,
159
195
],
160
196
)
161
197
162
198
@patch ("builtins.open" )
163
199
@patch ("py_sonar_scanner.configuration.sys" )
164
200
def test_error_while_reading_toml_file (self , mock_sys , mock_open ):
165
- toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE )
201
+ toml_file_path = os .path .join (CURRENT_DIR , "resources" , TEST_TOML_FILE_POETRY )
166
202
mock_sys .argv = ["path/to/scanner/py-sonar-scanner" , f"-Dtoml.path={ toml_file_path } " ]
167
203
168
204
mock_open .side_effect = OSError ("Test error while opening file." )
@@ -173,7 +209,7 @@ def test_error_while_reading_toml_file(self, mock_sys, mock_open):
173
209
self .assertListEqual (
174
210
configuration .scan_arguments ,
175
211
[
176
- f"-Dtoml.path={ CURRENT_DIR } /resources/test_toml_file.toml " ,
212
+ f"-Dtoml.path={ CURRENT_DIR } /resources/{ TEST_TOML_FILE_POETRY } " ,
177
213
],
178
214
)
179
215
0 commit comments