Skip to content

Commit

Permalink
Merge pull request #142 from gregoil/no_succes_after_expect
Browse files Browse the repository at this point in the history
Converted success message to info
  • Loading branch information
gregoil committed May 16, 2019
2 parents cd12cc6 + 7fdf3ec commit 7f76b6b
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 29 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages


__version__ = "7.2.2"
__version__ = "7.3.0"

result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
Expand Down
2 changes: 1 addition & 1 deletion src/rotest/core/abstract_test.py
Expand Up @@ -404,7 +404,7 @@ def addSuccess(self, msg):
Args:
msg (str): success message to add to the result.
"""
self.result.addSuccess(self, msg)
self.result.addInfo(self, msg)

# Shortcuts
success = addSuccess
Expand Down
10 changes: 9 additions & 1 deletion src/rotest/core/result/handlers/abstract_handler.py
Expand Up @@ -97,9 +97,17 @@ def stop_test_run(self):
"""Called once after all tests are executed."""
pass

def add_success(self, test, msg):
def add_success(self, test):
"""Called when a test has completed successfully.
Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
"""
pass

def add_info(self, test, msg):
"""Called when a test registers a success message.
Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
msg (str): success message.
Expand Down
10 changes: 9 additions & 1 deletion src/rotest/core/result/handlers/db_handler.py
Expand Up @@ -140,11 +140,19 @@ def stop_composite(self, test):
"""
test.data.save()

def add_success(self, test, msg):
def add_success(self, test):
"""Save the test data result as success.

Args:
test (object): test item instance.
"""
test.data.save()

def add_info(self, test, msg):
"""Called when a test registers a success message.

Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
msg (str): success message.
"""
test.data.save()
Expand Down
11 changes: 10 additions & 1 deletion src/rotest/core/result/handlers/excel_handler.py
Expand Up @@ -207,11 +207,20 @@ def update_resources(self, test):
self._write_to_cell(self.test_to_row[test.identifier], self.RESOURCES,
self.DEFAULT_CELL_STYLE, resources)

def add_success(self, test, msg):
def add_success(self, test):
"""Update the test Excel entry's result to success.

Args:
test (object): test item instance.
"""
self._write_test_result(test)
self.workbook.save(self.output_file_path)

def add_info(self, test, msg):
"""Called when a test registers a success message.

Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
msg (str): success message.
"""
self._write_test_result(test)
Expand Down
10 changes: 9 additions & 1 deletion src/rotest/core/result/handlers/remote_db_handler.py
Expand Up @@ -95,11 +95,19 @@ def stop_composite(self, test):
"""
self.client.stop_composite(test)

def add_success(self, test, msg):
def add_success(self, test):
"""Save the remote test data result as success.

Args:
test (object): test item instance.
"""
self.client.add_result(test, TestOutcome.SUCCESS)

def add_info(self, test, msg):
"""Called when a test registers a success message.

Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
msg (str): success message.
"""
self.client.add_result(test, TestOutcome.SUCCESS, msg)
Expand Down
3 changes: 1 addition & 2 deletions src/rotest/core/result/handlers/stream/dots_handler.py
Expand Up @@ -35,12 +35,11 @@ class DotsHandler(BaseStreamHandler):
NAME = 'dots'

@ignore_subtests
def add_success(self, test, msg):
def add_success(self, test):
"""Write the test success to the stream.

Args:
test (rotest.core.case.TestCase): test item instance.
msg (str): success message.
"""
self.stream.write('.', GREEN)

Expand Down
2 changes: 1 addition & 1 deletion src/rotest/core/result/handlers/stream/log_handler.py
Expand Up @@ -61,7 +61,7 @@ class PrettyHandler(LogStreamHandler):
def start_test(self, test):
self.stream.writeln(str(Pretty(test, TestResult.started)))

def add_success(self, test, msg):
def add_success(self, test):
self.stream.writeln(str(Pretty(test, TestResult.success)))

def add_skip(self, test, reason):
Expand Down
15 changes: 11 additions & 4 deletions src/rotest/core/result/handlers/stream/stream_handler.py
Expand Up @@ -54,16 +54,23 @@ def stop_test_run(self):
"""Write the test run end to the stream."""
self.stream.writeln('Tests Run Finished', None, BOLD)

