Skip to content

Commit

Permalink
Small adjustments to simplify tests readability (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Mendes authored and kashishm committed Sep 21, 2017
1 parent 2a7dea0 commit 833f336
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 97 deletions.
6 changes: 4 additions & 2 deletions tests/test_data/impl_stubs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from getgauge.python import before_step, step, after_step, before_scenario, after_scenario, before_spec, after_spec, \
before_suite, after_suite, screenshot, continue_on_failure
from getgauge.python import (before_step, step, after_step, before_scenario,
after_scenario, before_spec, after_spec,
before_suite, after_suite, screenshot,
continue_on_failure)


@step("Step 1")
Expand Down
20 changes: 13 additions & 7 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import socket
import unittest
from socket import socket, AF_INET, SOCK_STREAM
from unittest import TestCase, main

from getgauge.messages.messages_pb2 import Message, StepValidateResponse
from getgauge.messages.spec_pb2 import ProtoExecutionResult, Parameter
Expand All @@ -8,7 +8,7 @@
from getgauge.registry import registry


class ProcessorTests(unittest.TestCase):
class ProcessorTests(TestCase):
def setUp(self):
DataStoreFactory.suite_data_store().clear()
DataStoreFactory.spec_data_store().clear()
Expand All @@ -20,7 +20,10 @@ def tearDown(self):

def test_Processor_kill_request(self):
with self.assertRaises(SystemExit):
processors[Message.KillProcessRequest](None, None, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
processors[Message.KillProcessRequest](None,
None,
socket(AF_INET,
SOCK_STREAM))

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

self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
self.assertEqual(False, response.executionStatusResponse.executionResult.failed)
self.assertEqual(0, response.executionStatusResponse.executionResult.executionTime)
self.assertEqual(False,
response.executionStatusResponse.executionResult.failed)

self.assertEqual(0,
response.executionStatusResponse.executionResult.executionTime)

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

Expand Down Expand Up @@ -434,4 +440,4 @@ def failing_impl():


if __name__ == '__main__':
unittest.main()
main()
86 changes: 56 additions & 30 deletions tests/test_python.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import unittest
from unittest import TestCase, main

from getgauge.messages.messages_pb2 import Message
from getgauge.python import Messages, DataStore, DataStoreFactory, Table, Specification, Scenario, Step, \
ExecutionContext, \
create_execution_context_from
from getgauge.registry import registry, _MessagesStore
from getgauge.python import (Messages, DataStore, DataStoreFactory, Table,
Specification, Scenario, Step, ExecutionContext,
create_execution_context_from)

registry.clear()


class MessagesTests(unittest.TestCase):
class MessagesTests(TestCase):
def test_pending_messages(self):
messages = ['HAHAHAH', 'HAHAHAH1', 'HAHAHAH2', 'HAHAHAH3']
for message in messages:
Expand Down Expand Up @@ -45,10 +45,14 @@ def test_pending_messages_gives_only_those_messages_which_are_not_reported(self)
self.assertEqual(messages, pending_messages)


class DataStoreTests(unittest.TestCase):
class DataStoreTests(TestCase):
def test_data_store(self):
store = DataStore()
values = {'key': 'HAHAHAH', 'key1': 'HAHAHAH1', 'key2': 'HAHAHAH2', 'key3': 'HAHAHAH3'}
values = {'key': 'HAHAHAH',
'key1': 'HAHAHAH1',
'key2': 'HAHAHAH2',
'key3': 'HAHAHAH3'}

for value in values:
store.put(value, value)

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

def test_data_store_clear(self):
store = DataStore()
values = {'key': 'HAHAHAH', 'key1': 'HAHAHAH1', 'key2': 'HAHAHAH2', 'key3': 'HAHAHAH3'}
values = {'key': 'HAHAHAH',
'key1': 'HAHAHAH1',
'key2': 'HAHAHAH2',
'key3': 'HAHAHAH3'}

for value in values:
store.put(value, value)

Expand Down Expand Up @@ -92,7 +100,7 @@ def test_data_store_equality(self):
self.assertNotEqual(store, store1)


class DataStoreFactoryTests(unittest.TestCase):
class DataStoreFactoryTests(TestCase):
def test_data_store_factory(self):
scenario_data_store = DataStoreFactory.scenario_data_store()
spec_data_store = DataStoreFactory.spec_data_store()
Expand All @@ -116,7 +124,7 @@ def __init__(self, cells):
self.cells = cells


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

self.assertEqual(headers, table.headers)
self.assertEqual(expected_rows, table.rows)
self.assertEqual(expected_column_1, table.get_column_values_with_index(1))
self.assertEqual(expected_column_2, table.get_column_values_with_index(2))
self.assertEqual(expected_column_1, table.get_column_values_with_name(headers[0]))
self.assertEqual(expected_column_2, table.get_column_values_with_name(headers[1]))
self.assertEqual(expected_column_1,
table.get_column_values_with_index(1))
self.assertEqual(expected_column_2,
table.get_column_values_with_index(2))
self.assertEqual(expected_column_1,
table.get_column_values_with_name(headers[0]))
self.assertEqual(expected_column_2,
table.get_column_values_with_name(headers[1]))

for row in expected_rows:
self.assertEqual(row, table.get_row(expected_rows.index(row) + 1))

Expand Down Expand Up @@ -212,7 +225,7 @@ def test_Table__str__without_rows(self):
|----|-----------|""")


class SpecificationTests(unittest.TestCase):
class SpecificationTests(TestCase):
def test_Specification(self):
name = 'NAME'
file_name = 'FILE_NAME'
Expand All @@ -234,7 +247,7 @@ def test_Specification_equality(self):
self.assertEqual(specification, specification1)


class ScenarioTests(unittest.TestCase):
class ScenarioTests(TestCase):
def test_Scenario(self):
name = 'NAME3'
tags = ['TAGS']
Expand All @@ -253,7 +266,7 @@ def test_Scenario_equality(self):
self.assertEqual(scenario, scenario1)


class StepTests(unittest.TestCase):
class StepTests(TestCase):
def test_Step(self):
name = 'NAME1'
step = Step(name, False)
Expand All @@ -269,7 +282,7 @@ def test_Step_equality(self):
self.assertEqual(step, step1)


class ExecutionContextTests(unittest.TestCase):
class ExecutionContextTests(TestCase):
def test_ExecutionContextTests(self):
name = 'NAME'
file_name = 'FILE_NAME'
Expand Down Expand Up @@ -298,14 +311,25 @@ def test_ExecutionContextTests_equality(self):

def test_create_execution_context_from(self):
message = Message()
spec_name, spec_file_name, scenario_name, step_name = 'SPEC_NAME', 'SPEC_FILE_NAME', 'SCENARIO_NAME', 'STEP_NAME'
message.executionStartingRequest.currentExecutionInfo.currentSpec.name = spec_name
message.executionStartingRequest.currentExecutionInfo.currentSpec.fileName = spec_file_name
message.executionStartingRequest.currentExecutionInfo.currentSpec.isFailed = True
message.executionStartingRequest.currentExecutionInfo.currentScenario.name = scenario_name
message.executionStartingRequest.currentExecutionInfo.currentScenario.isFailed = False
message.executionStartingRequest.currentExecutionInfo.currentStep.step.actualStepText = step_name
message.executionStartingRequest.currentExecutionInfo.currentStep.isFailed = True
spec_name = 'SPEC_NAME'
spec_file_name = 'SPEC_FILE_NAME'
scenario_name = 'SCENARIO_NAME'
step_name = 'STEP_NAME'

message.executionStartingRequest.\
currentExecutionInfo.currentSpec.name = spec_name
message.executionStartingRequest.\
currentExecutionInfo.currentSpec.fileName = spec_file_name
message.executionStartingRequest.\
currentExecutionInfo.currentSpec.isFailed = True
message.executionStartingRequest.\
currentExecutionInfo.currentScenario.name = scenario_name
message.executionStartingRequest.\
currentExecutionInfo.currentScenario.isFailed = False
message.executionStartingRequest.\
currentExecutionInfo.currentStep.step.actualStepText = step_name
message.executionStartingRequest.\
currentExecutionInfo.currentStep.isFailed = True

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


class DecoratorTests(unittest.TestCase):
class DecoratorTests(TestCase):
def setUp(self):
from tests.test_data import impl_stubs
impl_stubs.step1()
Expand All @@ -332,8 +356,10 @@ def test_continue_on_failure(self):
step1 = registry.get_info_for('Step 1').impl
step2 = registry.get_info_for('Step 2').impl

self.assertEqual(registry.is_continue_on_failure(step1, RuntimeError()), False)
self.assertEqual(registry.is_continue_on_failure(step2, RuntimeError()), True)
self.assertEqual(
registry.is_continue_on_failure(step1, RuntimeError()), False)
self.assertEqual(
registry.is_continue_on_failure(step2, RuntimeError()), True)

def test_before_step_decorator(self):
funcs = registry.before_step()
Expand Down Expand Up @@ -382,4 +408,4 @@ def test_screenshot_decorator(self):


if __name__ == '__main__':
unittest.main()
main()
54 changes: 42 additions & 12 deletions tests/test_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ def test_Processor_refactor_request_with_add_param(self):
actual_data = self.getActualText()

self.assertEqual(Message.RefactorResponse, response.messageType)
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
self.assertEqual(True,
response.refactorResponse.success,
response.refactorResponse.error)

self.assertEqual([RefactorTests.path],
response.refactorResponse.filesChanged)

expected = """@step("Vowels in English language is <vowels> <bsdfdsf>.")
def assert_default_vowels(given_vowels, bsdfdsf):
Messages.write_message("Given vowels are {0}".format(given_vowels))
Expand Down Expand Up @@ -80,8 +85,13 @@ def test_Processor_refactor_request_with_add_param_and_invalid_identifier(self):
actual_data = self.getActualText()

self.assertEqual(Message.RefactorResponse, response.messageType)
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
self.assertEqual(True,
response.refactorResponse.success,
response.refactorResponse.error)

self.assertEqual([RefactorTests.path],
response.refactorResponse.filesChanged)

expected = """@step("Vowels in English language is <vowels> <vowels!2_ab%$>.")
def assert_default_vowels(given_vowels, arg1):
Messages.write_message("Given vowels are {0}".format(given_vowels))
Expand Down Expand Up @@ -110,8 +120,13 @@ def test_Processor_refactor_request_with_add_param_and_only_invalid_identifier(s
actual_data = self.getActualText()

self.assertEqual(Message.RefactorResponse, response.messageType)
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
self.assertEqual(True,
response.refactorResponse.success,
response.refactorResponse.error)

self.assertEqual([RefactorTests.path],
response.refactorResponse.filesChanged)

expected = """@step("Vowels in English language is <vowels> <!%$>.")
def assert_default_vowels(given_vowels, arg1):
Messages.write_message("Given vowels are {0}".format(given_vowels))
Expand All @@ -132,8 +147,13 @@ def test_Processor_refactor_request_with_remove_param(self):
actual_data = self.getActualText()

self.assertEqual(Message.RefactorResponse, response.messageType)
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
self.assertEqual(True,
response.refactorResponse.success,
response.refactorResponse.error)

self.assertEqual([RefactorTests.path],
response.refactorResponse.filesChanged)

expected = """@step("Vowels in English language is.")
def assert_default_vowels():
Messages.write_message("Given vowels are {0}".format(given_vowels))
Expand All @@ -159,8 +179,13 @@ def test_Processor_refactor_request(self):
actual_data = self.getActualText()

self.assertEqual(Message.RefactorResponse, response.messageType)
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
self.assertEqual(True,
response.refactorResponse.success,
response.refactorResponse.error)

self.assertEqual([RefactorTests.path],
response.refactorResponse.filesChanged)

expected = """@step("Vowels in English language is <vowels>.")
def assert_default_vowels(given_vowels):
Messages.write_message("Given vowels are {0}".format(given_vowels))
Expand All @@ -186,8 +211,13 @@ def test_Processor_refactor_request_with_add_and_remove_param(self):
actual_data = self.getActualText()

self.assertEqual(Message.RefactorResponse, response.messageType)
self.assertEqual(True, response.refactorResponse.success, response.refactorResponse.error)
self.assertEqual([RefactorTests.path], response.refactorResponse.filesChanged)
self.assertEqual(True,
response.refactorResponse.success,
response.refactorResponse.error)

self.assertEqual([RefactorTests.path],
response.refactorResponse.filesChanged)

expected = """@step("Vowels in English language is <bsdfdsf>.")
def assert_default_vowels(bsdfdsf):
Messages.write_message("Given vowels are {0}".format(given_vowels))
Expand Down
Loading

0 comments on commit 833f336

Please sign in to comment.