Skip to content

Commit

Permalink
Fix GitHub CI, use 3.11, 3.12 and 3.13 and fix pylint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Kaindl <[email protected]>
  • Loading branch information
bernhardkaindl committed Nov 15, 2024
1 parent 97b9a51 commit d462dba
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 184 deletions.
23 changes: 4 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ jobs:
fail-fast: false
matrix:
include:
- python-version: '3.6'
os: ubuntu-20.04
- python-version: '3.10'
os: ubuntu-22.04
- python-version: '3.11'
os: ubuntu-22.04
- python-version: '3.12'
os: ubuntu-22.04
- python-version: '3.13'
os: ubuntu-22.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -58,21 +58,6 @@ jobs:
pip install 'virtualenv<20.22' 'tox==4.5.1' tox-gh-actions
tox --workdir .github/workflows/.tox --recreate
# tox >= 4.0.0 is needed for using optional-dependencies from pyproject.toml, which is
# is not available for python <= 3.6, so use the python3.8 of Ubuntu-20.04 to install it:
- name: Run tox for 3.6 and 3.8 on ${{ matrix.os }}'s 3.8 to get 'extras' from pyproject.toml)
if: ${{ matrix.python-version == 2.7 || matrix.python-version == 3.6 }}
run: |
set -xv;curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py
# The alternative is installing python3-pip but we don't need full pip function for now:
# sudo apt-get update && sudo apt-get install -y python3-pip
# Let tox-gh-actions get the environment(s) to run tests with from tox.ini:
# Use tox==4.5.1: tox>=4 is needed for reading the extras from pyproject.toml
# Warning: tox>=4.5.2 depends on virutalenv>=20.23, which breaks Python 2.7:
python3.8 -m pip install 'virtualenv<20.22' 'tox==4.5.1' tox-gh-actions
tox --workdir .github/workflows/.tox --recreate
- name: Select the coverage file for upload
if: |
( matrix.python-version == '3.6' || matrix.python-version == '3.11' ) &&
Expand Down
6 changes: 4 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ disable=W0142,W0703,C0111,R0201,W0603,W0613,W0212,W0141,
len-as-condition,
no-else-return,
raise-missing-from,
too-many-positional-arguments,
too-many-branches,
too-many-nested-blocks,
too-many-statements,
Expand Down Expand Up @@ -222,8 +223,9 @@ defining-attr-methods=__init__,__new__,setUp

[DESIGN]

# Maximum number of arguments for function / method
max-args=100
# Maximum number of arguments for function / method.
# defaults to: max-args=5
max-args=10

