Skip to content

Commit 833f336

Browse files
Eduardo Mendeskashishm
authored andcommitted
Small adjustments to simplify tests readability (#12)
1 parent 2a7dea0 commit 833f336

File tree

5 files changed

+242
-97
lines changed

5 files changed

+242
-97
lines changed

tests/test_data/impl_stubs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from getgauge.python import before_step, step, after_step, before_scenario, after_scenario, before_spec, after_spec, \
2-
before_suite, after_suite, screenshot, continue_on_failure
1+
from getgauge.python import (before_step, step, after_step, before_scenario,
2+
after_scenario, before_spec, after_spec,
3+
before_suite, after_suite, screenshot,
4+
continue_on_failure)
35

46

57
@step("Step 1")

tests/test_processor.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import socket
2-
import unittest
1+
from socket import socket, AF_INET, SOCK_STREAM
2+
from unittest import TestCase, main
33

44
from getgauge.messages.messages_pb2 import Message, StepValidateResponse
55
from getgauge.messages.spec_pb2 import ProtoExecutionResult, Parameter
@@ -8,7 +8,7 @@
88
from getgauge.registry import registry
99

1010

11-
class ProcessorTests(unittest.TestCase):
11+
class ProcessorTests(TestCase):
1212
def setUp(self):
1313
DataStoreFactory.suite_data_store().clear()
1414
DataStoreFactory.spec_data_store().clear()
@@ -20,7 +20,10 @@ def tearDown(self):
2020

2121
def test_Processor_kill_request(self):
2222
with self.assertRaises(SystemExit):
23-
processors[Message.KillProcessRequest](None, None, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
23+
processors[Message.KillProcessRequest](None,
24+
None,
25+
socket(AF_INET,
26+
SOCK_STREAM))
2427

2528
def test_Processor_suite_data_store_init_request(self):
2629
DataStoreFactory.suite_data_store().put('suite', 'value')
@@ -31,8 +34,11 @@ def test_Processor_suite_data_store_init_request(self):
3134
processors[Message.SuiteDataStoreInit](None, response, None)
3235

3336
self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
34-
self.assertEqual(False, response.executionStatusResponse.executionResult.failed)
35-
self.assertEqual(0, response.executionStatusResponse.executionResult.executionTime)
37+
self.assertEqual(False,
38+
response.executionStatusResponse.executionResult.failed)
39+
40+
self.assertEqual(0,
41+
response.executionStatusResponse.executionResult.executionTime)
3642

3743
self.assertEqual(DataStore(), DataStoreFactory.suite_data_store())
3844

@@ -434,4 +440,4 @@ def failing_impl():
434440

435441

436442
if __name__ == '__main__':
437-
unittest.main()
443+
main()

tests/test_python.py

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import unittest
1+
from unittest import TestCase, main
22

33
from getgauge.messages.messages_pb2 import Message
4-
from getgauge.python import Messages, DataStore, DataStoreFactory, Table, Specification, Scenario, Step, \
5-
ExecutionContext, \
6-
create_execution_context_from
74
from getgauge.registry import registry, _MessagesStore
5+
from getgauge.python import (Messages, DataStore, DataStoreFactory, Table,
6+
Specification, Scenario, Step, ExecutionContext,
7+
create_execution_context_from)
88

99
registry.clear()
1010

1111

12-
class MessagesTests(unittest.TestCase):
12+
class MessagesTests(TestCase):
1313
def test_pending_messages(self):
1414
messages = ['HAHAHAH', 'HAHAHAH1', 'HAHAHAH2', 'HAHAHAH3']
1515
for message in messages:
@@ -45,10 +45,14 @@ def test_pending_messages_gives_only_those_messages_which_are_not_reported(self)
4545
self.assertEqual(messages, pending_messages)
4646

4747

48-
class DataStoreTests(unittest.TestCase):
48+
class DataStoreTests(TestCase):
4949
def test_data_store(self):
5050
store = DataStore()
51-
values = {'key': 'HAHAHAH', 'key1': 'HAHAHAH1', 'key2': 'HAHAHAH2', 'key3': 'HAHAHAH3'}
51+
values = {'key': 'HAHAHAH',
52+
'key1': 'HAHAHAH1',
53+
'key2': 'HAHAHAH2',
54+
'key3': 'HAHAHAH3'}
55+
5256
for value in values:
5357
store.put(value, value)
5458

@@ -60,7 +64,11 @@ def test_data_store(self):
6064

6165
def test_data_store_clear(self):
6266
store = DataStore()
63-
values = {'key': 'HAHAHAH', 'key1': 'HAHAHAH1', 'key2': 'HAHAHAH2', 'key3': 'HAHAHAH3'}
67+
values = {'key': 'HAHAHAH',
68+
'key1': 'HAHAHAH1',
69+
'key2': 'HAHAHAH2',
70+
'key3': 'HAHAHAH3'}
71+
6472
for value in values:
6573
store.put(value, value)
6674

@@ -92,7 +100,7 @@ def test_data_store_equality(self):
92100
self.assertNotEqual(store, store1)
93101

94102

95-
class DataStoreFactoryTests(unittest.TestCase):
103+
class DataStoreFactoryTests(TestCase):
96104
def test_data_store_factory(self):
97105
scenario_data_store = DataStoreFactory.scenario_data_store()
98106
spec_data_store = DataStoreFactory.spec_data_store()
@@ -116,7 +124,7 @@ def __init__(self, cells):
116124
self.cells = cells
117125

118126

119-
class TableTests(unittest.TestCase):
127+
class TableTests(TestCase):
120128
def test_Table(self):
121129
headers = ['Product', 'Description']
122130
rows = [{'cells': ['Gauge', 'Test automation with ease']},
@@ -134,10 +142,15 @@ def test_Table(self):
134142

135143
self.assertEqual(headers, table.headers)
136144
self.assertEqual(expected_rows, table.rows)
137-
self.assertEqual(expected_column_1, table.get_column_values_with_index(1))
138-
self.assertEqual(expected_column_2, table.get_column_values_with_index(2))
139-
self.assertEqual(expected_column_1, table.get_column_values_with_name(headers[0]))
140-
self.assertEqual(expected_column_2, table.get_column_values_with_name(headers[1]))
145+
self.assertEqual(expected_column_1,
146+
table.get_column_values_with_index(1))
147+
self.assertEqual(expected_column_2,
148+
table.get_column_values_with_index(2))
149+
self.assertEqual(expected_column_1,
150+
table.get_column_values_with_name(headers[0]))
151+
self.assertEqual(expected_column_2,
152+
table.get_column_values_with_name(headers[1]))
153+
141154
for row in expected_rows:
142155
self.assertEqual(row, table.get_row(expected_rows.index(row) + 1))
143156

@@ -212,7 +225,7 @@ def test_Table__str__without_rows(self):
212225
|----|-----------|""")
213226

214227

215-
class SpecificationTests(unittest.TestCase):
228+
class SpecificationTests(TestCase):
216229
def test_Specification(self):
217230
name = 'NAME'
218231
file_name = 'FILE_NAME'
@@ -234,7 +247,7 @@ def test_Specification_equality(self):
234247
self.assertEqual(specification, specification1)
235248

236249

237-
class ScenarioTests(unittest.TestCase):
250+
class ScenarioTests(TestCase):
238251
def test_Scenario(self):
239252
name = 'NAME3'
240253
tags = ['TAGS']
@@ -253,7 +266,7 @@ def test_Scenario_equality(self):
253266
self.assertEqual(scenario, scenario1)
254267

255268

256-
class StepTests(unittest.TestCase):
269+
class StepTests(TestCase):
257270
def test_Step(self):
258271
name = 'NAME1'
259272
step = Step(name, False)
@@ -269,7 +282,7 @@ def test_Step_equality(self):
269282
self.assertEqual(step, step1)
270283

271284

272-
class ExecutionContextTests(unittest.TestCase):
285+
class ExecutionContextTests(TestCase):
273286
def test_ExecutionContextTests(self):
274287
name = 'NAME'
275288
file_name = 'FILE_NAME'
@@ -298,14 +311,25 @@ def test_ExecutionContextTests_equality(self):
298311

299312
def test_create_execution_context_from(self):
300313
message = Message()
301-
spec_name, spec_file_name, scenario_name, step_name = 'SPEC_NAME', 'SPEC_FILE_NAME', 'SCENARIO_NAME', 'STEP_NAME'
302-
message.executionStartingRequest.currentExecutionInfo.currentSpec.name = spec_name
303-
message.executionStartingRequest.currentExecutionInfo.currentSpec.fileName = spec_file_name
304-
message.executionStartingRequest.currentExecutionInfo.currentSpec.isFailed = True
305-
message.executionStartingRequest.currentExecutionInfo.currentScenario.name = scenario_name
306-
message.executionStartingRequest.currentExecutionInfo.currentScenario.isFailed = False
307-
message.executionStartingRequest.currentExecutionInfo.currentStep.step.actualStepText = step_name
308-
message.executionStartingRequest.currentExecutionInfo.currentStep.isFailed = True
314+
spec_name = 'SPEC_NAME'
315+
spec_file_name = 'SPEC_FILE_NAME'
316+
scenario_name = 'SCENARIO_NAME'
317+
step_name = 'STEP_NAME'
318+
319+
message.executionStartingRequest.\
320+
currentExecutionInfo.currentSpec.name = spec_name
321+
message.executionStartingRequest.\
322+
currentExecutionInfo.currentSpec.fileName = spec_file_name
323+
message.executionStartingRequest.\
324+
currentExecutionInfo.currentSpec.isFailed = True
325+
message.executionStartingRequest.\
326+
currentExecutionInfo.currentScenario.name = scenario_name
327+
message.executionStartingRequest.\
328+
currentExecutionInfo.currentScenario.isFailed = False
329+
message.executionStartingRequest.\
330+
currentExecutionInfo.currentStep.step.actualStepText = step_name
331+
message.executionStartingRequest.\
332+
currentExecutionInfo.currentStep.isFailed = True
309333

310334
specification = Specification(spec_name, spec_file_name, True, [])
311335
scenario = Scenario(scenario_name, False, [])
@@ -318,7 +342,7 @@ def test_create_execution_context_from(self):
318342
self.assertEqual(expected_execution_context, context)
319343

320344

321-
class DecoratorTests(unittest.TestCase):
345+
class DecoratorTests(TestCase):
322346
def setUp(self):
323347
from tests.test_data import impl_stubs
324348
impl_stubs.step1()
@@ -332,8 +356,10 @@ def test_continue_on_failure(self):
332356
step1 = registry.get_info_for('Step 1').impl
333357
step2 = registry.get_info_for('Step 2').impl
334358

335-
self.assertEqual(registry.is_continue_on_failure(step1, RuntimeError()), False)
336-
self.assertEqual(registry.is_continue_on_failure(step2, RuntimeError()), True)
359+
self.assertEqual(
360+
registry.is_continue_on_failure(step1, RuntimeError()), False)
361+
self.assertEqual(
362+
registry.is_continue_on_failure(step2, RuntimeError()), True)
337363

338364
def test_before_step_decorator(self):
339365
funcs = registry.before_step()
@@ -382,4 +408,4 @@ def test_screenshot_decorator(self):
382408

383409

384410
if __name__ == '__main__':
385-
unittest.main()
411+
main()

tests/test_refactor.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ def test_Processor_refactor_request_with_add_param(self):
5050
actual_data = self.getActualText()
5151

5252
self.assertEqual(Message.RefactorResponse, response.messageType)
53-
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
54-
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
53+
self.assertEqual(True,
54+
response.refactorResponse.success,
55+
response.refactorResponse.error)
56+
57+
self.assertEqual([RefactorTests.path],
58+
response.refactorResponse.filesChanged)
59+
5560
expected = """@step("Vowels in English language is <vowels> <bsdfdsf>.")
5661
def assert_default_vowels(given_vowels, bsdfdsf):
5762
Messages.write_message("Given vowels are {0}".format(given_vowels))
@@ -80,8 +85,13 @@ def test_Processor_refactor_request_with_add_param_and_invalid_identifier(self):
8085
actual_data = self.getActualText()
8186

8287
self.assertEqual(Message.RefactorResponse, response.messageType)
83-
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
84-
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
88+
self.assertEqual(True,
89+
response.refactorResponse.success,
90+
response.refactorResponse.error)
91+
92+
self.assertEqual([RefactorTests.path],
93+
response.refactorResponse.filesChanged)
94+
8595
expected = """@step("Vowels in English language is <vowels> <vowels!2_ab%$>.")
8696
def assert_default_vowels(given_vowels, arg1):
8797
Messages.write_message("Given vowels are {0}".format(given_vowels))
@@ -110,8 +120,13 @@ def test_Processor_refactor_request_with_add_param_and_only_invalid_identifier(s
110120
actual_data = self.getActualText()
111121

112122
self.assertEqual(Message.RefactorResponse, response.messageType)
113-
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
114-
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
123+
self.assertEqual(True,
124+
response.refactorResponse.success,
125+
response.refactorResponse.error)
126+
127+
self.assertEqual([RefactorTests.path],
128+
response.refactorResponse.filesChanged)
129+
115130
expected = """@step("Vowels in English language is <vowels> <!%$>.")
116131
def assert_default_vowels(given_vowels, arg1):
117132
Messages.write_message("Given vowels are {0}".format(given_vowels))
@@ -132,8 +147,13 @@ def test_Processor_refactor_request_with_remove_param(self):
132147
actual_data = self.getActualText()
133148

134149
self.assertEqual(Message.RefactorResponse, response.messageType)
135-
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
136-
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
150+
self.assertEqual(True,
151+
response.refactorResponse.success,
152+
response.refactorResponse.error)
153+
154+
self.assertEqual([RefactorTests.path],
155+
response.refactorResponse.filesChanged)
156+
137157
expected = """@step("Vowels in English language is.")
138158
def assert_default_vowels():
139159
Messages.write_message("Given vowels are {0}".format(given_vowels))
@@ -159,8 +179,13 @@ def test_Processor_refactor_request(self):
159179
actual_data = self.getActualText()
160180

161181
self.assertEqual(Message.RefactorResponse, response.messageType)
162-
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
163-
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
182+
self.assertEqual(True,
183+
response.refactorResponse.success,
184+
response.refactorResponse.error)
185+
186+
self.assertEqual([RefactorTests.path],
187+
response.refactorResponse.filesChanged)
188+
164189
expected = """@step("Vowels in English language is <vowels>.")
165190
def assert_default_vowels(given_vowels):
166191
Messages.write_message("Given vowels are {0}".format(given_vowels))
@@ -186,8 +211,13 @@ def test_Processor_refactor_request_with_add_and_remove_param(self):
186211
actual_data = self.getActualText()
187212

188213
self.assertEqual(Message.RefactorResponse, response.messageType)
189-
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
190-
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
214+
self.assertEqual(True,
215+
response.refactorResponse.success,
216+
response.refactorResponse.error)
217+
218+
self.assertEqual([RefactorTests.path],
219+
response.refactorResponse.filesChanged)
220+
191221
expected = """@step("Vowels in English language is <bsdfdsf>.")
192222
def assert_default_vowels(bsdfdsf):
193223
Messages.write_message("Given vowels are {0}".format(given_vowels))

0 commit comments

Comments
 (0)