Skip to content

Commit

Permalink
Improve error message when the about_file path in the input CSV contains
Browse files Browse the repository at this point in the history
directory which ends with spaces.
See #236
  • Loading branch information
chinyeungli committed Feb 26, 2016
1 parent 0de1af0 commit 6c05160
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions about_code_tool/gen.py
Expand Up @@ -184,7 +184,24 @@ def generate(location, base_dir, policy=None, conf_location=None,
# TODO: check the paths overlap ...???
# For some reasons, the join does not work, using the '+' for now
# dump_loc = posixpath.join(bdir, about.about_file_path)

dump_loc = bdir + about.about_file_path

# The following code is to check if there is any directory ends with spaces
split_path = about.about_file_path.split('/')
dir_endswith_space = False
for segment in split_path:
if segment.endswith(' '):
msg = (u'File path : '
u'%(dump_loc)s '
u'contains directory name ends with spaces which is not '
u'allowed. Generation skipped.' % locals())
errors.append(Error(ERROR, msg))
dir_endswith_space = True
break
if dir_endswith_space:
continue

try:
# Write the ABOUT file
about.dump(dump_loc,
Expand Down
12 changes: 12 additions & 0 deletions about_code_tool/tests/test_gen.py
Expand Up @@ -66,6 +66,18 @@ def test_load_inventory(self):
for a in abouts]
assert expected == result

def test_generation_dir_endswith_space(self):
location = get_test_loc('inventory/complex/about_file_path_dir_endswith_space.csv')
gen_dir = get_temp_dir()

errors, abouts = gen.generate(location,
base_dir=gen_dir,
with_empty=False, with_absent=False)

expected_errors_msg = 'contains directory name ends with spaces which is not allowed. Generation skipped.'
assert (len(errors) == 1, 'Should return 1 error.')
assert expected_errors_msg in errors[0].message

@expectedFailure
def test_generate(self):
location = get_test_loc('gen/inv.csv')
Expand Down
@@ -0,0 +1,2 @@
about_file_path,about_resource_path,about_resource,name,version
about /about.ABOUT,about,.,AboutCode,0.11.0

0 comments on commit 6c05160

Please sign in to comment.