Skip to content

Commit a81a7c8

Browse files
committed
find and test_find upgrade
Updated find.py and test_find.py adding tests for unknown arguments.
1 parent 8194fd8 commit a81a7c8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: find.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import fnmatch
66
import io
7+
import sys
78

89

910
parser = argparse.ArgumentParser()
@@ -13,11 +14,15 @@
1314
parser.add_argument("-name", help="name of file")
1415
parser.add_argument("-type", help="type: be it a file or dir", choices='df')
1516

16-
args = parser.parse_args()
17-
18-
global results_found
1917
results_found = False
2018

19+
def initialize_args(argslist = sys.argv[1:]):
20+
global args
21+
global parser
22+
args = parser.parse_args(argslist)
23+
24+
return args
25+
2126
def do_search(provided_path, regex_pattern, name_to_match, type_ForD):
2227
outputFromSearch = io.StringIO()
2328

@@ -72,6 +77,7 @@ def search_recursively(provided_path, regex_pattern, name_to_match, type_ForD):
7277

7378

7479
#execute the search
80+
initArgs = initialize_args()
7581
results = do_search(args.path, args.regex, args.name, args.type)
7682
print(results.getvalue())
7783
results.close()

Diff for: test_find.py

+6
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ def test_type_works_with_name_specified(self):
138138

139139
self.assertEqual(actual_output.getvalue(), theoretical_output.getvalue())
140140

141+
def test_unknown_args_throws_error(self):
142+
try:
143+
actual_result = find.initialize_args(['-magic'])
144+
assert False
145+
except:
146+
pass
141147

142148
def tearDown(self):
143149
global tmp_dir_previously_existed

0 commit comments

Comments
 (0)