Skip to content

Commit 74381f7

Browse files
author
Shakeel Mohamed
committed
search command tests: clean up hard-coded paths and line numbers
1 parent d3f3a8f commit 74381f7

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

‎tests/searchcommands/test_search_command.py‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,13 @@ def test_process(self):
9494
# Command.process should produce an error record on parser errors, if
9595
# invoked to get configuration settings
9696

97-
expected = \
97+
expected_pattern = re.compile(
9898
'\r\n' \
9999
'ERROR\r\n' \
100-
'"ValueError at ""/Users/smohamed/git/splunk-sdk-python/splunklib/searchcommands/search_command_internals.py"", line 282 : ' \
101-
'Unrecognized option: undefined_option = value"\r\n'
102-
103-
expected_pattern = re.compile(
104-
'\r\n' +
105-
'ERROR\r\n' +
106-
'"ValueError at ""/Users/smohamed/git/splunk-sdk-python/splunklib/searchcommands/search_command_internals.py"", line \d\d\d : ' +
100+
'"ValueError at ""' + \
101+
os.path.abspath(os.path.join(os.path.dirname(__file__),
102+
"../../splunklib/searchcommands/search_command_internals.py")) + \
103+
'"", line \d\d\d : ' \
107104
'Unrecognized option: undefined_option = value"\r\n'
108105
)
109106

@@ -118,13 +115,8 @@ def test_process(self):
118115
self.assertTrue(expected_pattern.match(observed))
119116

120117
# Command.process should produce an error message and exit on parser
121-
# errors, if invoked to execute
122-
123-
expected = \
124-
'\r\n' \
125-
'ERROR\r\n' \
126-
'"ValueError at ""/Users/smohamed/git/splunk-sdk-python/splunklib/searchcommands/search_command_internals.py"", line 282 : ' \
127-
'Unrecognized option: undefined_option = value"\r\n'
118+
# errors, if invoked to execute. Same error message as expected_pattern
119+
# defined above
128120

129121
command = SearchCommand()
130122
result = StringIO()
@@ -137,18 +129,21 @@ def test_process(self):
137129
result.reset()
138130
observed = result.read()
139131
self.assertNotEqual(e.code, 0)
140-
self.assertEqual(expected, observed)
132+
self.assertTrue(expected_pattern.match(observed))
141133
except BaseException as e:
142134
self.fail("Expected SystemExit, but caught %s" % type(e))
143135
else:
144136
self.fail("Expected SystemExit, but no exception was raised")
145137

146138
# Command.process should exit on processing exceptions
147139

148-
expected = \
140+
expected_pattern = re.compile(
149141
'\r\n' \
150142
'ERROR\r\n' \
151-
'"TypeError at ""/Users/smohamed/git/splunk-sdk-python/splunklib/searchcommands/splunk_csv/dict_reader.py"", line 38 : \'NoneType\' object is not iterable"\r\n'
143+
'"TypeError at ""' + \
144+
os.path.abspath(os.path.join(os.path.dirname(__file__),
145+
"../../splunklib/searchcommands/splunk_csv/dict_reader.py")) + \
146+
'"", line \d\d : \'NoneType\' object is not iterable"\r\n')
152147

153148
command = SearchCommand()
154149
result = StringIO()
@@ -161,7 +156,7 @@ def test_process(self):
161156
result.reset()
162157
observed = result.read()
163158
self.assertNotEqual(e.code, 0)
164-
self.assertEqual(expected, observed)
159+
self.assertTrue(expected_pattern.match(observed))
165160
except BaseException as e:
166161
self.fail("Expected SystemExit, but caught %s" % type(e))
167162
else:

0 commit comments

Comments
 (0)