From 16ed5214510a1e025d333eb3912a94be0c52ecbf Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Fri, 15 Nov 2024 12:00:00 +0100 Subject: [PATCH 1/3] Fix GitHub CI and 'tox' for local CI on Ubuntu 24.04 - It has become impractical to use EOL versions like Python 3.6 in CI - It has become counterproductive to use pyre CI, disable it for now. - Move forward to run the unit tests with Python 3.11 Signed-off-by: Bernhard Kaindl --- .github/workflows/main.yml | 2 -- pytest.ini | 3 ++- tox.ini | 8 +++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e0bc4a8..07853454 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,8 +28,6 @@ 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' diff --git a/pytest.ini b/pytest.ini index e07456ee..0906991a 100644 --- a/pytest.ini +++ b/pytest.ini @@ -8,10 +8,11 @@ # These are the most of the needed pytest plugins, unfortunately this list does # not support ;python_version<=3.0 or ;python_version>3.0. Therefore, it can # only list plugins available for all tested python versions (2.7, 3.6 ... 3.11): +# pytest-localftpserver is also used, but its installation is not checked +# to to its installation not being detected on Ubuntu 24.04: required_plugins = pytest_httpserver pytest-forked - pytest-localftpserver pytest-pythonpath pytest-subprocess pytest-timeout diff --git a/tox.ini b/tox.ini index d7386335..5db78e4e 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ # 2. python 3.6 test and pylint warnings from changed lines # 3. pytype (needs Python 3.8 for best results) # 4. pyre and pyright checks, pytest test report as markdown for GitHub Actions summary -envlist = py38-covcombine-check, py36-lint-test, py310-pytype, py311-pyre-mdreport +envlist = py38-covcombine-check, py311-lint-test, py310-pytype, py311-pyre-mdreport isolated_build = true skip_missing_interpreters = true requires = @@ -28,9 +28,9 @@ commands = # https://github.com/actions/toolkit/blob/main/docs/commands.md#problem-matchers echo "::add-matcher::.github/workflows/PYTHONWARNINGS-problemMatcher.json" pytest --cov -v --new-first -x --show-capture=all -rA - sh -c 'ls -l {env:COVERAGE_FILE}' sh -c 'if [ -n "{env:PYTEST_MD_REPORT_OUTPUT}" -a -n "{env:GITHUB_STEP_SUMMARY}" ];then \ - sed -i "s/tests\(.*py\)/[&](&)/" {env:PYTEST_MD_REPORT_OUTPUT}; sed "/title/,/\/style/d" \ + mkdir -p $(dirname "{env:GITHUB_STEP_SUMMARY:.git/sum.md}"); \ + sed "s/tests\(.*py\)/[&](&)/" \ {env:PYTEST_MD_REPORT_OUTPUT} >{env:GITHUB_STEP_SUMMARY:.git/sum.md};fi' [testenv] @@ -202,8 +202,6 @@ max-line-length = 129 [pyre] commands = - pyre: python3.11 --version -V # Needs py311-pyre, does not work with py310-pyre - python pyre_runner.py -pyright [pytype] From efe4efb1921ed894397e84086ac2828616cf6099 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Fri, 15 Nov 2024 12:00:00 +0100 Subject: [PATCH 2/3] Add checks to compensate code coverage Signed-off-by: Bernhard Kaindl --- tests/test_accessor.py | 2 +- tests/test_logger.py | 1 + tests/test_pci.py | 23 ++++++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/test_accessor.py b/tests/test_accessor.py index 93f5d609..9394cf79 100644 --- a/tests/test_accessor.py +++ b/tests/test_accessor.py @@ -18,7 +18,7 @@ def test_file_accessor(fs): 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() diff --git a/tests/test_logger.py b/tests/test_logger.py index af8cd5c3..a8bb9bfd 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -31,3 +31,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) diff --git a/tests/test_pci.py b/tests/test_pci.py index 1b723538..034d7433 100644 --- a/tests/test_pci.py +++ b/tests/test_pci.py @@ -31,6 +31,7 @@ class TestValid(unittest.TestCase): def test_null_with_segment(self): + assert PCI.is_valid("0000:00:00.0") is True c = PCI("0000:00:00.0") self.assertEqual(c.segment, 0) @@ -43,6 +44,7 @@ def test_null_with_segment(self): def test_null_without_segment(self): + assert PCI.is_valid("00:00.0") is True c = PCI("00:00.0") self.assertEqual(c.segment, 0) @@ -54,6 +56,7 @@ def test_null_without_segment(self): def test_valid(self): + assert PCI.is_valid("8765:43:1f.3") is True c = PCI("8765:43:1f.3") self.assertEqual(c.segment, 0x8765) @@ -61,14 +64,31 @@ def test_valid(self): self.assertEqual(c.device, 0x1f) self.assertEqual(c.function, 0x3) + def test_valid_index(self): + + assert PCI.is_valid("8765:43:1f.3[0]") is True + assert PCI.is_valid("1234:56:01.7[1]") is True + c = PCI("1234:56:01.7[1]") + + self.assertEqual(c.segment, 0x1234) + self.assertEqual(c.bus, 0x56) + self.assertEqual(c.device, 0x01) + self.assertEqual(c.function, 0x7) + self.assertEqual(c.index, 0x1) + def test_equality(self): self.assertEqual(PCI("0000:00:00.0"), PCI("00:00.0")) + assert PCI("1234:56:01.7[1]") != PCI("1234:56:01.7[2]") + assert PCI("1234:56:01.2") >= PCI("1234:56:01.2") + assert PCI("1234:56:01.1") <= PCI("1234:56:01.2") + assert PCI("1234:56:01.3") > PCI("1234:56:01.2") + assert PCI("1234:56:01.1") < PCI("1234:56:02.2") if sys.version_info >= (2, 7): def assert_videoclass_devices(ids, devs): # type: (PCIIds, PCIDevices) -> None - """Verification function for checking the otuput of PCIDevices.findByClass()""" + """Verification function for checking the output of PCIDevices.findByClass()""" video_class = ids.lookupClass('Display controller') assert video_class == ["03"] sorted_devices = sorted(devs.findByClass(video_class), @@ -76,6 +96,7 @@ def assert_videoclass_devices(ids, devs): # type: (PCIIds, PCIDevices) -> None # Assert devs.findByClass() finding 3 GPUs from tests/data/lspci-mn in our mocked PCIIds DB: assert len(sorted_devices) == 3 + assert len(devs.findByClass("03", "80")) == 2 # For each of the found devices, assert these expected values: for (video_dev, From 0c94f631a9d940814c42cea5fcb5cab3c7f00006 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Fri, 15 Nov 2024 12:00:00 +0100 Subject: [PATCH 3/3] Cover the code handing a 2nd call of accessor.finish() Signed-off-by: Bernhard Kaindl --- tests/test_accessor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_accessor.py b/tests/test_accessor.py index 9394cf79..823e97c2 100644 --- a/tests/test_accessor.py +++ b/tests/test_accessor.py @@ -35,6 +35,7 @@ def check_repo_access(self, a): self.assertFalse(a.access('no_such_file')) self.assertEqual(a.lastError, 404) a.finish() + a.finish() # Cover the code handing a 2nd call of accessor.finish() def test_filesystem_accessor_access(self): """Test FilesystemAccessor.access()"""