Skip to content

Commit

Permalink
Merge pull request #193 from scalative/fix-support-for-recent-python-…
Browse files Browse the repository at this point in the history
…versions

update-ci-testing
  • Loading branch information
itziakos authored Dec 3, 2023
2 parents 06e5472 + 27b8185 commit 9f8126c
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 233 deletions.
143 changes: 32 additions & 111 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Test

on:
pull_request:
branches:
- master
- maintenance/**
push:
branches:
- master
Expand All @@ -17,118 +14,42 @@ env:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
python: "2.7"
toxenv: cp27
continue-on-error: false
- os: ubuntu-18.04
python: "3.4"
toxenv: cp34
continue-on-error: false
- os: ubuntu-18.04
python: "3.5"
toxenv: cp35
continue-on-error: false
- os: ubuntu-18.04
python: "3.6"
toxenv: cp36
continue-on-error: false
- os: ubuntu-18.04
python: "3.7"
toxenv: cp37
continue-on-error: false
- os: ubuntu-18.04
python: "3.8"
toxenv: cp38
continue-on-error: false
- os: ubuntu-18.04
python: "3.9"
toxenv: cp39
continue-on-error: false

- os: ubuntu-18.04
python: "pypy2"
toxenv: pp2
continue-on-error: false
- os: ubuntu-18.04
python: "pypy3"
toxenv: pp3
continue-on-error: false

- os: ubuntu-20.04
python: "2.7"
toxenv: cp27
continue-on-error: false
- os: ubuntu-20.04
python: "3.5"
toxenv: cp35
continue-on-error: false
- os: ubuntu-20.04
python: "pypy2"
toxenv: pp2
continue-on-error: false
- os: ubuntu-20.04
python: "pypy3"
toxenv: pp3
continue-on-error: false

- os: macos-10.15
python: "3.5"
toxenv: cp35
continue-on-error: true
- os: macos-11.0
python: "3.5"
toxenv: cp35
continue-on-error: true
- os: windows-2019
python: "3.5"
toxenv: cp35
continue-on-error: false

# 3.10 Alpha
- os: ubuntu-18.04
python: "3.10.0-alpha.2"
toxenv: "cp310"
continue-on-error: false
- os: macos-11.0
python: "3.10.0-alpha.2"
toxenv: "cp310"
continue-on-error: true
- os: windows-2019
python: "3.10.0-alpha.2"
toxenv: "cp310"
continue-on-error: true

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]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install
run: pip install -q -r "tox-requirements.txt"
- name: Run tests
continue-on-error: ${{ matrix.continue-on-error }}
env:
TOXENV: ${{ matrix.toxenv }}
run: tox -v
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install
run: |
pip install -e .
pip install -r "test_requirements.txt"
pip --version
- 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:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: "3.7"
- name: Install
run: pip install -q -r "tox-requirements.txt"
- name: Run tests
env:
TOXENV: flake8
run: tox -v
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install flake8
run: python -m pip install flake8
- name: Lint codebase
run: python -m flake8 haas
18 changes: 11 additions & 7 deletions haas/plugins/discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from __future__ import absolute_import, unicode_literals

from fnmatch import fnmatch
from importlib import import_module
from os import getcwd
from pathlib import Path
import logging
import os
import sys
Expand All @@ -16,7 +19,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__)
Expand All @@ -41,9 +43,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

Expand Down Expand Up @@ -77,7 +81,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)
Expand Down Expand Up @@ -365,7 +369,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:
Expand Down Expand Up @@ -421,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,
Expand Down
5 changes: 1 addition & 4 deletions haas/plugins/i_discoverer_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions haas/plugins/i_hook_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions haas/plugins/i_result_handler_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions haas/plugins/i_runner_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions haas/plugins/parallel_runner.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion haas/plugins/tests/test_discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
)
Expand Down
10 changes: 5 additions & 5 deletions haas/plugins/tests/test_result_handlers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions haas/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import traceback
import warnings

import six
from six.moves import StringIO
from io import StringIO

from .error_holder import ErrorHolder

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions haas/tests/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9f8126c

Please sign in to comment.