Skip to content

Commit

Permalink
Merge pull request #74 from rinslow/master
Browse files Browse the repository at this point in the history
Filtered tests are discarded and not skipped
  • Loading branch information
osherdp committed Jul 20, 2018
2 parents 5065dee + 70565eb commit 4b64ff7
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 374 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
"xml = rotest.core.result.handlers.xml_handler:XMLHandler",
"tags = rotest.core.result.handlers.tags_handler:TagsHandler",
"excel = rotest.core.result.handlers.excel_handler:ExcelHandler",
"dots = rotest.core.result.handlers.stream.dots_handler:DotsHandler",
"tree = rotest.core.result.handlers.stream.tree_handler:TreeHandler",
Expand Down
19 changes: 11 additions & 8 deletions src/rotest/cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
from attrdict import AttrDict

from rotest.core import TestSuite
from rotest.core.filter import match_tags
from rotest.core.utils.common import print_test_hierarchy
from rotest.core.result.result import get_result_handlers
from rotest.cli.discover import discover_tests_under_paths
from rotest.core.result.handlers.tags_handler import TagsHandler
from rotest.core.result.result import get_result_handler_options
from rotest.core.runner import (DEFAULT_CONFIG_PATH, parse_config_file,
update_resource_requests, run as rotest_runner,
parse_resource_identifiers)
Expand All @@ -72,7 +72,7 @@ def parse_outputs_option(outputs):

requested_handlers = set(outputs.split(","))

available_handlers = set(get_result_handler_options())
available_handlers = set(get_result_handlers())

non_existing_handlers = requested_handlers - available_handlers

Expand All @@ -85,6 +85,10 @@ def parse_outputs_option(outputs):
return requested_handlers


def get_tags_by_class(test_class):
return test_class.TAGS + [test_class.__name__]