def add_success(self, test, msg):
def add_success(self, test):
"""Write the test success to the stream.

Args:
test (TestCase): test item instance.
msg (str): success message.
"""
self.stream.writeln('Success: %s' % test, GREEN)
if msg is not None:
self.write_details(msg, color=GREEN)

def add_info(self, test, msg):
"""Called when a test registers a success message.

Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
msg (str): success message.
"""
self.stream.writeln('Success msg: %s' % test, GREEN)
self.write_details(msg, color=GREEN)

def add_skip(self, test, reason):
"""Write the test skip to the stream.
Expand Down
3 changes: 1 addition & 2 deletions src/rotest/core/result/handlers/stream/tree_handler.py
Expand Up @@ -46,12 +46,11 @@ def start_composite(self, test):
"""
self.start_test(test)

def add_success(self, test, msg):
def add_success(self, test):
"""Write the test success to the stream.

Args:
test (TestCase): test item instance.
msg (str): success message.
"""
if test.IS_COMPLEX:
indentation = test.parents_count * self.INDENTATION
Expand Down
27 changes: 22 additions & 5 deletions src/rotest/core/result/result.py
Expand Up @@ -193,22 +193,39 @@ def stopTestRun(self):
for result_handler in self.result_handlers:
result_handler.stop_test_run()

def addSuccess(self, test, msg=None):
def addSuccess(self, test):
"""Called when a test has completed successfully.

Args:
test (object): test item instance.
msg (str): success message.
"""
test.end(test_outcome=TestOutcome.SUCCESS, details=msg)
test.end(test_outcome=TestOutcome.SUCCESS)

if test.data.exception_type is not TestOutcome.SUCCESS:
# There was a stored failure in the test
return

if test.is_main:
super(Result, self).addSuccess(test)

test.logger.debug("Test %r ended successfully: %r", test.data, msg)
test.logger.debug("Test %r ended successfully", test.data)

for result_handler in self.result_handlers:
result_handler.add_success(test)

def addInfo(self, test, msg=None):
"""Called when a test registers a success message.

Args:
test (object): test item instance.
msg (str): success message.
"""
test.end(test_outcome=TestOutcome.SUCCESS, details=msg)

test.logger.debug("Test %r registered success: %r", test.data, msg)

for result_handler in self.result_handlers:
result_handler.add_success(test, msg)
result_handler.add_info(test, msg)

def addSkip(self, test, reason):
"""Called when a test is skipped.
Expand Down
13 changes: 12 additions & 1 deletion src/rotest/core/runners/multiprocess/manager/message_handler.py
Expand Up @@ -11,7 +11,8 @@
from rotest.management.common.parsers import DEFAULT_PARSER
from rotest.core.runners.multiprocess.common import (WrappedException,
get_item_by_id)
from rotest.management.common.messages import (StopTest,
from rotest.management.common.messages import (AddInfo,
StopTest,
StartTest,
AddResult,
ShouldSkip,
Expand Down Expand Up @@ -58,6 +59,7 @@ def __init__(self, multiprocess_runner, result, main_test):
TestOutcome.UNEXPECTED_SUCCESS: self.result.addUnexpectedSuccess}

self.message_handlers = {
AddInfo: self._handle_info_message,
AddResult: self._handle_end_message,
StopTest: self._handle_stop_message,
StartTest: self._handle_start_message,
Expand Down Expand Up @@ -194,6 +196,15 @@ def _handle_setup_finished_message(self, test, message):
"""
self.result.setupFinished(test)

def _handle_info_message(self, test, message):
"""Handle SetupFinished of a worker.

Args:
test (object): test item to update.
message (StartTest): worker message object.
"""
self.result.addInfo(test, message.info)

