Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

@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 All @@ -44,6 +46,6 @@
filepath = root + (real_path or file_path)
assert os.path.exists(path=filepath)
with open(file=filepath, mode="rb") as local_testdata_file:
return Response(local_testdata_file.read())

Check warning on line 49 in tests/httpserver_testcase.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

Object of type "type[Any]" is not callable (reportCallIssue)

Check warning on line 49 in tests/httpserver_testcase.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

Object of type "type[Any]" is not callable (reportCallIssue)

cls.httpserver.expect_request(uri="/" + file_path).respond_with_handler(func=handle_get)
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 All @@ -47,7 +48,7 @@
return next(ftp_content_generator)["content"]


@pytest.fixture

Check warning on line 51 in tests/test_ftpaccessor.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

Object of type "type[Any]" is not callable (reportCallIssue)

Check warning on line 51 in tests/test_ftpaccessor.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

Object of type "type[Any]" is not callable (reportCallIssue)
def ftp_accessor(ftpserver):
upload = {"src": "tests/test_ftpaccessor.py", "dest": "testdir/dummy-file-to-create-testdir"}
ftpserver.put_files(upload, anon=False, overwrite=True)
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 @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, cast

from mock import patch
from pyfakefs.fake_filesystem import FakeFileOpen, FakeFilesystem

Check failure on line 7 in tests/test_mountingaccessor.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0611: no-name-in-module

No name 'fake_filesystem' in module 'pyfakefs'

Check failure on line 7 in tests/test_mountingaccessor.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0401: import-error

Unable to import 'pyfakefs.fake_filesystem'

Check failure on line 7 in tests/test_mountingaccessor.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0611: no-name-in-module

No name 'fake_filesystem' in module 'pyfakefs'

Check failure on line 7 in tests/test_mountingaccessor.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0401: import-error

Unable to import 'pyfakefs.fake_filesystem'

import xcp.accessor
import xcp.mount
Expand All @@ -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 @@ -3,7 +3,7 @@
import unittest
from os import environ

import pyfakefs.fake_filesystem_unittest

Check failure on line 6 in tests/test_pci.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0611: no-name-in-module

No name 'fake_filesystem_unittest' in module 'pyfakefs'

Check failure on line 6 in tests/test_pci.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0401: import-error

Unable to import 'pyfakefs.fake_filesystem_unittest'

Check failure on line 6 in tests/test_pci.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0611: no-name-in-module

No name 'fake_filesystem_unittest' in module 'pyfakefs'

Check failure on line 6 in tests/test_pci.py

View workflow job for this annotation

GitHub Actions / test (3.11, ubuntu-22.04)

pylint E0401: import-error

Unable to import 'pyfakefs.fake_filesystem_unittest'
import pytest
from mock import Mock, patch

Expand All @@ -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 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()
Loading