Skip to content

Commit b88a193

Browse files
committed
#326 - Fix incorrect data for boolean value
* Added some tests
1 parent b6f0305 commit b88a193

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

src/attributecode/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,6 @@ def process(self, fields, about_file_path, running_inventory=False,
910910
afp = self.about_file_path
911911

912912
errors = self.hydrate(fields)
913-
914913
# We want to copy the license_files before the validation
915914
if reference_dir:
916915
copy_license_notice_files(
@@ -997,6 +996,7 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False, reference_di
997996
# 'Field licenses is a custom field.'
998997
licenses_field = (key, value)
999998
fields.remove(licenses_field)
999+
10001000
errors = self.process(
10011001
fields=fields,
10021002
about_file_path=self.about_file_path,
@@ -1027,9 +1027,9 @@ def dumps(self):
10271027
license_file = []
10281028
license_url = []
10291029
file_fields = ['about_resource', 'notice_file', 'changelog_file', 'author_file']
1030-
bool_fields = ['redistribute', 'attribute', 'track_changes', 'modified']
1030+
bool_fields = ['redistribute', 'attribute', 'track_changes', 'modified', 'internal_use_only']
10311031
for field in self.all_fields():
1032-
if not field.value:
1032+
if not field.value and not field.name in bool_fields:
10331033
continue
10341034

10351035
if field.name == 'license_key' and field.value:
@@ -1046,8 +1046,10 @@ def dumps(self):
10461046
# value of 'about_resource'
10471047
elif field.name in file_fields and field.value:
10481048
data[field.name] = list(field.value.keys())[0]
1049+
elif field.name in bool_fields and not field.value == None:
1050+
data[field.name] = field.value
10491051
else:
1050-
if field.value or (field.name in bool_fields and not field.value == None):
1052+
if field.value:
10511053
data[field.name] = field.value
10521054

10531055
# Group the same license information in a list

src/attributecode/util.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,10 @@ def wrap_boolean_value(context):
134134
key = line.partition(':')[0]
135135
value = line.partition(':')[2].strip()
136136
value = '"' + value + '"'
137-
print(value)
138137
if key in boolean_fields and not value == "":
139138
updated_context += key + ': ' + value + '\n'
140139
else:
141140
updated_context += line + '\n'
142-
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
143-
print(updated_context)
144141
return updated_context
145142

146143
# TODO: rename to normalize_path

tests/test_gen.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,18 @@ def test_generate_not_overwrite_original_license_file(self):
199199
'licenses:\n'
200200
' - file: this.LICENSE\n')
201201
assert expected == result
202+
203+
def test_boolean_value_not_lost(self):
204+
location = get_test_loc('test_gen/inv6.csv')
205+
base_dir = get_temp_dir()
206+
207+
_errors, abouts = gen.generate(location, base_dir)
208+
209+
in_mem_result = [a.dumps() for a in abouts][0]
210+
expected = (u'about_resource: .\n'
211+
u'name: AboutCode\n'
212+
u'version: 0.11.0\n'
213+
u'redistribute: yes\n'
214+
u'attribute: yes\n'
215+
u'modified: no\n')
216+
assert expected == in_mem_result

tests/test_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ def test_About_dumps_does_all_non_empty_present_fields(self):
681681
Error(INFO, 'Field custom2 is a custom field.'),
682682
Error(INFO, 'Field custom2 is present but empty.')
683683
]
684+
print("########################################")
685+
print(a.errors)
684686
assert sorted(expected_error) == sorted(a.errors)
685687

686688
expected = '''about_resource: .

tests/testdata/test_gen/inv6.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
about_file_path,about_resource,name,version,download_url,description,homepage_url,notes,license_name,license_file,license_url,copyright,notice_file,notice_url,redistribute,attribute,track_change,modified,changelog_file,owner,owner_url,contact,author,vcs_tool,vcs_repository,vcs_path,vcs_tag,vcs_branch,vcs_revision,checksum_md5,checksum_sha1,spec_version
2+
inv/this.ABOUT,.,AboutCode,0.11.0,,,,,,,,,,,Yes,Y,,N,,,,,,,,,,,,,,

0 commit comments

Comments
 (0)