# Argument names that match this expression will be ignored. Default to name
# with leading underscore
Expand Down
9 changes: 2 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ mypy = [
"types-six",
"types-toml",
]
# pyre introduced two false-postives recently, pin it to prevent further surprises:
pyre = [
"pyre-check == 0.9.21",
"pyre-extensions == 0.0.30",
]
pytype = [
"pandas",
"pytype",
Expand Down Expand Up @@ -198,7 +193,7 @@ exclude = [
extraPaths = ["stubs"]
include = ["xcp", "tests"]
pythonPlatform = "Linux"
pythonVersion = "3.6"
pythonVersion = "3.11"
reportFunctionMemberAccess = true
reportGeneralTypeIssues = "warning"
reportOptionalMemberAccess = "warning"
Expand All @@ -211,7 +206,7 @@ stubPath = "stubs"
inputs = ["xcp", "tests", "./*.py"]
keepgoing = true
platform = "linux"
python_version = "3.10"
python_version = "3.11"
pythonpath = ".:stubs"
disable = ["ignored-type-comment"]
overriding_parameter_count_checks = true
Expand Down
62 changes: 0 additions & 62 deletions pyre_runner.py

This file was deleted.

4 changes: 2 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
required_plugins =
pytest_httpserver
pytest-forked
pytest-localftpserver
pytest-pythonpath
pytest-subprocess
pytest-timeout
Expand All @@ -38,4 +37,5 @@ filterwarnings=ignore:Unknown config option
pythonpath=stubs
# Disable when using pytest >= 7.0.0:
# Used by pytest-pythonpath for Python >=2.7 (https://pypi.org/project/pytest-pythonpath):
python_paths=stubs
# Can now only be activated when using newer pytest:
#python_paths=stubs
Empty file removed stubs/pyfakefs/__init__.pyi
Empty file.
20 changes: 0 additions & 20 deletions stubs/pyfakefs/fake_filesystem_unittest.pyi

This file was deleted.

8 changes: 0 additions & 8 deletions stubs/pytest.pyi

This file was deleted.

3 changes: 0 additions & 3 deletions stubs/werkzeug/wrappers.pyi

This file was deleted.

14 changes: 12 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@
This module is run automatically by pytest to define and enable fixtures.
"""

# pyre-ignore-all-errors[21]
import os
import tempfile
import warnings

import pytest # pyre does not find the module when run by tox -e py311-pyre
import pytest


@pytest.fixture()
def mount_dir():
"""pytest fixture for getting a temporary name for a temp directory"""
mount_point = tempfile.mkdtemp(prefix="media-", dir="/tmp")
os.rmdir(mount_point)
return mount_point.encode()


@pytest.fixture(autouse=True)
def set_warnings():
Expand Down
6 changes: 4 additions & 2 deletions tests/httpserver_testcase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import unittest
from typing import Callable, Optional

Expand All @@ -11,9 +12,10 @@
from pytest_httpserver import HTTPServer
from werkzeug.wrappers import Request, Response

ErrorHandler = Optional[Callable[[Request], Response]]
ErrorHandler = Optional[Callable[[Request], Response | None]]
except ImportError:
pytest.skip(allow_module_level=True)
sys.exit(0) # Let pyright know that this is a dead end


class HTTPServerTestCase(unittest.TestCase):
Expand All @@ -31,7 +33,7 @@ def tearDownClass(cls):

@classmethod
def serve_file(cls, root, file_path, error_handler=None, real_path=None):
# type:(str, str, Optional[Callable[[Request], Response]], Optional[str]) -> None
# type:(str, str, ErrorHandler, Optional[str]) -> None
"""Expect a GET request and handle it using the local pytest_httpserver.HTTPServer"""

def handle_get(request):
Expand Down
15 changes: 9 additions & 6 deletions tests/test_accessor.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import unittest

from pyfakefs.fake_filesystem import FakeFilesystem
from typing import TYPE_CHECKING

import xcp.accessor

from .test_mountingaccessor import check_binary_read, check_binary_write

if TYPE_CHECKING:
import pyfakefs
import pytest


def test_file_accessor(fs):
# type:(FakeFilesystem) -> None
def test_file_accessor(fs, caplog):
# type(pyfakefs.fake_filesystem.FakeFilesystem, pytest.LogCaptureFixture) -> None
"""Test FileAccessor.writeFile(), .openAddress and .access using pyfakefs"""
accessor = xcp.accessor.createAccessor("file://repo/", False)
assert isinstance(accessor, xcp.accessor.FileAccessor)
check_binary_read(accessor, "/repo", fs)
check_binary_write(accessor, "/repo", fs)
check_binary_write(accessor, "/repo", fs, caplog)


class TestAccessor(unittest.TestCase):
def setUp(self):
"""Provide the refrence content of the repo/.treeinfo file for check_repo_access()"""
"""Provide the reference content of the repo/.treeinfo file for check_repo_access()"""
with open("tests/data/repo/.treeinfo", "rb") as dot_treeinfo:
self.reference_treeinfo = dot_treeinfo.read()

Expand Down
3 changes: 1 addition & 2 deletions tests/test_bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def test_grub2(self):
universal_newlines=True)
assert proc.stdout
for line in proc.stdout:
# pylint: disable-next=deprecated-method
self.assertRegexpMatches(line, r"^(5a6,13$|>)")
self.assertRegex(line, r"^(5a6,13$|>)") # Replaced removed assert call

proc.stdout.close()
proc.wait()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ftpaccessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
from io import BytesIO

import pytest
import pytest_localftpserver # pylint: disable=unused-import # Ensure that it is installed
import pytest_localftpserver # Ensure that it is installed
from six import ensure_binary, ensure_str

import xcp.accessor

binary_data = b"\x80\x91\xaa\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xcc\xdd\xee\xff"
text_data = "✋➔Hello Accessor from the 🗺, download and verify ✅ me!"
assert pytest_localftpserver


def upload_textfile(ftpserver, accessor):
Expand Down
1 change: 0 additions & 1 deletion tests/test_httpaccessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def http_get_request_data(self, url, read_file, error_handler):

def assert_http_get_request_data(self, url, read_file, error_handler):
# type:(str, str, ErrorHandler) -> HTTPAccessor
# pyre-ignore[23]: silence false positive
with self.http_get_request_data(url, read_file, error_handler) as (httpaccessor, ref):
http_accessor_filehandle = httpaccessor.openAddress(read_file)
if sys.version_info >= (3, 0):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ifrename_logic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pyright: reportGeneralTypeIssues=false
# pyright: reportGeneralTypeIssues=false,reportAttributeAccessIssue=false
# pytype: disable=attribute-error
from __future__ import print_function
from __future__ import unicode_literals
Expand Down
4 changes: 3 additions & 1 deletion tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from xcp.logger import openLog


def test_openLog_mock_open():
def test_openLog_mock_open(fs):
# type(FakeFilesystem) -> None
"""Cover xcp.logger.openLog.open_with_codec_handling and check the arguments used for open()"""
fh = StringIO()
with patch("xcp.compat.open", mock_open()) as open_mock:
Expand All @@ -31,3 +32,4 @@ def test_openLog_mock_stdin():
assert openLog("test.log") is True
os.close(slave_fd)
os.close(master_fd)
open_mock.assert_called_once_with("test.log", "a", **open_utf8)
Loading

0 comments on commit d462dba

Please sign in to comment.