20
20
from pathlib import Path
21
21
22
22
from pyfakefs .fake_filesystem_unittest import TestCase
23
- from pysonar_scanner .configuration import pyproject_toml
23
+ from pysonar_scanner .configuration . pyproject_toml import TomlConfigurationLoader
24
24
25
25
26
26
class TestTomlFile (TestCase ):
@@ -38,12 +38,14 @@ def test_load_toml_file_with_sonarqube_config(self):
38
38
exclusions = "**/generated/**/*,**/deprecated/**/*,**/testdata/**/*"
39
39
""" ,
40
40
)
41
- properties = pyproject_toml .load (Path ("." ))
41
+ properties = TomlConfigurationLoader .load (Path ("." ))
42
42
43
- self .assertEqual (properties .get ("sonar.projectKey" ), "my-project" )
44
- self .assertEqual (properties .get ("sonar.projectName" ), "My Project" )
45
- self .assertEqual (properties .get ("sonar.sources" ), "src" )
46
- self .assertEqual (properties .get ("sonar.exclusions" ), "**/generated/**/*,**/deprecated/**/*,**/testdata/**/*" )
43
+ self .assertEqual (properties .sonar_properties .get ("sonar.projectKey" ), "my-project" )
44
+ self .assertEqual (properties .sonar_properties .get ("sonar.projectName" ), "My Project" )
45
+ self .assertEqual (properties .sonar_properties .get ("sonar.sources" ), "src" )
46
+ self .assertEqual (
47
+ properties .sonar_properties .get ("sonar.exclusions" ), "**/generated/**/*,**/deprecated/**/*,**/testdata/**/*"
48
+ )
47
49
48
50
def test_load_toml_file_kebab_case (self ):
49
51
self .fs .create_file (
@@ -54,10 +56,10 @@ def test_load_toml_file_kebab_case(self):
54
56
project-name = "My Project"
55
57
""" ,
56
58
)
57
- properties = pyproject_toml .load (Path ("." ))
59
+ properties = TomlConfigurationLoader .load (Path ("." ))
58
60
59
- self .assertEqual (properties .get ("sonar.projectKey" ), "my-project" )
60
- self .assertEqual (properties .get ("sonar.projectName" ), "My Project" )
61
+ self .assertEqual (properties .sonar_properties . get ("sonar.projectKey" ), "my-project" )
62
+ self .assertEqual (properties .sonar_properties . get ("sonar.projectName" ), "My Project" )
61
63
62
64
def test_load_toml_file_without_sonar_section (self ):
63
65
self .fs .create_file (
@@ -71,19 +73,19 @@ def test_load_toml_file_without_sonar_section(self):
71
73
profile = "black"
72
74
""" ,
73
75
)
74
- properties = pyproject_toml .load (Path ("." ))
76
+ properties = TomlConfigurationLoader .load (Path ("." ))
75
77
76
- self .assertEqual (len (properties ), 0 )
78
+ self .assertEqual (len (properties . sonar_properties ), 0 )
77
79
78
80
def test_load_missing_file (self ):
79
- properties = pyproject_toml .load (Path ("." ))
80
- self .assertEqual (len (properties ), 0 )
81
+ properties = TomlConfigurationLoader .load (Path ("." ))
82
+ self .assertEqual (len (properties . sonar_properties ), 0 )
81
83
82
84
def test_load_empty_file (self ):
83
85
self .fs .create_file ("pyproject.toml" , contents = "" )
84
- properties = pyproject_toml .load (Path ("." ))
86
+ properties = TomlConfigurationLoader .load (Path ("." ))
85
87
86
- self .assertEqual (len (properties ), 0 )
88
+ self .assertEqual (len (properties . sonar_properties ), 0 )
87
89
88
90
def test_load_malformed_toml_file (self ):
89
91
self .fs .create_file (
@@ -93,9 +95,9 @@ def test_load_malformed_toml_file(self):
93
95
sonar.projectKey = "my-project"
94
96
""" ,
95
97
)
96
- properties = pyproject_toml .load (Path ("." ))
98
+ properties = TomlConfigurationLoader .load (Path ("." ))
97
99
98
- self .assertEqual (len (properties ), 0 )
100
+ self .assertEqual (len (properties . sonar_properties ), 0 )
99
101
100
102
def test_load_toml_with_nested_values (self ):
101
103
self .fs .create_file (
@@ -109,11 +111,11 @@ def test_load_toml_with_nested_values(self):
109
111
coverage.reportPaths = "coverage.xml"
110
112
""" ,
111
113
)
112
- properties = pyproject_toml .load (Path ("." ))
114
+ properties = TomlConfigurationLoader .load (Path ("." ))
113
115
114
- self .assertEqual (properties .get ("sonar.projectKey" ), "my-project" )
115
- self .assertEqual (properties .get ("sonar.python.version" ), "3.9,3.10,3.11,3.12,3.13" )
116
- self .assertEqual (properties .get ("sonar.python.coverage.reportPaths" ), "coverage.xml" )
116
+ self .assertEqual (properties .sonar_properties . get ("sonar.projectKey" ), "my-project" )
117
+ self .assertEqual (properties .sonar_properties . get ("sonar.python.version" ), "3.9,3.10,3.11,3.12,3.13" )
118
+ self .assertEqual (properties .sonar_properties . get ("sonar.python.coverage.reportPaths" ), "coverage.xml" )
117
119
118
120
def test_load_toml_file_from_custom_dir (self ):
119
121
self .fs .create_dir ("custom/path" )
@@ -125,7 +127,30 @@ def test_load_toml_file_from_custom_dir(self):
125
127
projectName = "Custom Path Project"
126
128
""" ,
127
129
)
128
- properties = pyproject_toml .load (Path ("custom/path" ))
130
+ properties = TomlConfigurationLoader .load (Path ("custom/path" ))
131
+
132
+ self .assertEqual (properties .sonar_properties .get ("sonar.projectKey" ), "custom-path-project" )
133
+ self .assertEqual (properties .sonar_properties .get ("sonar.projectName" ), "Custom Path Project" )
134
+
135
+ def test_load_toml_file_project_content (self ):
136
+ self .fs .create_file (
137
+ "pyproject.toml" ,
138
+ contents = (
139
+ """
140
+ [project]
141
+ name = "My Overridden Project Name"
142
+ description = "My Project Description"
143
+ requires-python = ["3.6", "3.7", "3.8"]
144
+ [tool.sonar]
145
+ project-key = "my-project"
146
+ project-name = "My Project"
147
+ """
148
+ ),
149
+ )
150
+ properties = TomlConfigurationLoader .load (Path ("." ))
129
151
130
- self .assertEqual (properties .get ("sonar.projectKey" ), "custom-path-project" )
131
- self .assertEqual (properties .get ("sonar.projectName" ), "Custom Path Project" )
152
+ self .assertEqual (properties .sonar_properties .get ("sonar.projectKey" ), "my-project" )
153
+ self .assertEqual (properties .sonar_properties .get ("sonar.projectName" ), "My Project" )
154
+ self .assertEqual (properties .project_properties .get ("sonar.projectName" ), "My Overridden Project Name" )
155
+ self .assertEqual (properties .project_properties .get ("sonar.projectDescription" ), "My Project Description" )
156
+ self .assertEqual (properties .project_properties .get ("sonar.python.version" ), "3.6,3.7,3.8" )
0 commit comments