Skip to content

Commit

Permalink
Fix first half of the pyright warnings in unit tests
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 0c94f63 commit 32aceac
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion 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 @@ -14,6 +15,7 @@
ErrorHandler = Optional[Callable[[Request], Response]]
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
8 changes: 5 additions & 3 deletions tests/test_accessor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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


def test_file_accessor(fs):
# type:(FakeFilesystem) -> None
# type(pyfakefs.fake_filesystem.FakeFilesystem) -> None
"""Test FileAccessor.writeFile(), .openAddress and .access using pyfakefs"""
accessor = xcp.accessor.createAccessor("file://repo/", False)
assert isinstance(accessor, xcp.accessor.FileAccessor)
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
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
1 change: 1 addition & 0 deletions tests/test_mountingaccessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest

pytest.skip(allow_module_level=True)
sys.exit(0) # Let pyright know that this is a dead end

binary_data = b"\x00\x1b\x5b\x95\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xcc\xdd\xee\xff"

Expand Down
5 changes: 4 additions & 1 deletion tests/test_pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

if sys.version_info >= (3, 6):
from pytest_subprocess.fake_process import FakeProcess
else:
pytest.skip(allow_module_level=True)

class TestInvalid(unittest.TestCase):

Expand Down Expand Up @@ -185,6 +187,7 @@ def test_videoclass_by_mock_calls(fp):
def mock_lspci_using_open_testfile(fp):
"""Mock xcp.pci.PCIDevices.Popen() using open(tests/data/lspci-mn)"""
with open("tests/data/lspci-mn", "rb") as fake_data:
assert isinstance(fp, FakeProcess)
if sys.version_info >= (3, 6):
assert isinstance(fp, FakeProcess)
fp.register_subprocess(["lspci", "-mn"], stdout=fake_data.read())
return PCIDevices()

0 comments on commit 32aceac

Please sign in to comment.