Skip to content

Commit

Permalink
Merge pull request #107 from gregoil/feature/python3-sanity-tests
Browse files Browse the repository at this point in the history
Feature/python3 sanity tests
  • Loading branch information
osherdp committed Oct 22, 2018
2 parents 39a42bb + e332790 commit 1d3614c
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 27 deletions.
7 changes: 0 additions & 7 deletions .editorconfig
Expand Up @@ -10,12 +10,5 @@ insert_final_newline = true
charset = utf-8
end_of_line = lf

[*.bat]
indent_style = tab
end_of_line = crlf

[LICENSE]
insert_final_newline = false

[Makefile]
indent_style = tab
4 changes: 2 additions & 2 deletions src/rotest/cli/client.py
Expand Up @@ -199,8 +199,8 @@ def main(*tests):
arguments = parser.parse_args()

config = AttrDict(chain(
list(parse_config_file(DEFAULT_CONFIG_PATH).items()),
list(parse_config_file(arguments.config_path).items()),
six.iteritems(parse_config_file(DEFAULT_CONFIG_PATH)),
six.iteritems(parse_config_file(arguments.config_path)),
filter_valid_values(vars(arguments)),
))

Expand Down
10 changes: 6 additions & 4 deletions src/rotest/common/config.py
Expand Up @@ -10,6 +10,8 @@
from future.utils import iteritems
from future.builtins import zip, object

import six


ROTEST_CONFIGURATION_FILES = ("rotest.yaml", "rotest.yml",
".rotest.yaml", ".rotest.yml")
Expand Down Expand Up @@ -68,7 +70,7 @@ def get_command_line_configuration(configuration_schema, command_line_options):
not command_line_option.startswith("-")):
pass

for target, option in list(configuration_schema.items()):
for target, option in six.iteritems(configuration_schema):
if command_line_option in option.command_line_options:
configuration[target] = value

Expand All @@ -89,7 +91,7 @@ def get_environment_variables_configuration(configuration_schema,
dict: a match between each target option to the given value.
"""
configuration = {}
for target, option in list(configuration_schema.items()):
for target, option in six.iteritems(configuration_schema):
for environment_variable in option.environment_variables:
if environment_variable in environment_variables:
configuration[target] = \
Expand Down Expand Up @@ -140,7 +142,7 @@ def get_file_configuration(configuration_schema, config_content):
yaml_configuration = yaml_configuration["rotest"]

configuration = {}
for target, option in list(configuration_schema.items()):
for target, option in six.iteritems(configuration_schema):
for config_file_option in option.config_file_options:
if config_file_option in yaml_configuration:
configuration[target] = yaml_configuration[config_file_option]
Expand Down Expand Up @@ -171,7 +173,7 @@ def get_configuration(configuration_schema,
"""
default_configuration = {
target: option.default_value
for target, option in list(configuration_schema.items())}
for target, option in six.iteritems(configuration_schema)}

if command_line_options is None:
cli_configuration = {}
Expand Down
2 changes: 1 addition & 1 deletion src/rotest/core/flow_component.py
Expand Up @@ -23,7 +23,7 @@
# CRITICAL: stop test on failure
# FINALLY: always run test, unskippable
# OPTIONAL: don't stop test on failure (but do so on error)
MODE_CRITICAL, MODE_FINALLY, MODE_OPTIONAL = list(range(1, 4))
MODE_CRITICAL, MODE_FINALLY, MODE_OPTIONAL = range(1, 4)


class PipeTo(object):
Expand Down
2 changes: 1 addition & 1 deletion src/rotest/core/models/case_data.py
Expand Up @@ -18,7 +18,7 @@ class TestOutcome(object):
save that outcome as the result of the test.
"""
(SUCCESS, ERROR, FAILED, SKIPPED,
EXPECTED_FAILURE, UNEXPECTED_SUCCESS) = list(range(6))
EXPECTED_FAILURE, UNEXPECTED_SUCCESS) = range(6)

RESULT_PRIORITY = {SUCCESS: 0,
SKIPPED: 1,
Expand Down
4 changes: 3 additions & 1 deletion src/rotest/core/result/handlers/excel_handler.py
Expand Up @@ -17,6 +17,8 @@
from rotest.core.result.handlers.remote_db_handler import RemoteDBHandler
from rotest.core.result.handlers.abstract_handler import AbstractResultHandler

import six


class ExcelHandler(AbstractResultHandler):
"""Excel result handler.
Expand Down Expand Up @@ -365,7 +367,7 @@ def _write_headers(self):

def _align_columns(self):
"""Align the columns width."""
for header, col_width in list(self.HEADER_TO_WIDTH.items()):
for header, col_width in six.iteritems(self.HEADER_TO_WIDTH):
self.sheet.col(self.HEADERS.index(header)).width = col_width

def _create_result_summary(self):
Expand Down
6 changes: 3 additions & 3 deletions src/rotest/core/runners/multiprocess/manager/runner.py
Expand Up @@ -6,9 +6,9 @@
import os
import time
import datetime
import platform
from multiprocessing import Queue

import six
from six.moves import queue
from future.builtins import range
from future.utils import itervalues
Expand Down Expand Up @@ -200,10 +200,10 @@ def restart_worker(self, worker, reason):

# Check if the worker was restarted before a test started
if worker.test is not None:
if platform.python_version().startswith("2"):
if six.PY2:
self.result.addError(worker.test, (RuntimeError, reason, None))

