Skip to content

Commit 0871355

Browse files
committed
Fixed #236
The tool will not log an error in the error.log if a directory name in a file path endswith space.
1 parent 9d2d6b1 commit 0871355

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

about_code_tool/genabout.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def process_dje_licenses(self, dje_license_list, dje_license_dict, output_path):
481481

482482
def pre_generation(self, gen_location, input_list, action_num):
483483
"""
484-
Perfom some pre-generation.
484+
Perform some pre-generation.
485485
TODO: document me
486486
"""
487487
output_list = []
@@ -500,6 +500,18 @@ def pre_generation(self, gen_location, input_list, action_num):
500500
file_location = dirname(file_location)
501501
file_location = join(file_location, basename(file_location))
502502
file_location += '.ABOUT'
503+
# The following code is to check if there is any directory ends with spaces
504+
split_path = file_location.split('/')
505+
dir_endswith_space = False
506+
for segment in split_path:
507+
if segment.endswith(' '):
508+
msg = 'File path contains directory name ends with spaces which is not allowed. Generation skipped.'
509+
self.errors.append(Error(VALUE, 'about_file_path',
510+
file_location, msg))
511+
dir_endswith_space = True
512+
break
513+
if dir_endswith_space:
514+
continue
503515

504516
about_file_location = join(gen_location, file_location)
505517
about_file_dir = dirname(about_file_location)

about_code_tool/tests/test_genabout.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,21 @@ def test_pre_generation_about_exists_action_3(self):
514514
self.assertFalse(gen.warnings, 'No warnings should be returned.')
515515
self.assertFalse(gen.errors, 'No errors should be returned.')
516516

517+
def test_pre_generation_dir_endswith_space(self):
518+
gen = genabout.GenAbout()
519+
test_fields = [{'about_file': '/abc /about.py.ABOUT',
520+
'version': '0.8.2',
521+
'about_resource': '.',
522+
'name': '',
523+
'test': 'test sample'}]
524+
525+
result = gen.pre_generation(GEN_LOCATION,
526+
test_fields,
527+
action_num=0)
528+
529+
self.assertTrue(len(gen.errors) == 1, 'Should return 1 error.')
530+
self.assertTrue(gen.errors, 'It should prompt error because directory ends with sapce')
531+
517532
def test_format_output(self):
518533
gen = genabout.GenAbout()
519534
test_fields = [

0 commit comments

Comments
 (0)