def run_tests(test, save_state, delta_iterations, processes, outputs, filter,
run_name, list, fail_fast, debug, skip_init, config_path,
resources):
Expand All @@ -95,11 +99,6 @@ def run_tests(test, save_state, delta_iterations, processes, outputs, filter,
resource_identifiers = parse_resource_identifiers(resources)
update_resource_requests(test, resource_identifiers)

if filter:
# Add a tags filtering handler.
TagsHandler.TAGS_PATTERN = filter
outputs.add('tags')

runs_data = rotest_runner(config=config_path,
test_class=test,
outputs=outputs,
Expand Down Expand Up @@ -178,6 +177,10 @@ def main(*tests):
if len(tests) == 0:
tests = discover_tests_under_paths(options.paths)

if options.filter is not None:
tests = [test for test in tests
if match_tags(get_tags_by_class(test), options.filter)]

if len(tests) == 0:
print("No test was found at given paths: {}".format(
", ".join(options.paths)))
Expand Down
1 change: 0 additions & 1 deletion src/rotest/core/abstract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def __init__(self, indexer=count(), methodName='runTest', save_state=True,

super(AbstractTest, self).__init__(methodName)

self._tags = None
self.result = None
self.config = config
self.parent = parent
Expand Down
27 changes: 0 additions & 27 deletions src/rotest/core/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# pylint: disable=protected-access,eval-used
from fnmatch import fnmatch

from rotest.core.case import TestCase


VALID_LITERALS = ["and", "or", "not", "(", ")", "True", "False"]

Expand All @@ -25,31 +23,6 @@ def validate_boolean_expression(expression):
raise ValueError("Illegal boolean expression %r" % expression)


def get_tags(test):
"""Return the tags of a test item.
Args:
test (TestSuite / TestCase): test item instance.
Returns:
list. tags of the test item.
"""
if test._tags is not None:
return test._tags

tags = test.TAGS[:]
tags.append(test.__class__.__name__)

if isinstance(test, TestCase):
tags.append(test._testMethodName)

if test.parent is not None:
tags.extend(get_tags(test.parent))

test._tags = tags
return tags


def match_tags(tags_list, tags_filter):
"""Check whether a tags list answers a condition expressed in tags_filter.
Expand Down
31 changes: 0 additions & 31 deletions src/rotest/core/result/handlers/excel_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from rotest.core.flow_component import AbstractFlowComponent
from rotest.core.result.handlers.db_handler import DBHandler
from rotest.core.models.case_data import CaseData, TestOutcome
from rotest.core.result.handlers.tags_handler import TagsHandler
from rotest.core.result.handlers.remote_db_handler import RemoteDBHandler
from rotest.core.result.handlers.abstract_handler import AbstractResultHandler

Expand Down Expand Up @@ -112,7 +111,6 @@ class ExcelHandler(AbstractResultHandler):
(UNEXPECTED_SUCCESS, easyxf(CELL_STYLE % (UNEXPECTED_SUCCESS_COLOR,
BLACK_COLOR)))])

TAGS_SKIP_MESSAGE = TagsHandler.SKIP_MESSAGE
LOCAL_DB_SKIP_MESSAGE = DBHandler.SKIP_DELTA_MESSAGE
REMOTE_DB_SKIP_MESSAGE = RemoteDBHandler.SKIP_DELTA_MESSAGE
PASSED_MESSAGES = (LOCAL_DB_SKIP_MESSAGE, REMOTE_DB_SKIP_MESSAGE)
Expand Down Expand Up @@ -366,32 +364,6 @@ def _align_columns(self):
for header, col_width in self.HEADER_TO_WIDTH.items():
self.sheet.col(self.HEADERS.index(header)).width = col_width

def _create_skipped_reason_summary(self):
"""Create Skipped tests summary.
Describe amount of tests skipped since they were filtered by tags,
or noted as 'Already Passed' in the DB.
"""
for skip_reason in (self.TAGS_SKIP_MESSAGE,):

self._write_to_cell(self.row_number,
self.SUMMARY_RESULT_TYPE_COLUMN,
self.DEFAULT_CELL_STYLE,
self.SKIPPED_SUMMARY_PATTERN % skip_reason)

skip_count_formula = xlwt.Formula(self.FORMULA_PATTERN %
(self.TRACEBACK_COLUMN,
self.TRACEBACK_COLUMN,
self.row_number,
skip_reason))

self._write_to_cell(self.row_number,
self.SUMMARY_RESULT_COUNTER_COLUMN,
self.DEFAULT_CELL_STYLE,
skip_count_formula)

self.row_number += 1

def _create_result_summary(self):
"""Create result summary at the end of the Excel report."""
self.row_number += self.ROWS_TO_SKIP
Expand All @@ -413,6 +385,3 @@ def _create_result_summary(self):
result_type_count)

self.row_number += 1

if result_type == self.SKIPPED:
self._create_skipped_reason_summary()
37 changes: 0 additions & 37 deletions src/rotest/core/result/handlers/tags_handler.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/rotest/core/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ def get_result_handlers():
pkg_resources.iter_entry_points("rotest.result_handlers")}


def get_result_handler_options():
return [handler_name
for handler_name in get_result_handlers()
if handler_name != "tags"]


class Result(TestResult):
"""Manager class for handling tests' run information.
Expand Down
1 change: 0 additions & 1 deletion src/rotest/core/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def __init__(self, base_work_dir=ROTEST_WORK_DIR, save_state=True,
"""
super(TestSuite, self).__init__()

self._tags = None
self.parent = parent
name = self.get_name()
self.identifier = indexer.next()
Expand Down
18 changes: 6 additions & 12 deletions src/rotest/core/utils/common.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Common result utils."""
# pylint: disable=dangerous-default-value
from termcolor import colored
from __future__ import print_function

from rotest.core.case import TestCase
from rotest.core.flow import TestFlow
from rotest.core.block import TestBlock
from rotest.core.suite import TestSuite
from rotest.core.filter import match_tags
from rotest.common.constants import MAGENTA


PASS_ALL_FILTER = "*"
Expand All @@ -30,20 +29,16 @@ def print_test_instance(test_name, depth, tag_filter, test_tags, all_tags):
"""
test_format = " ".join([HIERARCHY_SEPARATOR * depth,
test_name, str(test_tags)])
print(test_format)

if tag_filter is not None and match_tags(all_tags, tag_filter):
print colored(test_format, MAGENTA)
return True

print test_format
return False
return tag_filter is not None and match_tags(all_tags, tag_filter)


def print_test_hierarchy(test, tag_filter, tags=[], depth=0):
"""Recursively print the test's hierarchy tree and tags.
Args:
test (object): test to print.
test (rotest.core.AbstractTest): test to print.
tag_filter (str): boolean expression composed of tags and boolean
operators, e.g. "Tag1 and (Tag2 or Tag3 or Tag3)".
tags (list): tags list to be verified against the tag_filter,
Expand All @@ -62,14 +57,13 @@ def print_test_hierarchy(test, tag_filter, tags=[], depth=0):
test.TAGS, method_tags)

elif issubclass(actual_test, TestBlock):
print_test_instance(test.get_name(), depth, tag_filter,
[], tags)
print_test_instance(test.get_name(), depth, tag_filter, [], tags)

elif issubclass(actual_test, TestSuite):
tags.extend(actual_test.TAGS)
tags.append(actual_test.__name__)
sub_tests = test.components
print HIERARCHY_SEPARATOR * depth, test.get_name(), test.TAGS
print(HIERARCHY_SEPARATOR * depth, test.get_name(), test.TAGS)
for sub_test in sub_tests:
print_test_hierarchy(sub_test, tag_filter, tags, depth + 1)

Expand Down

0 comments on commit 4b64ff7

Please sign in to comment.