elif platform.python_version().startswith("3"):
elif six.PY3:
self.result.addError(worker.test, (RuntimeError,
RuntimeError(reason),
None))
Expand Down
3 changes: 3 additions & 0 deletions src/rotest/core/utils/pretty.py
Expand Up @@ -220,6 +220,9 @@ def __str__(self):
def __eq__(self, other):
return str(self) == other

def __hash__(self):
return hash(str(self))


class Pretty(object):
"""Title with decoration.
Expand Down
2 changes: 1 addition & 1 deletion src/rotest/management/models/ut_models.py
Expand Up @@ -30,7 +30,7 @@ class DemoResourceData(ResourceData):
fails_on_finalize (bool): the resource should fail on finalization.
fails_on_initialize (bool): the resource should fail on initialization.
"""
BOOT_MODE, PROD_MODE = list(range(2))
BOOT_MODE, PROD_MODE = range(2)

MODE_CHOICE = ((BOOT_MODE, 'Boot'),
(PROD_MODE, 'Production'))
Expand Down
3 changes: 2 additions & 1 deletion src/rotest/management/utils/resources_discoverer.py
Expand Up @@ -4,6 +4,7 @@
from fnmatch import fnmatch

import py
import six
import django
from rotest.common.config import DISCOVERER_BLACKLIST
from rotest.management.base_resource import BaseResource
Expand Down Expand Up @@ -39,7 +40,7 @@ def _import_resources_from_module(module_path):

module = py.path.local(module_path).pyimport()

return {item.__name__: item for item in list(module.__dict__.values())
return {item.__name__: item for item in six.itervalues(module.__dict__)
if _is_resource_class(item)}


Expand Down
4 changes: 2 additions & 2 deletions tests/core/handlers_tests/test_excel_handler.py
Expand Up @@ -227,8 +227,8 @@ def validate_stop_test_run(self):
self.assertEqual(actual_sheet.nrows, expected_sheet.nrows)
self.assertEqual(actual_sheet.ncols, expected_sheet.ncols)

for row, col in itertools.product(list(range(actual_sheet.nrows,
actual_sheet.ncols))):
for row, col in itertools.product(range(actual_sheet.nrows,
actual_sheet.ncols)):
actual_cell = actual_sheet.cell(row, col)
expected_cell = expected_sheet.cell(row, col)
self.assertEqual(actual_cell, expected_cell)
4 changes: 1 addition & 3 deletions tests/core/handlers_tests/test_monitor.py
@@ -1,6 +1,4 @@
"""Test Rotest's Monitor class behavior."""
from __future__ import print_function

import time
import threading

Expand Down Expand Up @@ -204,7 +202,7 @@ def test_method(self):
'Case failed when it should have succeeded')

fail_nums = len(self.result.failures)
print(self.result.failures)

self.assertEqual(fail_nums, 1,
"Unexpected number of failures, expected %d got %d" %
(1, fail_nums))
Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_case.py
Expand Up @@ -5,6 +5,7 @@

import os
import re
import six

from future.builtins import next
from future.utils import iteritems
Expand Down Expand Up @@ -221,7 +222,7 @@ def test_complex_resource_request(self):

test_resources = case.all_resources
locked_names = []
for resource in list(test_resources.values()):
for resource in six.itervalues(test_resources):
self.assertTrue(isinstance(resource, DemoResource),
"Got wrong resource %r for the request" % resource)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/__init__.py
@@ -0,0 +1 @@
"""Integration tests validate that a rotest project is usable."""
33 changes: 33 additions & 0 deletions tests/integration/playground.py
@@ -0,0 +1,33 @@
from __future__ import absolute_import, print_function

from rotest import main
from rotest.core import TestBlock, TestFlow


class ExampleBlock1(TestBlock):
__test__ = False

# pylint: disable=no-self-use
def test_method(self):
print("ExampleBlock1 ran")


class ExampleBlock2(TestBlock):
__test__ = False

# pylint: disable=no-self-use
def test_method(self):
print("ExampleBlock2 ran")


class ExampleFlow(TestFlow):
__test__ = False

blocks = [
ExampleBlock1,
ExampleBlock2
]


if __name__ == "__main__":
main(ExampleFlow)
29 changes: 29 additions & 0 deletions tests/integration/test_integration_sanity.py
@@ -0,0 +1,29 @@
import os
import sys

import subprocess

THIS_FILE = os.path.abspath(__file__)
THIS_DIRECTORY = os.path.dirname(THIS_FILE)
ROTEST_WORK_DIR = os.path.join(os.path.expanduser("~"), ".rotest")


def test_sanity():
python = sys.executable
playground = os.path.join(THIS_DIRECTORY, "playground.py")
environment_variables = dict(
os.environ,
DJANGO_SETTINGS_MODULE="rotest.common.django_utils.settings",
ROTEST_WORK_DIR=ROTEST_WORK_DIR
)

p = subprocess.Popen([python, playground], env=environment_variables,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

return_code = p.wait()
stderr = p.stderr.read()
stdout = p.stdout.read()
assert b"Test run has started" in stderr
assert b'ExampleBlock1 ran' in stdout
assert b'ExampleBlock2 ran' in stdout
assert return_code == 0

0 comments on commit 1d3614c

Please sign in to comment.