Skip to content

Commit 32aceac

Browse files
Fix first half of the pyright warnings in unit tests
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 0c94f63 commit 32aceac

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

tests/httpserver_testcase.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import unittest
34
from typing import Callable, Optional
45

@@ -14,6 +15,7 @@
1415
ErrorHandler = Optional[Callable[[Request], Response]]
1516
except ImportError:
1617
pytest.skip(allow_module_level=True)
18+
sys.exit(0) # Let pyright know that this is a dead end
1719

1820

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

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

3739
def handle_get(request):

tests/test_accessor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import unittest
2-
3-
from pyfakefs.fake_filesystem import FakeFilesystem
2+
from typing import TYPE_CHECKING
43

54
import xcp.accessor
65

76
from .test_mountingaccessor import check_binary_read, check_binary_write
87

8+
if TYPE_CHECKING:
9+
import pyfakefs
10+
911

1012
def test_file_accessor(fs):
11-
# type:(FakeFilesystem) -> None
13+
# type(pyfakefs.fake_filesystem.FakeFilesystem) -> None
1214
"""Test FileAccessor.writeFile(), .openAddress and .access using pyfakefs"""
1315
accessor = xcp.accessor.createAccessor("file://repo/", False)
1416
assert isinstance(accessor, xcp.accessor.FileAccessor)

tests/test_ftpaccessor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
from io import BytesIO
2222

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

2727
import xcp.accessor
2828

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

3233

3334
def upload_textfile(ftpserver, accessor):

tests/test_ifrename_logic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pyright: reportGeneralTypeIssues=false
1+
# pyright: reportGeneralTypeIssues=false,reportAttributeAccessIssue=false
22
# pytype: disable=attribute-error
33
from __future__ import print_function
44
from __future__ import unicode_literals

tests/test_mountingaccessor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import pytest
2121

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

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

tests/test_pci.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
if sys.version_info >= (3, 6):
1313
from pytest_subprocess.fake_process import FakeProcess
14+
else:
15+
pytest.skip(allow_module_level=True)
1416

1517
class TestInvalid(unittest.TestCase):
1618

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

0 commit comments

Comments
 (0)