Skip to content

Commit fd68263

Browse files
authored
change_detection setting needs to be bool (#147)
1 parent 110615f commit fd68263

File tree

2 files changed

+73
-23
lines changed

2 files changed

+73
-23
lines changed

config/config.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def artifact(option, dflt, valid_values=None):
9797
excluded_src_file_extensions=artifact("excluded_extensions", (".md",)),
9898
transitives_versioning_mode=artifact("transitives_versioning_mode", "semver", valid_values=("semver", "counter")),
9999
jar_artifact_classifier=artifact("jar_classifier", None),
100-
change_detection=artifact("change_detection", True),
100+
change_detection_enabled=artifact("change_detection_enabled", True),
101101
)
102102

103103
if verbose:
@@ -129,7 +129,7 @@ def __init__(self,
129129
excluded_src_file_extensions=(),
130130
transitives_versioning_mode="semver",
131131
jar_artifact_classifier=None,
132-
change_detection=True):
132+
change_detection_enabled=True):
133133

134134
# general
135135
self.pom_template_path_and_content=pom_template_path_and_content
@@ -144,7 +144,7 @@ def __init__(self,
144144
self.excluded_src_file_extensions = _to_tuple(excluded_src_file_extensions)
145145
self.transitives_versioning_mode = transitives_versioning_mode
146146
self._jar_artifact_classifier = jar_artifact_classifier
147-
self._change_detection = change_detection
147+
self._change_detection_enabled = _to_bool(change_detection_enabled)
148148

149149
@property
150150
def pom_template(self):
@@ -160,7 +160,7 @@ def jar_artifact_classifier(self):
160160

161161
@property
162162
def change_detection_enabled(self):
163-
return self._change_detection
163+
return self._change_detection_enabled
164164

165165
@property
166166
def all_src_exclusions(self):
@@ -204,9 +204,18 @@ def _to_tuple(thing):
204204
tokens = thing.split(",")
205205
filtered_tokens = [t.strip() for t in tokens if len(t.strip()) > 0]
206206
return tuple(filtered_tokens)
207-
raise Exception("Cannot convert to tuple")
207+
raise Exception("Cannot convert to tuple [%s] % thing")
208208

209209

210+
def _to_bool(thing):
211+
if isinstance(thing, bool):
212+
return thing
213+
if isinstance(thing, int):
214+
return False if thing == 0 else True
215+
if isinstance(thing, str):
216+
return True if thing.lower() in ("true", "on", "1") else False
217+
raise Exception("Cannot convert to bool [%s]" % thing)
218+
210219
def _read_files(repo_root, paths):
211220
"""
212221
Returns a list of tuples: (<path>, <file content>).

tests/configtest.py

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tempfile
1111
import unittest
1212

13+
1314
class ConfigTest(unittest.TestCase):
1415

1516
def test_pom_template(self):
@@ -126,6 +127,45 @@ def test_classifier__set_in_config__env_var_takes_precedence(self):
126127
finally:
127128
del os.environ["POMGEN_JAR_CLASSIFIER"]
128129

130+
def test_change_detection__default(self):
131+
repo_root = tempfile.mkdtemp("root")
132+
os.mkdir(os.path.join(repo_root, "config"))
133+
pom_template_path = self._write_file(repo_root, "WORKSPACE", "foo")
134+
pom_template_path = self._write_file(repo_root, "config/pom_template.xml", "foo")
135+
self._write_file(repo_root, ".pomgenrc", "")
136+
137+
cfg = config.load(repo_root)
138+
139+
self.assertTrue(cfg.change_detection_enabled)
140+
141+
def test_change_detection__enabled(self):
142+
repo_root = tempfile.mkdtemp("root")
143+
os.mkdir(os.path.join(repo_root, "config"))
144+
pom_template_path = self._write_file(repo_root, "WORKSPACE", "foo")
145+
pom_template_path = self._write_file(repo_root, "config/pom_template.xml", "foo")
146+
self._write_file(repo_root, ".pomgenrc", """
147+
[artifact]
148+
change_detection_enabled=True
149+
""")
150+
151+
cfg = config.load(repo_root)
152+
153+
self.assertTrue(cfg.change_detection_enabled)
154+
155+
def test_change_detection__disabled(self):
156+
repo_root = tempfile.mkdtemp("root")
157+
os.mkdir(os.path.join(repo_root, "config"))
158+
pom_template_path = self._write_file(repo_root, "WORKSPACE", "foo")
159+
pom_template_path = self._write_file(repo_root, "config/pom_template.xml", "foo")
160+
self._write_file(repo_root, ".pomgenrc", """
161+
[artifact]
162+
change_detection_enabled=False
163+
""")
164+
165+
cfg = config.load(repo_root)
166+
167+
self.assertFalse(cfg.change_detection_enabled)
168+
129169
def test_str(self):
130170
repo_root = tempfile.mkdtemp("root")
131171
pom_template_path = self._write_file(repo_root, "pom_template", "foo")
@@ -136,24 +176,6 @@ def test_str(self):
136176
self.assertIn("pom_template_path=%s" % pom_template_path, str(cfg))
137177
self.assertIn("maven_install_paths=('maven', 'misc')" , str(cfg))
138178

139-
def _write_pomgenrc(self, repo_root, pom_template_path, maven_install_paths):
140-
content = """[general]
141-
pom_template_path=%s
142-
""" % pom_template_path
143-
144-
if maven_install_paths is not None:
145-
content = content + """
146-
maven_install_paths=%s
147-
""" % maven_install_paths
148-
149-
self._write_file(repo_root, ".pomgenrc", content)
150-
151-
def _write_file(self, repo_root, relative_path, content):
152-
path = os.path.join(repo_root, relative_path)
153-
with open(path, "w") as f:
154-
f.write(content)
155-
return path
156-
157179
def test_pathsep__excluded_dependency_paths(self):
158180
cfg = config.Config(excluded_dependency_paths="abc")
159181
self.assertEqual("abc/", cfg.excluded_dependency_paths[0])
@@ -189,6 +211,25 @@ def test_tuple__excluded_src_file_extensions(self):
189211
self.assertTrue(isinstance(cfg.excluded_src_file_extensions, tuple))
190212
self.assertEqual(0, len(cfg.excluded_src_file_extensions))
191213

214+
def _write_pomgenrc(self, repo_root, pom_template_path, maven_install_paths):
215+
content = """[general]
216+
pom_template_path=%s
217+
""" % pom_template_path
218+
219+
if maven_install_paths is not None:
220+
content = content + """
221+
maven_install_paths=%s
222+
""" % maven_install_paths
223+
224+
self._write_file(repo_root, ".pomgenrc", content)
225+
226+
def _write_file(self, repo_root, relative_path, content):
227+
path = os.path.join(repo_root, relative_path)
228+
with open(path, "w") as f:
229+
f.write(content)
230+
return path
231+
232+
192233
if __name__ == '__main__':
193234
unittest.main()
194235

0 commit comments

Comments
 (0)