From 60b06eea87db971f3869d9e15f12af3e8ed34896 Mon Sep 17 00:00:00 2001 From: Ioannis Tziakos Date: Sun, 22 Sep 2024 13:55:24 +0100 Subject: [PATCH 1/5] remove unittest compatibility code --- haas/testing.py | 17 ----------------- haas/tests/compat.py | 4 ---- 2 files changed, 21 deletions(-) delete mode 100644 haas/testing.py delete mode 100644 haas/tests/compat.py diff --git a/haas/testing.py b/haas/testing.py deleted file mode 100644 index 616133fb..00000000 --- a/haas/testing.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2013-2014 Simon Jagoe -# All rights reserved. -# -# This software may be modified and distributed under the terms -# of the 3-clause BSD license. See the LICENSE.txt file for details. -__all__ = [ - 'unittest', -] - -import sys - - -if sys.version_info[:2] == (2, 6): # pragma: no cover - import unittest2 as unittest -else: - import unittest diff --git a/haas/tests/compat.py b/haas/tests/compat.py deleted file mode 100644 index 0e64d805..00000000 --- a/haas/tests/compat.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - from unittest import mock # noqa -except ImportError: - import mock # noqa From ab1429d9e6bda8daf1dd4c2a9a81beebbd385296 Mon Sep 17 00:00:00 2001 From: Ioannis Tziakos Date: Sun, 22 Sep 2024 13:56:23 +0100 Subject: [PATCH 2/5] Modenrize tests - Update imports - Do not use "object" in class definitions --- haas/plugins/tests/__init__.py | 1 - haas/plugins/tests/test_coverage.py | 7 ++--- haas/plugins/tests/test_discoverer.py | 34 ++++++++++------------ haas/plugins/tests/test_result_handlers.py | 7 ++--- haas/tests/__init__.py | 1 - haas/tests/_test_case_data.py | 5 ++-- haas/tests/_test_cases.py | 10 ++----- haas/tests/builder.py | 7 ++--- haas/tests/fixtures.py | 4 +-- haas/tests/test_buffering.py | 6 ++-- haas/tests/test_builder.py | 4 +-- haas/tests/test_deprecations.py | 3 +- haas/tests/test_error_holder.py | 4 +-- haas/tests/test_fail_test.py | 4 +-- haas/tests/test_haas_application.py | 8 ++--- haas/tests/test_loader.py | 15 ++++------ haas/tests/test_parallel_runner.py | 9 +++--- haas/tests/test_plugin_context.py | 6 ++-- haas/tests/test_plugin_manager.py | 6 ++-- haas/tests/test_quiet_result_handler.py | 7 ++--- haas/tests/test_runner.py | 4 +-- haas/tests/test_standard_result_handler.py | 7 ++--- haas/tests/test_suite.py | 10 +++---- haas/tests/test_test_duration_ordering.py | 7 +---- haas/tests/test_text_test_result.py | 6 ++-- haas/tests/test_utils.py | 6 ++-- haas/tests/test_verbose_result_handler.py | 7 ++--- 27 files changed, 69 insertions(+), 126 deletions(-) diff --git a/haas/plugins/tests/__init__.py b/haas/plugins/tests/__init__.py index c7ed91e5..e95bbccb 100644 --- a/haas/plugins/tests/__init__.py +++ b/haas/plugins/tests/__init__.py @@ -4,4 +4,3 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals diff --git a/haas/plugins/tests/test_coverage.py b/haas/plugins/tests/test_coverage.py index 5a4938ff..28d8c31f 100644 --- a/haas/plugins/tests/test_coverage.py +++ b/haas/plugins/tests/test_coverage.py @@ -4,7 +4,8 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals +from unittest import mock +import unittest try: import coverage @@ -14,10 +15,6 @@ Coverage = None -from haas.testing import unittest -from haas.tests.compat import mock - - @unittest.skipIf(coverage is None, 'Coverage is not installed') class TestCoverage(unittest.TestCase): diff --git a/haas/plugins/tests/test_discoverer.py b/haas/plugins/tests/test_discoverer.py index 929ed5d1..2db52539 100644 --- a/haas/plugins/tests/test_discoverer.py +++ b/haas/plugins/tests/test_discoverer.py @@ -4,18 +4,14 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - +from unittest import mock import os import shutil import sys import tempfile -import unittest as python_unittest - -from haas.testing import unittest +import unittest from haas.tests import _test_cases, builder -from haas.tests.compat import mock from haas.loader import Loader from haas.module_import_error import ModuleImportError from haas.suite import find_test_cases, TestSuite @@ -35,7 +31,7 @@ class FilterTestCase(_test_cases.TestCase): pass -class TestDiscoveryMixin(object): +class TestDiscoveryMixin: def setUp(self): self.tmpdir = os.path.abspath(tempfile.mkdtemp()) @@ -261,7 +257,7 @@ def assertSuite(self, suite): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 2) for test in tests: - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_from_top_level_directory(self): @@ -346,7 +342,7 @@ def test_discover_package(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 2) for test in tests: - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_package_no_top_level(self): @@ -361,7 +357,7 @@ def test_discover_module(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 2) for test in tests: - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_case(self): @@ -371,7 +367,7 @@ def test_discover_case(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_missing_case(self): @@ -396,7 +392,7 @@ def test_discover_method(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_too_many_components(self): @@ -424,7 +420,7 @@ def test_discover_subpackage(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 2) for test in tests: - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_test_method(self): @@ -435,7 +431,7 @@ def test_discover_test_method(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 2) for test in tests: - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_class(self): @@ -446,7 +442,7 @@ def test_discover_class(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_no_top_level(self): @@ -460,7 +456,7 @@ def test_discover_no_top_level(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_class_and_method(self): @@ -471,7 +467,7 @@ def test_discover_class_and_method(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_module_and_class_and_method(self): @@ -482,7 +478,7 @@ def test_discover_module_and_class_and_method(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') def test_discover_module_and_class(self): @@ -493,7 +489,7 @@ def test_discover_module_and_class(self): tests = list(self.get_test_cases(suite)) self.assertEqual(len(tests), 1) test, = tests - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertEqual(test._testMethodName, 'test_method') diff --git a/haas/plugins/tests/test_result_handlers.py b/haas/plugins/tests/test_result_handlers.py index ff2aeb1b..b0bbce8b 100644 --- a/haas/plugins/tests/test_result_handlers.py +++ b/haas/plugins/tests/test_result_handlers.py @@ -1,12 +1,11 @@ from datetime import datetime, timedelta -import statistics - from io import StringIO +from unittest import mock +import statistics +import unittest from haas.result import TestResult, TestCompletionStatus, TestDuration -from haas.testing import unittest from haas.tests import _test_cases -from haas.tests.compat import mock from haas.tests.fixtures import ExcInfoFixture from ..result_handler import ( QuietTestResultHandler, diff --git a/haas/tests/__init__.py b/haas/tests/__init__.py index c7ed91e5..e95bbccb 100644 --- a/haas/tests/__init__.py +++ b/haas/tests/__init__.py @@ -4,4 +4,3 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals diff --git a/haas/tests/_test_case_data.py b/haas/tests/_test_case_data.py index c54a34ec..fbc50541 100644 --- a/haas/tests/_test_case_data.py +++ b/haas/tests/_test_case_data.py @@ -1,4 +1,5 @@ -from haas.testing import unittest +import unittest + from ..suite import TestSuite @@ -22,7 +23,7 @@ def test_method(self): pass -class TestSuiteNotSubclass(object): +class TestSuiteNotSubclass: def __init__(self, tests=()): self.tests = tests diff --git a/haas/tests/_test_cases.py b/haas/tests/_test_cases.py index 1586315c..794df8de 100644 --- a/haas/tests/_test_cases.py +++ b/haas/tests/_test_cases.py @@ -4,14 +4,10 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals +import unittest -import unittest as python_unittest -from haas.testing import unittest - - -class NotTestCase(object): +class NotTestCase: def test_method(self): pass @@ -28,7 +24,7 @@ class TestCase(NotTestCase, unittest.TestCase): pass -class PythonTestCase(NotTestCase, python_unittest.TestCase): +class AnotherTestCase(NotTestCase, unittest.TestCase): pass diff --git a/haas/tests/builder.py b/haas/tests/builder.py index cd44b784..b2723102 100644 --- a/haas/tests/builder.py +++ b/haas/tests/builder.py @@ -4,16 +4,13 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import abc import os import textwrap - -from ..testing import unittest +import unittest -class Importable(object, metaclass=abc.ABCMeta): +class Importable(abc.ABC): def __init__(self, name, contents=()): self.name = name diff --git a/haas/tests/fixtures.py b/haas/tests/fixtures.py index ce174ace..0ff52a3d 100644 --- a/haas/tests/fixtures.py +++ b/haas/tests/fixtures.py @@ -2,7 +2,7 @@ import sys -class ExcInfoFixture(object): +class ExcInfoFixture: @contextmanager def failure_exc_info(self, msg=None): @@ -19,7 +19,7 @@ def exc_info(self, cls): yield sys.exc_info() -class MockDateTime(object): +class MockDateTime: def __init__(self, ret): try: self.ret = iter(ret) diff --git a/haas/tests/test_buffering.py b/haas/tests/test_buffering.py index 79f4edde..84eaf4f6 100644 --- a/haas/tests/test_buffering.py +++ b/haas/tests/test_buffering.py @@ -4,19 +4,17 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from datetime import datetime, timedelta +from unittest import mock import sys +import unittest from io import StringIO -from haas.tests.compat import mock from ..plugins.i_result_handler_plugin import IResultHandlerPlugin from ..result import ( ResultCollector, TestResult, TestCompletionStatus, TestDuration ) -from ..testing import unittest from . import _test_cases from .fixtures import ExcInfoFixture, MockDateTime diff --git a/haas/tests/test_builder.py b/haas/tests/test_builder.py index bef98369..c978bcdf 100644 --- a/haas/tests/test_builder.py +++ b/haas/tests/test_builder.py @@ -4,14 +4,12 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import os import shutil import tempfile import textwrap +import unittest -from ..testing import unittest from . import builder diff --git a/haas/tests/test_deprecations.py b/haas/tests/test_deprecations.py index fb0eaab7..c165cc58 100644 --- a/haas/tests/test_deprecations.py +++ b/haas/tests/test_deprecations.py @@ -4,12 +4,11 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals +import unittest from testfixtures import ShouldWarn from ..result import ResultCollecter -from ..testing import unittest class TestResultCollecterDepricated(unittest.TestCase): diff --git a/haas/tests/test_error_holder.py b/haas/tests/test_error_holder.py index bafe79bb..1e5284fd 100644 --- a/haas/tests/test_error_holder.py +++ b/haas/tests/test_error_holder.py @@ -4,9 +4,7 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - -from haas.testing import unittest +import unittest from ..error_holder import ErrorHolder diff --git a/haas/tests/test_fail_test.py b/haas/tests/test_fail_test.py index 128e1ed0..ea206193 100644 --- a/haas/tests/test_fail_test.py +++ b/haas/tests/test_fail_test.py @@ -4,11 +4,9 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - +import unittest from ..result import ResultCollector -from ..testing import unittest from . import _test_cases from .fixtures import ExcInfoFixture diff --git a/haas/tests/test_haas_application.py b/haas/tests/test_haas_application.py index 036d9875..b2610ed3 100644 --- a/haas/tests/test_haas_application.py +++ b/haas/tests/test_haas_application.py @@ -4,16 +4,16 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from argparse import Namespace from contextlib import contextmanager from functools import wraps +from unittest import mock import logging import os import shutil import tempfile import types +import unittest from testfixtures import LogCapture from stevedore.extension import ExtensionManager, Extension @@ -24,13 +24,11 @@ from ..plugin_manager import PluginManager from ..plugins.discoverer import Discoverer from ..suite import TestSuite -from ..testing import unittest from ..utils import cd -from .compat import mock from . import builder -class MockLambda(object): +class MockLambda: def __eq__(self, other): if isinstance(other, types.FunctionType): diff --git a/haas/tests/test_loader.py b/haas/tests/test_loader.py index a64fbba4..2dbe173b 100644 --- a/haas/tests/test_loader.py +++ b/haas/tests/test_loader.py @@ -4,11 +4,7 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - -import unittest as python_unittest - -from haas.testing import unittest +import unittest from . import _test_cases from . import _test_case_data @@ -16,7 +12,7 @@ from ..suite import TestSuite -class LoaderTestMixin(object): +class LoaderTestMixin: def setUp(self): self.loader = Loader() @@ -29,7 +25,7 @@ class TestLoadTest(LoaderTestMixin, unittest.TestCase): def test_creates_instance_for_valid_test(self): test = self.loader.load_test(_test_cases.TestCase, 'test_method') - self.assertIsInstance(test, python_unittest.TestCase) + self.assertIsInstance(test, unittest.TestCase) self.assertIsInstance(test, _test_cases.TestCase) def test_raises_for_invalid_test(self): @@ -54,7 +50,6 @@ def test_create_custom_class_raises(self): def test_load_test_overridden_init(self): test = self.loader.load_test( _test_case_data.BadlySubclassedTestCase, 'test_method') - self.assertIsInstance(test, python_unittest.TestCase) self.assertIsInstance(test, unittest.TestCase) @@ -110,7 +105,7 @@ def assertSuiteClasses(self, suite, klass): def test_find_all_cases_in_module(self): cases = self.loader.get_test_cases_from_module(_test_cases) self.assertCountEqual( - cases, [_test_cases.TestCase, _test_cases.PythonTestCase]) + cases, [_test_cases.TestCase, _test_cases.AnotherTestCase]) def test_load_all_cases_in_module(self): suite = self.loader.load_module(_test_cases) @@ -121,7 +116,7 @@ def test_load_all_cases_in_module(self): for sub_suite in sub_suites: self.assertEqual(len(list(sub_suite)), 1) for case in sub_suite: - self.assertIsInstance(case, python_unittest.TestCase) + self.assertIsInstance(case, unittest.TestCase) cases.append(case) self.assertEqual(len(cases), 2) diff --git a/haas/tests/test_parallel_runner.py b/haas/tests/test_parallel_runner.py index d190b6ca..8ef97566 100644 --- a/haas/tests/test_parallel_runner.py +++ b/haas/tests/test_parallel_runner.py @@ -1,21 +1,20 @@ from argparse import ArgumentParser from datetime import datetime, timedelta -import time - from io import StringIO +from unittest import mock +import unittest +import time from ..plugins.discoverer import _create_import_error_test from ..plugins.parallel_runner import ChildResultHandler, ParallelTestRunner from ..result import ( ResultCollector, TestCompletionStatus, TestResult, TestDuration) from ..suite import TestSuite -from ..testing import unittest from . import _test_cases from .fixtures import MockDateTime -from .compat import mock -class AsyncResult(object): +class AsyncResult: def ready(self): return True diff --git a/haas/tests/test_plugin_context.py b/haas/tests/test_plugin_context.py index 2083d3b5..134d7921 100644 --- a/haas/tests/test_plugin_context.py +++ b/haas/tests/test_plugin_context.py @@ -4,12 +4,10 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - +from unittest import mock +import unittest from ..plugin_context import PluginContext -from ..testing import unittest -from .compat import mock class TestPluginContext(unittest.TestCase): diff --git a/haas/tests/test_plugin_manager.py b/haas/tests/test_plugin_manager.py index cb25f861..b0ad1ca2 100644 --- a/haas/tests/test_plugin_manager.py +++ b/haas/tests/test_plugin_manager.py @@ -4,9 +4,8 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from argparse import ArgumentParser +import unittest from stevedore.extension import ExtensionManager, Extension @@ -14,10 +13,9 @@ from haas.plugins.runner import BaseTestRunner from ..haas_application import create_argument_parser from ..plugin_manager import PluginManager -from ..testing import unittest -class InvalidPlugin(object): +class InvalidPlugin: pass diff --git a/haas/tests/test_quiet_result_handler.py b/haas/tests/test_quiet_result_handler.py index 3bd4f103..7afa1e98 100644 --- a/haas/tests/test_quiet_result_handler.py +++ b/haas/tests/test_quiet_result_handler.py @@ -4,19 +4,16 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from datetime import datetime, timedelta - from io import StringIO +from unittest import mock +import unittest from ..plugins.result_handler import QuietTestResultHandler from ..result import ( TestResult, TestCompletionStatus, TestDuration) -from ..testing import unittest from . import _test_cases from .fixtures import ExcInfoFixture -from .compat import mock class TestQuietResultHandler(ExcInfoFixture, unittest.TestCase): diff --git a/haas/tests/test_runner.py b/haas/tests/test_runner.py index df9a1121..2e7678af 100644 --- a/haas/tests/test_runner.py +++ b/haas/tests/test_runner.py @@ -1,8 +1,8 @@ from argparse import ArgumentParser +from unittest import mock +import unittest from ..plugins.runner import BaseTestRunner -from ..testing import unittest -from .compat import mock class TestBaseTestRunner(unittest.TestCase): diff --git a/haas/tests/test_standard_result_handler.py b/haas/tests/test_standard_result_handler.py index 69f6a255..c420a003 100644 --- a/haas/tests/test_standard_result_handler.py +++ b/haas/tests/test_standard_result_handler.py @@ -4,19 +4,16 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from datetime import datetime, timedelta - from io import StringIO +from unittest import mock +import unittest from ..plugins.result_handler import StandardTestResultHandler from ..result import ( TestResult, TestCompletionStatus, TestDuration) -from ..testing import unittest from . import _test_cases from .fixtures import ExcInfoFixture -from .compat import mock class TestStandardResultHandler(ExcInfoFixture, unittest.TestCase): diff --git a/haas/tests/test_suite.py b/haas/tests/test_suite.py index 6a212640..68c1d7e6 100644 --- a/haas/tests/test_suite.py +++ b/haas/tests/test_suite.py @@ -4,19 +4,17 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from contextlib import contextmanager from itertools import count import sys +import unittest from ._test_cases import TestCase from ..result import ResultCollector from ..suite import TestSuite, _TestSuiteState -from ..testing import unittest -class MockModule(object): +class MockModule: def __init__(self, setup_raise=False, teardown_raise=False): self.setup = False @@ -45,7 +43,7 @@ class MockModuleSetupTeardown(MockModuleSetup, MockModuleTeardown): pass -class MockTestCase(object): +class MockTestCase: setup = False teardown = False @@ -100,7 +98,7 @@ class MockTestCaseSetupTeardown(MockTestCaseSetup, MockTestCaseTeardown): pass -class ResetClassStateMixin(object): +class ResetClassStateMixin: def setUp(self): for klass in (MockTestCase, MockTestCaseSetup, diff --git a/haas/tests/test_test_duration_ordering.py b/haas/tests/test_test_duration_ordering.py index 83a97698..a6c5984b 100644 --- a/haas/tests/test_test_duration_ordering.py +++ b/haas/tests/test_test_duration_ordering.py @@ -4,19 +4,14 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - +import unittest from datetime import datetime, timedelta -import sys from ..result import TestDuration -from ..testing import unittest class TestTestDurationOrdering(unittest.TestCase): - @unittest.skipIf(sys.version_info < (3,), - 'Python 2 does not raise on unorderable types') def test_unorderable_types(self): start_time = datetime(2015, 12, 23, 8, 14, 12) duration = timedelta(seconds=10) diff --git a/haas/tests/test_text_test_result.py b/haas/tests/test_text_test_result.py index fefddd99..82471aee 100644 --- a/haas/tests/test_text_test_result.py +++ b/haas/tests/test_text_test_result.py @@ -4,18 +4,16 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from datetime import datetime, timedelta +from unittest import mock +import unittest from ..plugins.i_result_handler_plugin import IResultHandlerPlugin from ..result import ( ResultCollector, TestResult, TestCompletionStatus, TestDuration ) -from ..testing import unittest from . import _test_cases, _test_case_data from .fixtures import ExcInfoFixture, MockDateTime -from .compat import mock class TestTextTestResult(ExcInfoFixture, unittest.TestCase): diff --git a/haas/tests/test_utils.py b/haas/tests/test_utils.py index 34dae3b6..c978c9cb 100644 --- a/haas/tests/test_utils.py +++ b/haas/tests/test_utils.py @@ -4,13 +4,11 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - +import unittest +from unittest import mock import haas -from ..testing import unittest from ..utils import configure_logging -from .compat import mock class TestConfigureLogging(unittest.TestCase): diff --git a/haas/tests/test_verbose_result_handler.py b/haas/tests/test_verbose_result_handler.py index a10b3491..ffdac465 100644 --- a/haas/tests/test_verbose_result_handler.py +++ b/haas/tests/test_verbose_result_handler.py @@ -4,20 +4,17 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from datetime import datetime, timedelta from time import ctime - from io import StringIO +from unittest import mock +import unittest from ..plugins.result_handler import VerboseTestResultHandler from ..result import ( TestResult, TestCompletionStatus, TestDuration) -from ..testing import unittest from . import _test_cases from .fixtures import ExcInfoFixture -from .compat import mock class TestVerboseResultHandler(ExcInfoFixture, unittest.TestCase): From c887c0cf7dfacff3d7d73f0cdbcf38c040ac1c97 Mon Sep 17 00:00:00 2001 From: Ioannis Tziakos Date: Sun, 22 Sep 2024 13:57:33 +0100 Subject: [PATCH 3/5] Modenrize tests - Update imports - Do not use "object" in class definitions - remove future imports --- haas/__init__.py | 2 -- haas/error_holder.py | 12 +++++----- haas/exceptions.py | 1 - haas/haas_application.py | 4 +--- haas/loader.py | 4 +--- haas/main.py | 2 -- haas/module_import_error.py | 3 +-- haas/plugin_context.py | 3 +-- haas/plugin_manager.py | 11 ++-------- haas/plugins/__init__.py | 1 - haas/plugins/base_hook_plugin.py | 2 -- haas/plugins/coverage.py | 2 -- haas/plugins/discoverer.py | 4 +--- haas/plugins/i_discoverer_plugin.py | 8 ++----- haas/plugins/i_hook_plugin.py | 10 +++------ haas/plugins/i_result_handler_plugin.py | 8 ++----- haas/plugins/i_runner_plugin.py | 8 ++----- haas/plugins/parallel_runner.py | 6 +++++ haas/plugins/result_handler.py | 4 +--- haas/plugins/runner.py | 2 -- haas/result.py | 8 +++---- haas/suite.py | 6 ++--- haas/utils.py | 29 +------------------------ 23 files changed, 35 insertions(+), 105 deletions(-) diff --git a/haas/__init__.py b/haas/__init__.py index ef68ddea..579f62d1 100644 --- a/haas/__init__.py +++ b/haas/__init__.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import logging __version__ = '0.10.0.dev1' diff --git a/haas/error_holder.py b/haas/error_holder.py index 8850a970..86bd2090 100644 --- a/haas/error_holder.py +++ b/haas/error_holder.py @@ -3,7 +3,7 @@ # Copyright the CPython developers and contributors. -class ErrorHolder(object): +class ErrorHolder: """ Placeholder for a TestCase inside a result. As far as a TestResult is concerned, this looks exactly like a unit test. Used to insert @@ -21,15 +21,11 @@ def __init__(self, description): def id(self): return self.description - @property - def _testMethodName(self): - return self.description - def shortDescription(self): return None def __repr__(self): - return "" % (self.description,) + return f"" def __str__(self): return self.id() @@ -44,3 +40,7 @@ def __call__(self, result): def countTestCases(self): return 0 + + @property + def _testMethodName(self): + return self.description diff --git a/haas/exceptions.py b/haas/exceptions.py index 1adf9dbc..81462a3f 100644 --- a/haas/exceptions.py +++ b/haas/exceptions.py @@ -4,7 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals class HaasException(Exception): diff --git a/haas/haas_application.py b/haas/haas_application.py index 38d41bb8..47a11c07 100644 --- a/haas/haas_application.py +++ b/haas/haas_application.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import argparse import os @@ -64,7 +62,7 @@ def _add_log_level_option(parser): help='Log level for haas logging') -class HaasApplication(object): +class HaasApplication: """Main haas application entry-point. """ diff --git a/haas/loader.py b/haas/loader.py index d8b8e204..bce50436 100644 --- a/haas/loader.py +++ b/haas/loader.py @@ -4,14 +4,12 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import unittest from .suite import TestSuite -class Loader(object): +class Loader: """Load individual test cases from modules and wrap them in the :class:`~haas.suite.Suite` container. diff --git a/haas/main.py b/haas/main.py index 86a5454c..7cd0ac10 100644 --- a/haas/main.py +++ b/haas/main.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals # pragma: no cover - import sys # pragma: no cover from .haas_application import HaasApplication # pragma: no cover diff --git a/haas/module_import_error.py b/haas/module_import_error.py index 371347e6..504718d4 100644 --- a/haas/module_import_error.py +++ b/haas/module_import_error.py @@ -4,10 +4,9 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals -class ModuleImportError(object): +class ModuleImportError: """A base class for generated ModuleImportError placeholder test cases. """ diff --git a/haas/plugin_context.py b/haas/plugin_context.py index 67b6fbfb..fe9ef0a5 100644 --- a/haas/plugin_context.py +++ b/haas/plugin_context.py @@ -4,10 +4,9 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals -class PluginContext(object): +class PluginContext: """Handles correct setup and teardown of multiple plugins. """ diff --git a/haas/plugin_manager.py b/haas/plugin_manager.py index 9880d928..04bef76f 100644 --- a/haas/plugin_manager.py +++ b/haas/plugin_manager.py @@ -4,24 +4,17 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - -import sys import logging +from collections import OrderedDict from stevedore.extension import ExtensionManager from .utils import uncamelcase -if sys.version_info < (2, 7): # pragma: no cover - from ordereddict import OrderedDict -else: # pragma: no cover - from collections import OrderedDict - logger = logging.getLogger(__name__) -class PluginManager(object): +class PluginManager: ENVIRONMENT_HOOK = 'haas.hooks.environment' diff --git a/haas/plugins/__init__.py b/haas/plugins/__init__.py index c7ed91e5..e95bbccb 100644 --- a/haas/plugins/__init__.py +++ b/haas/plugins/__init__.py @@ -4,4 +4,3 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals diff --git a/haas/plugins/base_hook_plugin.py b/haas/plugins/base_hook_plugin.py index d4cd6464..482e948f 100644 --- a/haas/plugins/base_hook_plugin.py +++ b/haas/plugins/base_hook_plugin.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from .i_hook_plugin import IHookPlugin diff --git a/haas/plugins/coverage.py b/haas/plugins/coverage.py index 6f1996f9..36088974 100644 --- a/haas/plugins/coverage.py +++ b/haas/plugins/coverage.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import coverage from .base_hook_plugin import BaseHookPlugin diff --git a/haas/plugins/discoverer.py b/haas/plugins/discoverer.py index ca2f3de5..d6fc2777 100644 --- a/haas/plugins/discoverer.py +++ b/haas/plugins/discoverer.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from fnmatch import fnmatch from importlib import import_module from os import getcwd @@ -14,11 +12,11 @@ import os import sys import traceback +import unittest from haas.exceptions import DotInModuleNameError from haas.module_import_error import ModuleImportError from haas.suite import find_test_cases -from haas.testing import unittest from .i_discoverer_plugin import IDiscovererPlugin logger = logging.getLogger(__name__) diff --git a/haas/plugins/i_discoverer_plugin.py b/haas/plugins/i_discoverer_plugin.py index dc2e0bee..a0dc3686 100644 --- a/haas/plugins/i_discoverer_plugin.py +++ b/haas/plugins/i_discoverer_plugin.py @@ -4,14 +4,10 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals +from abc import ABC, abstractmethod, abstractclassmethod -from abc import ABCMeta, abstractmethod -from haas.utils import abstractclassmethod - - -class IDiscovererPlugin(object, metaclass=ABCMeta): +class IDiscovererPlugin(ABC): @abstractclassmethod def from_args(cls, args, arg_prefix, loader): diff --git a/haas/plugins/i_hook_plugin.py b/haas/plugins/i_hook_plugin.py index fa16238b..846b218e 100644 --- a/haas/plugins/i_hook_plugin.py +++ b/haas/plugins/i_hook_plugin.py @@ -4,14 +4,10 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import abc -from haas.utils import abstractclassmethod - -class IHookPlugin(object, metaclass=abc.ABCMeta): +class IHookPlugin(abc.ABC): @abc.abstractmethod def setup(self): # pragma: no cover @@ -21,10 +17,10 @@ def setup(self): # pragma: no cover def teardown(self): # pragma: no cover pass - @abstractclassmethod + @abc.abstractclassmethod def add_parser_arguments(cls, parser, name, option_prefix, dest_prefix): pass - @abstractclassmethod + @abc.abstractclassmethod def from_args(cls, args, dest_prefix): pass diff --git a/haas/plugins/i_result_handler_plugin.py b/haas/plugins/i_result_handler_plugin.py index 80c15512..94befa3b 100644 --- a/haas/plugins/i_result_handler_plugin.py +++ b/haas/plugins/i_result_handler_plugin.py @@ -4,14 +4,10 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals +from abc import ABC, abstractmethod, abstractclassmethod -from abc import ABCMeta, abstractmethod -from haas.utils import abstractclassmethod - - -class IResultHandlerPlugin(object, metaclass=ABCMeta): +class IResultHandlerPlugin(ABC): @abstractclassmethod def from_args(cls, args, name, dest_prefix, test_count): diff --git a/haas/plugins/i_runner_plugin.py b/haas/plugins/i_runner_plugin.py index 65e3de81..438f4cda 100644 --- a/haas/plugins/i_runner_plugin.py +++ b/haas/plugins/i_runner_plugin.py @@ -4,14 +4,10 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals +from abc import ABC, abstractclassmethod -import abc -from haas.utils import abstractclassmethod - - -class IRunnerPlugin(object, metaclass=abc.ABCMeta): +class IRunnerPlugin(ABC): @abstractclassmethod def from_args(cls, args, arg_prefix): diff --git a/haas/plugins/parallel_runner.py b/haas/plugins/parallel_runner.py index d1d13b93..bc0e7bdb 100644 --- a/haas/plugins/parallel_runner.py +++ b/haas/plugins/parallel_runner.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2013-2014 Simon Jagoe +# All rights reserved. +# +# This software may be modified and distributed under the terms +# of the 3-clause BSD license. See the LICENSE.txt file for details. from importlib import import_module from multiprocessing import Pool import time diff --git a/haas/plugins/result_handler.py b/haas/plugins/result_handler.py index 63d05228..7b472fe9 100644 --- a/haas/plugins/result_handler.py +++ b/haas/plugins/result_handler.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import statistics import sys import time @@ -22,7 +20,7 @@ def get_test_description(test, descriptions=True): return str(test) -class _WritelnDecorator(object): +class _WritelnDecorator: """Used to decorate file-like objects with a handy 'writeln' method""" def __init__(self, stream): self.stream = stream diff --git a/haas/plugins/runner.py b/haas/plugins/runner.py index c3f6763e..d31427ff 100644 --- a/haas/plugins/runner.py +++ b/haas/plugins/runner.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from .i_runner_plugin import IRunnerPlugin import warnings diff --git a/haas/result.py b/haas/result.py index 14f9eaa3..ccb82756 100644 --- a/haas/result.py +++ b/haas/result.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - from datetime import datetime, timedelta from enum import Enum from functools import wraps @@ -110,7 +108,7 @@ def _format_exception(err, is_failure, stdout=None, stderr=None): return ''.join(msgLines) -class TestDuration(object): +class TestDuration: """An orderable representation of the duration of an individual test. """ @@ -214,7 +212,7 @@ def __truediv__(self, divisor): return TestDuration(self.duration / divisor) -class TestResult(object): +class TestResult: """Container object for all information related to the run of a single test. This contains the test itself, the actual status including the reason or error associated with status, along with timing @@ -330,7 +328,7 @@ def inner(self, *args, **kw): return inner -class ResultCollector(object): +class ResultCollector: """Collecter for test results. This handles creating :class:`~.TestResult` instances and handing them off the registered result output handlers. diff --git a/haas/suite.py b/haas/suite.py index 5e92ec68..469d352f 100644 --- a/haas/suite.py +++ b/haas/suite.py @@ -4,8 +4,6 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import logging import sys from .error_holder import ErrorHolder @@ -32,7 +30,7 @@ def find_test_cases(suite): yield test_ -class _TestSuiteState(object): +class _TestSuiteState: def __init__(self, result): self._result = result @@ -147,7 +145,7 @@ def teardown(self): self._teardown_module(previous_module) -class TestSuite(object): +class TestSuite: """A ``TestSuite`` is a container of test cases and allows executing many test cases while managing the state of the overall suite. diff --git a/haas/utils.py b/haas/utils.py index 677922f7..7f68205b 100644 --- a/haas/utils.py +++ b/haas/utils.py @@ -4,12 +4,9 @@ # # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. -from __future__ import absolute_import, unicode_literals - import logging import os import re -import sys import haas @@ -50,7 +47,7 @@ def uncamelcase(string, sep='_'): return UNCAMELCASE_SECOND_PASS.sub(replace, temp).lower() -class cd(object): +class cd: def __init__(self, destdir): self.destdir = destdir @@ -63,27 +60,3 @@ def __enter__(self): def __exit__(self, exc_type, exc_value, traceback): os.chdir(self.startdir) self.startdir = None - - -if sys.version_info < (3, 2): # pragma: no cover - # Copied from Python 3.2 abc.py - class abstractclassmethod(classmethod): - """A decorator indicating abstract classmethods. - - Similar to abstractmethod. - - Usage: - - class C(metaclass=ABCMeta): - @abstractclassmethod - def my_abstract_classmethod(cls, ...): - ... - """ - - __isabstractmethod__ = True - - def __init__(self, callable): - callable.__isabstractmethod__ = True - super(abstractclassmethod, self).__init__(callable) -else: # pragma: no cover - from abc import abstractclassmethod # noqa From b1b671ecc68b4a26b1955b66a4a08a8954339ef2 Mon Sep 17 00:00:00 2001 From: Ioannis Tziakos Date: Sun, 22 Sep 2024 14:06:41 +0100 Subject: [PATCH 4/5] exclude build on missing configurations --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7fb9e669..45d2c80f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,9 @@ jobs: matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"] os: [windows-latest, ubuntu-latest, macos-latest] + exclude: + - python-version: "3.7" + os: macos-latest fail-fast: false runs-on: ${{ matrix.os }} steps: From 866a865dfcedf92c0dbbd84a817d8c11dd35797e Mon Sep 17 00:00:00 2001 From: Ioannis Tziakos Date: Sun, 22 Sep 2024 14:11:49 +0100 Subject: [PATCH 5/5] statistics module is available since Python 3.4 --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 438e211a..bc4f333f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ classifiers = [ "Topic :: Software Development :: Testing", ] dependencies = [ - "statistics", "stevedore", ]