def _handle_start_teardown_message(self, test, message):
"""Handle StartTeardown of a worker.

Expand Down
19 changes: 15 additions & 4 deletions src/rotest/core/runners/multiprocess/worker/result_handler.py
Expand Up @@ -9,7 +9,8 @@
from rotest.core.models.case_data import TestOutcome
from rotest.management.common.parsers import DEFAULT_PARSER
from rotest.core.result.handlers.abstract_handler import AbstractResultHandler
from rotest.management.common.messages import (StopTest,
from rotest.management.common.messages import (AddInfo,
StopTest,
AddResult,
StartTest,
ShouldSkip,
Expand Down Expand Up @@ -140,12 +141,22 @@ def stop_composite(self, test):
self.send_message(StopComposite(msg_id=self.worker_pid,
test_id=test.identifier))

def add_success(self, test, msg):
def add_success(self, test):
"""Notify the manager about a success via queue."""
self.send_message(AddResult(msg_id=self.worker_pid,
test_id=test.identifier,
code=TestOutcome.SUCCESS,
info=msg))
code=TestOutcome.SUCCESS))

def add_info(self, test, msg):
"""Called when a test registers a success message.

Args:
test (rotest.core.abstract_test.AbstractTest): test item instance.
msg (str): success message.
"""
self.send_message(AddInfo(msg_id=self.worker_pid,
test_id=test.identifier,
info=msg))

def add_error(self, test, exception_string):
"""Notify the manager about an error via queue.
Expand Down
10 changes: 10 additions & 0 deletions src/rotest/management/common/messages.py
Expand Up @@ -261,3 +261,13 @@ class AddResult(AbstractTestEventMessage):
info (str): additional data about the result (traceback, reason, etc.).
"""
pass


@slots_extender(('info',))
class AddInfo(AbstractTestEventMessage):
"""Register a success message.

Attributes:
info (str): success message.
"""
pass
2 changes: 1 addition & 1 deletion tests/core/handlers_tests/base_result_handler_test.py
Expand Up @@ -40,7 +40,7 @@ class BaseResultHandlerTest(with_metaclass(ABCMeta, TransactionTestCase)):

fixtures = ['resource_ut.json']

RESULT_MESSAGES = {TestOutcome.SUCCESS: ['Ok'],
RESULT_MESSAGES = {TestOutcome.SUCCESS: [],
TestOutcome.FAILED: ['Fail'],
TestOutcome.ERROR: ['Error'],
TestOutcome.SKIPPED: ['Skip'],
Expand Down
23 changes: 20 additions & 3 deletions tests/core/test_runner_results.py
Expand Up @@ -23,9 +23,10 @@
SetupTimeoutFlow, SetupCrashFlow)
from tests.core.utils import (FailureCase, SuccessCase, ErrorCase, SkipCase,
UnexpectedSuccessCase, ExpectedFailureCase,
MockSuite1, MockSuite2, MockTestSuite,
StoreMultipleFailuresCase, StoreFailureErrorCase,
TwoTestsCase, BasicRotestUnitTest)
SuccessMessageCase, MockSuite1, MockSuite2,
MockTestSuite, StoreMultipleFailuresCase,
StoreFailureErrorCase, TwoTestsCase,
BasicRotestUnitTest)

standard_library.install_aliases()

Expand Down Expand Up @@ -83,6 +84,22 @@ def test_success(self):
self.validate_all_finished(test)
self.validate_result(result, True, successes=3)

def test_info(self):
"""Validate behavior of success messages."""
MockTestSuite.components = (SuccessMessageCase,)

self.runner.run(MockTestSuite)
test = self.runner.test_item
result = self.runner.result

self.validate_all_finished(test)
self.validate_result(result, True, successes=1)
test_data = list(test)[0].data
self.assertEqual(test_data.traceback,
"SUCCESS: " + SuccessMessageCase.MESSAGE,
"Success message wasn't registered properly: %r" %
test_data.traceback)

def test_standalone_case(self):
"""Validate that a TestCase can run on its own."""
self.runner.run(TwoTestsCase)
Expand Down
11 changes: 11 additions & 0 deletions tests/core/utils.py
Expand Up @@ -394,6 +394,17 @@ def test_success(self):
pass


class SuccessMessageCase(MockCase):
"""Mock case, given the required resources always succeed."""
__test__ = False

MESSAGE = "It's all good"

def test_success(self):
"""Mock test function - always succeed."""
self.addSuccess(self.MESSAGE)


class DynamicResourceLockingCase(MockCase):
"""Mock case, requests a resource and validates the attributes."""
__test__ = False
Expand Down

0 comments on commit 7f76b6b

Please sign in to comment.