Skip to content

Commit 0650bc3

Browse files
author
Shakeel Mohamed
committed
fix more search commands tests + code formatting
1 parent bbaf698 commit 0650bc3

3 files changed

Lines changed: 238 additions & 92 deletions

File tree

‎tests/searchcommands/test_decorators.py‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
import os
2727
import sys
2828

29+
2930
@Configuration()
3031
class SearchCommand(StreamingCommand):
31-
3232
def stream(self, records):
3333
pass
3434

3535

3636
class TestDecorators(unittest.TestCase):
37-
3837
def setUp(self):
3938
super(TestDecorators, self).setUp()
4039
return
@@ -59,12 +58,14 @@ def test_builtin_options(self):
5958
if type(level) is int:
6059
command.logging_level = level
6160
level_name = logging.getLevelName(level)
62-
self.assertEquals(command.logging_level, warning if level_name == notset else level_name)
61+
self.assertEquals(command.logging_level,
62+
warning if level_name == notset else level_name)
6363
else:
6464
level_name = logging.getLevelName(logging.getLevelName(level))
6565
for variant in level, level.lower(), level.capitalize():
6666
command.logging_level = variant
67-
self.assertEquals(command.logging_level, warning if level_name == notset else level_name)
67+
self.assertEquals(command.logging_level,
68+
warning if level_name == notset else level_name)
6869

6970
# logging_level accepts any numeric value
7071

@@ -83,11 +84,13 @@ def test_builtin_options(self):
8384
except BaseException as e:
8485
self.fail('Expected ValueError, but %s was raised' % type(e))
8586
else:
86-
self.fail('Expected ValueError, but logging_level=%s' % command.logging_level)
87+
self.fail(
88+
'Expected ValueError, but logging_level=%s' % command.logging_level)
8789

8890
self.assertEqual(command.logging_level, current_value)
8991

90-
app_root = os.path.join(TestDecorators._package_directory, 'data', 'app')
92+
app_root = os.path.join(TestDecorators._package_directory, 'data',
93+
'app')
9194
command = SearchCommand() # guarantee: no logging.conf
9295
directory = os.getcwd()
9396
os.chdir(os.path.join(app_root, 'bin'))
@@ -105,27 +108,33 @@ def test_builtin_options(self):
105108
self.assertEqual(len(command.logger.handlers), 0)
106109

107110
# TODO: capture this output and verify it
108-
command.logger.warning('Test that output is directed to stderr without formatting')
111+
command.logger.warning(
112+
'Test that output is directed to stderr without formatting')
109113

110-
default_logging_configuration = os.path.join(directory, app_root, 'default', 'logging.conf')
114+
default_logging_configuration = os.path.join(directory, app_root,
115+
'default',
116+
'logging.conf')
111117

112118
# A search command loads {local,default}/logging.conf when it is
113119
# available
114120

115121
command = SearchCommand() # guarantee: default/logging.conf
116-
self.assertEqual(command.logging_configuration, default_logging_configuration)
122+
self.assertEqual(command.logging_configuration,
123+
default_logging_configuration)
117124

118125
# logging_configuration loads a new logging configuration file
119126
# relative to the app root
120127

121128
command.logging_configuration = 'logging.conf'
122-
self.assertEqual(command.logging_configuration, default_logging_configuration)
129+
self.assertEqual(command.logging_configuration,
130+
default_logging_configuration)
123131

124132
# logging_configuration loads a new logging configuration file on an
125133
# absolute path
126134

127135
command.logging_configuration = default_logging_configuration
128-
self.assertEqual(command.logging_configuration, default_logging_configuration)
136+
self.assertEqual(command.logging_configuration,
137+
default_logging_configuration)
129138

130139
# logging_configuration raises a value error, if a non-existent
131140
# logging configuration file is provided
@@ -137,16 +146,20 @@ def test_builtin_options(self):
137146
except BaseException as e:
138147
self.fail('Expected ValueError, but %s was raised' % type(e))
139148
else:
140-
self.fail('Expected ValueError, but logging_configuration=%s' % command.logging_configuration)
149+
self.fail(
150+
'Expected ValueError, but logging_configuration=%s' % command.logging_configuration)
141151

142152
try:
143-
command.logging_configuration = os.path.join(TestDecorators._package_directory, 'non-existent.logging.conf')
153+
command.logging_configuration = os.path.join(
154+
TestDecorators._package_directory,
155+
'non-existent.logging.conf')
144156
except ValueError:
145157
pass
146158
except BaseException as e:
147159
self.fail('Expected ValueError, but %s was raised' % type(e))
148160
else:
149-
self.fail('Expected ValueError, but logging_configuration=%s' % command.logging_configuration)
161+
self.fail(
162+
'Expected ValueError, but logging_configuration=%s' % command.logging_configuration)
150163

151164
finally:
152165
os.chdir(directory)
@@ -163,7 +176,8 @@ def test_builtin_options(self):
163176
for value in boolean_values:
164177
for variant in [value, value.capitalize(), value.upper()]:
165178
command.show_configuration = variant
166-
self.assertEquals(command.show_configuration, boolean_values[value])
179+
self.assertEquals(command.show_configuration,
180+
boolean_values[value])
167181

168182
for value in 'any-other-string', 13:
169183
try:
@@ -173,7 +187,8 @@ def test_builtin_options(self):
173187
except BaseException as e:
174188
self.fail('Expected ValueError, but %s was raised' % type(e))
175189
else:
176-
self.fail('Expected ValueError, but show_configuration=%s' % command.show_configuration)
190+
self.fail(
191+
'Expected ValueError, but show_configuration=%s' % command.show_configuration)
177192

178193
# SearchCommandParser recognizes each built-in option
179194

@@ -185,5 +200,6 @@ def test_builtin_options(self):
185200

186201
_package_directory = os.path.dirname(__file__)
187202

203+
188204
if __name__ == "__main__":
189205
unittest.main()

0 commit comments

Comments
 (0)