-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_sonar_project_properties.py
More file actions
87 lines (74 loc) · 3.62 KB
/
test_sonar_project_properties.py
File metadata and controls
87 lines (74 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# Sonar Scanner Python
# Copyright (C) 2011-2024 SonarSource Sàrl.
# mailto:info AT sonarsource DOT com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
#
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
from pathlib import Path
import pyfakefs.fake_filesystem_unittest as pyfakefs
from pysonar_scanner.configuration import sonar_project_properties
class TestPropertiesFile(pyfakefs.TestCase):
def setUp(self):
self.setUpPyfakefs()
def test_load_sonar_project_properties(self):
self.fs.create_file(
"sonar-project.properties",
contents=(
"sonar.projectKey=my-project\n"
"sonar.projectName=My Project\n"
"sonar.sources=src # my sources\n"
"sonar.sources=src\n"
"sonar.exclusions=**/generated/**/*,**/deprecated/**/*,**/testdata/**/*\n"
"sonar.some.unknownProperty=my_unknown_property_value\n"
),
)
properties = sonar_project_properties.load(Path("."))
self.assertEqual(properties.get("sonar.projectKey"), "my-project")
self.assertEqual(properties.get("sonar.projectName"), "My Project")
self.assertEqual(properties.get("sonar.sources"), "src")
self.assertEqual(properties.get("sonar.exclusions"), "**/generated/**/*,**/deprecated/**/*,**/testdata/**/*")
self.assertEqual(properties.get("sonar.some.unknownProperty"), "my_unknown_property_value")
def test_load_sonar_project_properties_custom_path(self):
self.fs.create_file(
"custom/path/sonar-project.properties",
contents=("sonar.projectKey=my-project\n" "sonar.projectName=My Project\n"),
)
properties = sonar_project_properties.load(Path("custom/path"))
self.assertEqual(properties.get("sonar.projectKey"), "my-project")
self.assertEqual(properties.get("sonar.projectName"), "My Project")
def test_load_missing_file(self):
properties = sonar_project_properties.load(Path("custom/path"))
self.assertEqual(len(properties), 0)
def test_load_empty_file(self):
self.fs.create_file("sonar-project.properties", contents="")
properties = sonar_project_properties.load(Path("."))
self.assertEqual(len(properties), 0)
def test_load_with_malformed_lines_jproperties(self):
self.fs.create_file(
"sonar-project.properties",
contents=(
"valid.key=valid value\n"
"malformed line without equals\n"
"another.valid.key=another valid value\n"
"=value without key\n"
),
)
properties = sonar_project_properties.load(Path("."))
self.assertEqual(properties.get("valid.key"), "valid value")
self.assertEqual(properties.get("another.valid.key"), "another valid value")
self.assertEqual(properties.get("malformed"), "line without equals")
self.assertEqual(properties.get(""), "value without key")
self.assertEqual(len(properties), 4)