From 399eb77706d499db80d9add1ac66de6417700f66 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:16:52 +0200 Subject: [PATCH 01/16] Replace assertRegexpMatches with assertRegex --- haas/plugins/tests/test_result_handlers.py | 8 ++++---- haas/tests/test_quiet_result_handler.py | 6 +++--- haas/tests/test_standard_result_handler.py | 6 +++--- haas/tests/test_verbose_result_handler.py | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/haas/plugins/tests/test_result_handlers.py b/haas/plugins/tests/test_result_handlers.py index b1c98af1..b10c08e8 100644 --- a/haas/plugins/tests/test_result_handlers.py +++ b/haas/plugins/tests/test_result_handlers.py @@ -53,7 +53,7 @@ def test_output_stop_test_run_success(self, stderr): output = stderr.getvalue() output_start = '\n\nTest timing report\n' + handler.separator2 self.assertTrue(output.startswith(output_start)) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?00:10\.123 test_method \(') @mock.patch('time.ctime') @@ -234,7 +234,7 @@ def test_output_with_error_on_stop_test_run(self, stderr): output = stderr.getvalue() output_start = '\n\nTest timing report\n' + handler.separator2 self.assertTrue(output.startswith(output_start)) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?1543:00:12\.234 test_method \(') @mock.patch('sys.stderr', new_callable=StringIO) @@ -261,7 +261,7 @@ def test_output_with_failure_on_stop_test_run(self, stderr): output = stderr.getvalue() output_start = '\n\nTest timing report\n' + handler.separator2 self.assertTrue(output.startswith(output_start)) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?1:01:14\.567 test_method \(') def _calculate_statistics(self, test_durations): @@ -341,7 +341,7 @@ class Case(_test_cases.TestCase): output = stderr.getvalue() output_start = '\n\nTest timing report\n' + handler.separator2 self.assertTrue(output.startswith(output_start)) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?00:09\.123 test_method \(') self.assertIn(expected_stats, output) diff --git a/haas/tests/test_quiet_result_handler.py b/haas/tests/test_quiet_result_handler.py index 556197ef..48a146b0 100644 --- a/haas/tests/test_quiet_result_handler.py +++ b/haas/tests/test_quiet_result_handler.py @@ -46,7 +46,7 @@ def test_output_stop_test_run(self, stderr): output = stderr.getvalue() self.assertTrue(output.startswith('\n' + handler.separator2)) self.assertTrue(output.endswith('OK\n')) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?Ran 0 tests.*?OK') @mock.patch('sys.stderr', new_callable=StringIO) @@ -226,7 +226,7 @@ def test_no_output_with_error_on_stop_test_run(self, stderr): output = stderr.getvalue().replace('\n', '') description = handler.get_test_description( case,).replace('(', r'\(').replace(')', r'\)') - self.assertRegexpMatches( + self.assertRegex( output, '{0}.*?Traceback.*?RuntimeError'.format( description)) @@ -254,7 +254,7 @@ def test_no_output_with_failure_on_stop_test_run(self, stderr): output = stderr.getvalue().replace('\n', '') description = handler.get_test_description( case,).replace('(', r'\(').replace(')', r'\)').replace('\n', '') - self.assertRegexpMatches( + self.assertRegex( output, '{0}.*?Traceback.*?AssertionError'.format( description)) # The contents of unittest.TestCase should not be in the traceback diff --git a/haas/tests/test_standard_result_handler.py b/haas/tests/test_standard_result_handler.py index 84e1658c..499edea3 100644 --- a/haas/tests/test_standard_result_handler.py +++ b/haas/tests/test_standard_result_handler.py @@ -46,7 +46,7 @@ def test_output_stop_test_run(self, stderr): output = stderr.getvalue() self.assertTrue(output.startswith('\n' + handler.separator2)) self.assertTrue(output.endswith('OK\n')) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?Ran 0 tests.*?OK') @mock.patch('sys.stderr', new_callable=StringIO) @@ -226,7 +226,7 @@ def test_no_output_with_error_on_stop_test_run(self, stderr): output = stderr.getvalue().replace('\n', '') description = handler.get_test_description( case).replace('(', r'\(').replace(')', r'\)') - self.assertRegexpMatches( + self.assertRegex( output, '{0}.*?Traceback.*?RuntimeError'.format( description)) @@ -254,7 +254,7 @@ def test_no_output_with_failure_on_stop_test_run(self, stderr): output = stderr.getvalue().replace('\n', '') description = handler.get_test_description( case).replace('(', r'\(').replace(')', r'\)').replace('\n', '') - self.assertRegexpMatches( + self.assertRegex( output, '{0}.*?Traceback.*?AssertionError'.format( description)) # The contents of unittest.TestCase should not be in the traceback diff --git a/haas/tests/test_verbose_result_handler.py b/haas/tests/test_verbose_result_handler.py index b136a1e5..ce8f2004 100644 --- a/haas/tests/test_verbose_result_handler.py +++ b/haas/tests/test_verbose_result_handler.py @@ -47,7 +47,7 @@ def test_no_output_stop_test_run(self, stderr): output = stderr.getvalue() self.assertTrue(output.startswith('\n' + handler.separator2)) self.assertTrue(output.endswith('OK\n')) - self.assertRegexpMatches( + self.assertRegex( output.replace('\n', ''), r'--+.*?Ran 0 tests.*?OK') @mock.patch('time.ctime') @@ -232,7 +232,7 @@ def test_output_with_error_on_stop_test_run(self, stderr): output = stderr.getvalue().replace('\n', '') description = handler.get_test_description( case).replace('(', r'\(').replace(')', r'\)') - self.assertRegexpMatches( + self.assertRegex( output, '{0}.*?Traceback.*?RuntimeError'.format( description)) @@ -260,7 +260,7 @@ def test_output_with_failure_on_stop_test_run(self, stderr): output = stderr.getvalue().replace('\n', '') description = handler.get_test_description( case).replace('(', r'\(').replace(')', r'\)').replace('\n', '') - self.assertRegexpMatches( + self.assertRegex( output, '{0}.*?Traceback.*?AssertionError'.format( description)) # The contents of unittest.TestCase should not be in the traceback From 93e5141b1234096ee662bcbc72ce31b057f5cd8b Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:26:42 +0200 Subject: [PATCH 02/16] Simplify install requirements and required python versions --- setup.py | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 3bcff0d7..b45d82b3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ # This software may be modified and distributed under the terms # of the 3-clause BSD license. See the LICENSE.txt file for details. import os -import sys import subprocess from setuptools import setup @@ -105,21 +104,12 @@ def write_version_py(filename='haas/_version.py'): if __name__ == "__main__": - install_requires = ['six'] - common_requires = ['enum34', 'statistics'] - py26_requires = [ - 'stevedore >= 1.0.0, < 1.10.0', - 'unittest2', - 'argparse', - 'ordereddict'] + common_requires - py34_requires = ['stevedore >= 1.0.0, < 1.12.0'] - py33_requires = py34_requires + common_requires - if sys.version_info < (2, 7): - install_requires += py26_requires - elif sys.version_info < (3, 4): - install_requires += py33_requires - else: - install_requires = py34_requires + install_requires = [ + 'six', + 'enum34', + 'statistics', + 'stevedore >= 4.1.0, < 5.0.0', + ] write_version_py() from haas import __version__ @@ -179,13 +169,4 @@ def write_version_py(filename='haas/_version.py'): 'timing = haas.plugins.result_handler:TimingResultHandler', ] }, - extras_require={ - ':python_version=="2.6"': py26_requires, - ':python_version=="2.7"': py33_requires, - ':python_version=="3.3"': py33_requires, - ':python_version=="3.4"': py34_requires, - ':python_version=="3.5"': py34_requires, - ':python_version=="3.6"': py34_requires, - ':python_version=="3.7"': py34_requires, - }, ) From c8188218da498c4de9dec646c397cd5ccae7606e Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:42:13 +0200 Subject: [PATCH 03/16] Remove dependency on six --- haas/plugins/discoverer.py | 6 ++-- haas/plugins/i_discoverer_plugin.py | 5 +--- haas/plugins/i_hook_plugin.py | 5 +--- haas/plugins/i_result_handler_plugin.py | 5 +--- haas/plugins/i_runner_plugin.py | 5 +--- haas/plugins/parallel_runner.py | 4 +-- haas/plugins/tests/test_result_handlers.py | 2 +- haas/result.py | 5 ++-- haas/tests/builder.py | 5 +--- haas/tests/test_buffering.py | 2 +- haas/tests/test_loader.py | 5 +--- haas/tests/test_parallel_runner.py | 2 +- haas/tests/test_quiet_result_handler.py | 2 +- haas/tests/test_standard_result_handler.py | 2 +- haas/tests/test_test_duration_ordering.py | 34 ++++++++++------------ haas/tests/test_verbose_result_handler.py | 2 +- haas/utils.py | 16 +--------- setup.py | 1 - test_requirements.txt | 1 - 19 files changed, 36 insertions(+), 73 deletions(-) diff --git a/haas/plugins/discoverer.py b/haas/plugins/discoverer.py index 74a5ca09..a8d2ab09 100644 --- a/haas/plugins/discoverer.py +++ b/haas/plugins/discoverer.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, unicode_literals from fnmatch import fnmatch +from importlib import import_module import logging import os import sys @@ -16,7 +17,6 @@ from haas.module_import_error import ModuleImportError from haas.suite import find_test_cases from haas.testing import unittest -from haas.utils import get_module_by_name from .i_discoverer_plugin import IDiscovererPlugin logger = logging.getLogger(__name__) @@ -77,7 +77,7 @@ def find_module_by_name(full_name): module_attributes = [] while True: try: - module = get_module_by_name(module_name) + module = import_module(module_name) except ImportError: if '.' in module_name: module_name, attribute = module_name.rsplit('.', 1) @@ -365,7 +365,7 @@ def _load_from_file(self, filepath, top_level_directory): module_name = get_module_name(top_level_directory, filepath) logger.debug('Loading tests from %r', module_name) try: - module = get_module_by_name(module_name) + module = import_module(module_name) except Exception: test = _create_import_error_test(module_name) else: diff --git a/haas/plugins/i_discoverer_plugin.py b/haas/plugins/i_discoverer_plugin.py index 7a17ce3c..dc2e0bee 100644 --- a/haas/plugins/i_discoverer_plugin.py +++ b/haas/plugins/i_discoverer_plugin.py @@ -8,13 +8,10 @@ from abc import ABCMeta, abstractmethod -from six import add_metaclass - from haas.utils import abstractclassmethod -@add_metaclass(ABCMeta) -class IDiscovererPlugin(object): +class IDiscovererPlugin(object, metaclass=ABCMeta): @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 e3826f63..fa16238b 100644 --- a/haas/plugins/i_hook_plugin.py +++ b/haas/plugins/i_hook_plugin.py @@ -8,13 +8,10 @@ import abc -from six import add_metaclass - from haas.utils import abstractclassmethod -@add_metaclass(abc.ABCMeta) -class IHookPlugin(object): +class IHookPlugin(object, metaclass=abc.ABCMeta): @abc.abstractmethod def setup(self): # pragma: no cover diff --git a/haas/plugins/i_result_handler_plugin.py b/haas/plugins/i_result_handler_plugin.py index 6a20913d..80c15512 100644 --- a/haas/plugins/i_result_handler_plugin.py +++ b/haas/plugins/i_result_handler_plugin.py @@ -8,13 +8,10 @@ from abc import ABCMeta, abstractmethod -from six import add_metaclass - from haas.utils import abstractclassmethod -@add_metaclass(ABCMeta) -class IResultHandlerPlugin(object): +class IResultHandlerPlugin(object, metaclass=ABCMeta): @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 25d134c3..65e3de81 100644 --- a/haas/plugins/i_runner_plugin.py +++ b/haas/plugins/i_runner_plugin.py @@ -8,13 +8,10 @@ import abc -from six import add_metaclass - from haas.utils import abstractclassmethod -@add_metaclass(abc.ABCMeta) -class IRunnerPlugin(object): +class IRunnerPlugin(object, metaclass=abc.ABCMeta): @abstractclassmethod def from_args(cls, args, arg_prefix): diff --git a/haas/plugins/parallel_runner.py b/haas/plugins/parallel_runner.py index 803e0cb4..d1d13b93 100644 --- a/haas/plugins/parallel_runner.py +++ b/haas/plugins/parallel_runner.py @@ -1,10 +1,10 @@ +from importlib import import_module from multiprocessing import Pool import time from haas.module_import_error import ModuleImportError from haas.suite import find_test_cases from haas.result import ResultCollector -from haas.utils import get_module_by_name from .i_result_handler_plugin import IResultHandlerPlugin from .runner import BaseTestRunner @@ -82,7 +82,7 @@ def from_args(cls, args, arg_prefix): initializer = None else: module_name, initializer_name = initializer_spec.rsplit('.', 1) - init_module = get_module_by_name(module_name) + init_module = import_module(module_name) initializer = getattr(init_module, initializer_name) return cls(process_count=args.processes, initializer=initializer, maxtasksperchild=args.process_max_tasks) diff --git a/haas/plugins/tests/test_result_handlers.py b/haas/plugins/tests/test_result_handlers.py index b10c08e8..ff2aeb1b 100644 --- a/haas/plugins/tests/test_result_handlers.py +++ b/haas/plugins/tests/test_result_handlers.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta import statistics -from six.moves import StringIO +from io import StringIO from haas.result import TestResult, TestCompletionStatus, TestDuration from haas.testing import unittest diff --git a/haas/result.py b/haas/result.py index de1a3e10..1a3a834f 100644 --- a/haas/result.py +++ b/haas/result.py @@ -14,8 +14,7 @@ import traceback import warnings -import six -from six.moves import StringIO +from io import StringIO from .error_holder import ErrorHolder @@ -65,7 +64,7 @@ def _count_relevant_tb_levels(tb): def _decode(line, encoding): - if isinstance(line, six.text_type): + if isinstance(line, str): return line try: return line.decode(encoding) diff --git a/haas/tests/builder.py b/haas/tests/builder.py index a2c3f9bf..cd44b784 100644 --- a/haas/tests/builder.py +++ b/haas/tests/builder.py @@ -10,13 +10,10 @@ import os import textwrap -from six import add_metaclass - from ..testing import unittest -@add_metaclass(abc.ABCMeta) -class Importable(object): +class Importable(object, metaclass=abc.ABCMeta): def __init__(self, name, contents=()): self.name = name diff --git a/haas/tests/test_buffering.py b/haas/tests/test_buffering.py index f279a349..79f4edde 100644 --- a/haas/tests/test_buffering.py +++ b/haas/tests/test_buffering.py @@ -9,7 +9,7 @@ from datetime import datetime, timedelta import sys -from six.moves import StringIO +from io import StringIO from haas.tests.compat import mock from ..plugins.i_result_handler_plugin import IResultHandlerPlugin diff --git a/haas/tests/test_loader.py b/haas/tests/test_loader.py index afe0bf55..a64fbba4 100644 --- a/haas/tests/test_loader.py +++ b/haas/tests/test_loader.py @@ -8,8 +8,6 @@ import unittest as python_unittest -import six - from haas.testing import unittest from . import _test_cases @@ -111,8 +109,7 @@ def assertSuiteClasses(self, suite, klass): def test_find_all_cases_in_module(self): cases = self.loader.get_test_cases_from_module(_test_cases) - six.assertCountEqual( - self, + self.assertCountEqual( cases, [_test_cases.TestCase, _test_cases.PythonTestCase]) def test_load_all_cases_in_module(self): diff --git a/haas/tests/test_parallel_runner.py b/haas/tests/test_parallel_runner.py index 6590fd38..d190b6ca 100644 --- a/haas/tests/test_parallel_runner.py +++ b/haas/tests/test_parallel_runner.py @@ -2,7 +2,7 @@ from datetime import datetime, timedelta import time -from six.moves import StringIO +from io import StringIO from ..plugins.discoverer import _create_import_error_test from ..plugins.parallel_runner import ChildResultHandler, ParallelTestRunner diff --git a/haas/tests/test_quiet_result_handler.py b/haas/tests/test_quiet_result_handler.py index 48a146b0..3bd4f103 100644 --- a/haas/tests/test_quiet_result_handler.py +++ b/haas/tests/test_quiet_result_handler.py @@ -8,7 +8,7 @@ from datetime import datetime, timedelta -from six.moves import StringIO +from io import StringIO from ..plugins.result_handler import QuietTestResultHandler from ..result import ( diff --git a/haas/tests/test_standard_result_handler.py b/haas/tests/test_standard_result_handler.py index 499edea3..69f6a255 100644 --- a/haas/tests/test_standard_result_handler.py +++ b/haas/tests/test_standard_result_handler.py @@ -8,7 +8,7 @@ from datetime import datetime, timedelta -from six.moves import StringIO +from io import StringIO from ..plugins.result_handler import StandardTestResultHandler from ..result import ( diff --git a/haas/tests/test_test_duration_ordering.py b/haas/tests/test_test_duration_ordering.py index 7f0059ec..83a97698 100644 --- a/haas/tests/test_test_duration_ordering.py +++ b/haas/tests/test_test_duration_ordering.py @@ -9,8 +9,6 @@ from datetime import datetime, timedelta import sys -import six - from ..result import TestDuration from ..testing import unittest @@ -76,11 +74,11 @@ def test_equality(self): self.assertEqual(duration1, duration2) self.assertLessEqual(duration1, duration2) self.assertGreaterEqual(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not less than'): + with self.assertRaisesRegex( + self.failureException, 'not less than'): self.assertLess(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not greater than'): + with self.assertRaisesRegex( + self.failureException, 'not greater than'): self.assertGreater(duration1, duration2) self.assertNotEqual(duration1, object()) @@ -99,11 +97,11 @@ def test_equality(self): self.assertEqual(duration1, duration2) self.assertLessEqual(duration1, duration2) self.assertGreaterEqual(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not less than'): + with self.assertRaisesRegex( + self.failureException, 'not less than'): self.assertLess(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not greater than'): + with self.assertRaisesRegex( + self.failureException, 'not greater than'): self.assertGreater(duration1, duration2) def test_lessthan(self): @@ -122,11 +120,11 @@ def test_lessthan(self): self.assertNotEqual(duration1, duration2) self.assertLess(duration1, duration2) self.assertLessEqual(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not greater than or equal to'): + with self.assertRaisesRegex( + self.failureException, 'not greater than or equal to'): self.assertGreaterEqual(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not greater than'): + with self.assertRaisesRegex( + self.failureException, 'not greater than'): self.assertGreater(duration1, duration2) def test_greaterthan(self): @@ -145,9 +143,9 @@ def test_greaterthan(self): self.assertNotEqual(duration1, duration2) self.assertGreater(duration1, duration2) self.assertGreaterEqual(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not less than or equal to'): + with self.assertRaisesRegex( + self.failureException, 'not less than or equal to'): self.assertLessEqual(duration1, duration2) - with six.assertRaisesRegex( - self, self.failureException, 'not less than'): + with self.assertRaisesRegex( + self.failureException, 'not less than'): self.assertLess(duration1, duration2) diff --git a/haas/tests/test_verbose_result_handler.py b/haas/tests/test_verbose_result_handler.py index ce8f2004..a10b3491 100644 --- a/haas/tests/test_verbose_result_handler.py +++ b/haas/tests/test_verbose_result_handler.py @@ -9,7 +9,7 @@ from datetime import datetime, timedelta from time import ctime -from six.moves import StringIO +from io import StringIO from ..plugins.result_handler import VerboseTestResultHandler from ..result import ( diff --git a/haas/utils.py b/haas/utils.py index 93a5057b..677922f7 100644 --- a/haas/utils.py +++ b/haas/utils.py @@ -8,10 +8,8 @@ import logging import os -import sys import re - -import six +import sys import haas @@ -40,18 +38,6 @@ def configure_logging(level): logging.getLevelName(actual_level)) -if six.PY2: - def get_module_by_name(name): - """Import a module and return the imported module object. - - """ - __import__(name) - return sys.modules[name] -else: - import importlib - get_module_by_name = importlib.import_module - - UNCAMELCASE_FIRST_PASS = re.compile( r'(?P.)(?P[A-Z]+)') UNCAMELCASE_SECOND_PASS = re.compile( diff --git a/setup.py b/setup.py index b45d82b3..eb48be3e 100644 --- a/setup.py +++ b/setup.py @@ -105,7 +105,6 @@ def write_version_py(filename='haas/_version.py'): if __name__ == "__main__": install_requires = [ - 'six', 'enum34', 'statistics', 'stevedore >= 4.1.0, < 5.0.0', diff --git a/test_requirements.txt b/test_requirements.txt index f345fa94..ff0b4f14 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,5 +1,4 @@ coverage unittest2; python_version == '2.6' mock; python_version < '3.3' -six testfixtures From e4d9f5853afd6124805f4db4ea859108bd1d90a8 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:47:25 +0200 Subject: [PATCH 04/16] Fix unittest invocation in tests --- .github/workflows/test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 033c569a..2c927d99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: needs: [lint] strategy: matrix: - python: [3.7, 3.8, 3.9, "3.10", "3.11", '3.12', 'pypy2', 'pypy3'] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy2", "pypy3"] os: [windows-2019, ubuntu-22.04, macos-11] fail-fast: false runs-on: ${{ matrix.os }} @@ -36,10 +36,8 @@ jobs: pip install -r "test_requirements.txt" pip --version - name: Run tests - continue-on-error: false - working-directory: .github run: | - python -m unittest discover haas + python -m unittest discover -v -t . haas python -m haas haas lint: runs-on: ubuntu-latest From 77e36c0444a9d662d3210009e9937026ba6fa596 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:48:18 +0200 Subject: [PATCH 05/16] Don't limit testing on pull request target branch --- .github/workflows/test.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c927d99..66330d4d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,6 @@ name: Test on: pull_request: - branches: - - master - - maintenance/** push: branches: - master From c1f39dc9839eb5478b417718aa5ff75d8a0c478d Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:51:30 +0200 Subject: [PATCH 06/16] Run coverage --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 66330d4d..f448ec2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,8 +34,9 @@ jobs: pip --version - name: Run tests run: | - python -m unittest discover -v -t . haas + coverage run --branch -m unittest discover -v -t . haas python -m haas haas + coverage report lint: runs-on: ubuntu-latest steps: From f99186188e47c0fd4030af8cf38ab973ad1588b2 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 00:52:05 +0200 Subject: [PATCH 07/16] Run lint and tests in parallel --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f448ec2f..c82874d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,6 @@ env: jobs: test: - needs: [lint] strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy2", "pypy3"] @@ -37,6 +36,7 @@ jobs: coverage run --branch -m unittest discover -v -t . haas python -m haas haas coverage report + lint: runs-on: ubuntu-latest steps: From d9d7e6e6905afd4f6034266d01d70058da98c4d6 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:00:10 +0200 Subject: [PATCH 08/16] Separate out test steps --- .github/workflows/test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c82874d8..7ddc0c45 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,10 +31,14 @@ jobs: pip install -e . pip install -r "test_requirements.txt" pip --version - - name: Run tests + - name: Run tests with unittest run: | coverage run --branch -m unittest discover -v -t . haas + - name: Run tests with haas + run: | python -m haas haas + - name: Print coverage report + run: | coverage report lint: From 920d0c9e751b4017fa0f6452555b661cdb433555 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:06:07 +0200 Subject: [PATCH 09/16] Fix python version installed --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ddc0c45..b8f54f58 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: - name: Setup python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} - name: Install run: | pip install -e . From cdb90453cb29eef157a0237144dcb2fac0e0782f Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:08:06 +0200 Subject: [PATCH 10/16] Fix pypy versions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8f54f58..373c4a30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: test: strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy2", "pypy3"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.10", "pypy3.11"] os: [windows-2019, ubuntu-22.04, macos-11] fail-fast: false runs-on: ${{ matrix.os }} From 0516fa17e7fba2e8806eacdb2bbaf8272235b168 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:09:29 +0200 Subject: [PATCH 11/16] Relax stevedore version for windows and python 3.7 support --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index eb48be3e..d6824667 100644 --- a/setup.py +++ b/setup.py @@ -107,7 +107,7 @@ def write_version_py(filename='haas/_version.py'): install_requires = [ 'enum34', 'statistics', - 'stevedore >= 4.1.0, < 5.0.0', + 'stevedore >= 3.5.2, < 5.0.0', ] write_version_py() From 0591a852355d4bebf06156e1a7feb4c93066db09 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:13:11 +0200 Subject: [PATCH 12/16] Decrement pypy versions for available on github actions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 373c4a30..1c821972 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: test: strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.10", "pypy3.11"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"] os: [windows-2019, ubuntu-22.04, macos-11] fail-fast: false runs-on: ${{ matrix.os }} From f54d0a35764012844f5d6c4fd68ae4cea2150ad9 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:14:23 +0200 Subject: [PATCH 13/16] Update github actions runners --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c821972..69e9d743 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"] - os: [windows-2019, ubuntu-22.04, macos-11] + os: [windows-latest, ubuntu-latest, macos-latest] fail-fast: false runs-on: ${{ matrix.os }} steps: From 3903345641702dba749800dd5df70c678cb648ce Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 01:20:58 +0200 Subject: [PATCH 14/16] Update classifiers --- setup.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index d6824667..f250d729 100644 --- a/setup.py +++ b/setup.py @@ -132,13 +132,14 @@ def write_version_py(filename='haas/_version.py'): 'Operating System :: POSIX', 'Operating System :: Unix', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Topic :: Software Development', 'Topic :: Software Development :: Testing', ], From 31cb5896d585f7efce87596fb531ae400b988eaf Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 17:23:13 +0200 Subject: [PATCH 15/16] Use pathlib for path resolution and relative path check --- haas/plugins/discoverer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/haas/plugins/discoverer.py b/haas/plugins/discoverer.py index a8d2ab09..392a8951 100644 --- a/haas/plugins/discoverer.py +++ b/haas/plugins/discoverer.py @@ -8,6 +8,7 @@ from fnmatch import fnmatch from importlib import import_module +from pathlib import Path import logging import os import sys @@ -41,9 +42,11 @@ def test_error(self): def get_relpath(top_level_directory, fullpath): - normalized = os.path.normpath(fullpath) - relpath = os.path.relpath(normalized, top_level_directory) - if os.path.isabs(relpath) or relpath.startswith('..'): + top_level = Path(top_level_directory).resolve() + normalized = Path(fullpath).resolve() + try: + relpath = str(normalized.relative_to(top_level)) + except ValueError: raise ValueError('Path not within project: {0}'.format(fullpath)) return relpath From 1933de3eac2a07ae16004fa933201dac42e93654 Mon Sep 17 00:00:00 2001 From: Simon Jagoe Date: Sun, 3 Dec 2023 17:27:43 +0200 Subject: [PATCH 16/16] Only mock the instance of getcwd that we're interested in --- haas/plugins/discoverer.py | 3 ++- haas/plugins/tests/test_discoverer.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/haas/plugins/discoverer.py b/haas/plugins/discoverer.py index 392a8951..ca2f3de5 100644 --- a/haas/plugins/discoverer.py +++ b/haas/plugins/discoverer.py @@ -8,6 +8,7 @@ from fnmatch import fnmatch from importlib import import_module +from os import getcwd from pathlib import Path import logging import os @@ -424,7 +425,7 @@ def discover_filtered_tests(self, filter_name, top_level_directory=None, """ if top_level_directory is None: top_level_directory = find_top_level_directory( - os.getcwd()) + getcwd()) logger.debug('Discovering filtered tests: filter_name=%r, ' 'top_level_directory=%r, pattern=%r', top_level_directory, diff --git a/haas/plugins/tests/test_discoverer.py b/haas/plugins/tests/test_discoverer.py index 0314f8a5..929ed5d1 100644 --- a/haas/plugins/tests/test_discoverer.py +++ b/haas/plugins/tests/test_discoverer.py @@ -20,6 +20,7 @@ from haas.module_import_error import ModuleImportError from haas.suite import find_test_cases, TestSuite from haas.utils import cd +from haas.plugins import discoverer from ..discoverer import ( Discoverer, filter_test_suite, @@ -451,7 +452,7 @@ def test_discover_class(self): def test_discover_no_top_level(self): getcwd = mock.Mock() getcwd.return_value = self.tmpdir - with mock.patch.object(os, 'getcwd', getcwd): + with mock.patch.object(discoverer, 'getcwd', getcwd): suite = self.discoverer.discover( 'TestCase', )