Skip to content

Commit d8ad457

Browse files
committed
#35 fixed tests
1 parent c0f308f commit d8ad457

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

about.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def main(parser, args):
11031103
assert False, "Unsupported option(s)."
11041104

11051105

1106-
if __name__ == "__main__":
1106+
def get_parser():
11071107
parser = argparse.ArgumentParser(
11081108
description=SYNTAX, formatter_class=argparse.RawTextHelpFormatter)
11091109
parser.add_argument('--overwrite', action='store_true',
@@ -1115,6 +1115,11 @@ def main(parser, args):
11151115
help=VERBOSITY)
11161116
parser.add_argument('input_path', help='The input path')
11171117
parser.add_argument('output_path', help='The output path')
1118+
return parser
1119+
1120+
1121+
if __name__ == "__main__":
1122+
parser = get_parser()
11181123
args = parser.parse_args()
11191124

11201125
main(parser, args)

tests.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828

2929
class BasicTest(unittest.TestCase):
3030
def test_simple_about_command_line_can_run(self):
31-
testpath = tempfile.NamedTemporaryFile(suffix='.csv', delete=True)
32-
tst_fn = testpath.name
33-
testpath.close()
34-
shutil.rmtree(tst_fn , ignore_errors=True)
35-
assert about.main(['about.ABOUT', tst_fn], []) == None
36-
self.assertTrue(len(open(tst_fn).read()) > 10)
37-
shutil.rmtree(tst_fn, ignore_errors=True)
31+
test_path = tempfile.NamedTemporaryFile(suffix='.csv', delete=True)
32+
test_filename = test_path.name
33+
test_path.close()
34+
shutil.rmtree(test_filename , ignore_errors=True)
35+
parser = about.get_parser()
36+
args = parser.parse_args(['about.ABOUT', test_filename])
37+
38+
assert about.main(parser, args) == None
39+
self.assertTrue(len(open(test_filename).read()) > 10)
40+
shutil.rmtree(test_filename, ignore_errors=True)
3841

3942
def test_return_path_is_not_abspath_and_contains_subdirs_on_file(self):
4043
test_input = "testdata/thirdparty/django_snippets_2413.ABOUT"
@@ -43,7 +46,7 @@ def test_return_path_is_not_abspath_and_contains_subdirs_on_file(self):
4346
os.remove(test_output)
4447
except OSError:
4548
pass
46-
collector = about.AboutCollector(test_input, test_output, '0')
49+
collector = about.AboutCollector(test_input, test_output, 0)
4750
collector.extract_about_info()
4851
self.assertTrue(open(test_output).read().partition('\n')[2].startswith('testdata/thirdparty/django_snippets_2413.ABOUT'))
4952
os.remove(test_output)
@@ -55,7 +58,7 @@ def test_return_path_is_not_abspath_and_contains_subdirs_on_dir(self):
5558
os.remove(test_output)
5659
except OSError:
5760
pass
58-
collector = about.AboutCollector(test_input, test_output, '0')
61+
collector = about.AboutCollector(test_input, test_output, 0)
5962
collector.extract_about_info()
6063
self.assertTrue(open(test_output).read().partition('\n')[2].startswith('testdata/basic'))
6164
os.remove(test_output)

0 commit comments

Comments
 (0)