kdump-anaconda-addon/backport-use-pytest-to-run-the-unit-tests.patch
2022-11-08 11:30:42 +00:00

216 lines
8.4 KiB
Diff

From fe60eaf2d6e32ed7009f6d9cfecc1f761ec77560 Mon Sep 17 00:00:00 2001
From: Vendula Poncova <vponcova@redhat.com>
Date: Thu, 23 Sep 2021 14:43:26 +0200
Subject: [PATCH] Use pytest to run the unit tests
The nose library is no longer maintained and it doesn't work with Python 3.9.
---
Makefile | 2 +-
test/Dockerfile | 2 +-
test/{unittests => unit_tests}/test_common.py | 6 +++---
test/{unittests => unit_tests}/test_installation.py | 10 +++++-----
test/{unittests => unit_tests}/test_interface.py | 6 +++---
test/{unittests => unit_tests}/test_kickstart.py | 12 ++++++------
6 files changed, 19 insertions(+), 19 deletions(-)
rename test/{unittests => unit_tests}/test_common.py (92%)
rename test/{unittests => unit_tests}/test_installation.py (89%)
rename test/{unittests => unit_tests}/test_interface.py (94%)
rename test/{unittests => unit_tests}/test_kickstart.py (94%)
diff --git a/Makefile b/Makefile
index 7db520c..f095243 100644
--- a/Makefile
+++ b/Makefile
@@ -95,7 +95,7 @@ runpylint:
unittest:
@echo "***Running unittests checks***"
- PYTHONPATH=. python3 -m nose --processes=-1 -vw test/unittests
+ PYTHONPATH=. pytest -vv test/unit_tests
version.sh:
@echo "KDUMP_ADDON_VERSION=$(VERSION)" > version.sh
diff --git a/test/Dockerfile b/test/Dockerfile
index c09ad78..925a720 100644
--- a/test/Dockerfile
+++ b/test/Dockerfile
@@ -9,7 +9,7 @@ RUN dnf update -y \
RUN pip install \
pylint \
- nose
+ pytest
RUN mkdir /kdump-anaconda-addon
WORKDIR /kdump-anaconda-addon
diff --git a/test/unittests/test_common.py b/test/unit_tests/test_common.py
similarity index 92%
rename from test/unittests/test_common.py
rename to test/unit_tests/test_common.py
index e8c532e..16c973c 100644
--- a/test/unittests/test_common.py
+++ b/test/unit_tests/test_common.py
@@ -48,15 +48,15 @@ class KdumpCommonTestCase(TestCase):
@patch("builtins.open", MockFileRead(X86_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="x86_64")
- def memory_bound_test_x86(self, _mock_read):
+ def test_memory_bound_x86(self, _mock_read):
self.assertEqual((128, 4 * 1024 - 256, 1), common.getMemoryBounds())
@patch("builtins.open", MockFileRead(AARCH64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
- def memory_bound_test_aarch64(self, _mock_read):
+ def test_memory_bound_aarch64(self, _mock_read):
self.assertEqual((128, 64 * 1024 - 256, 1), common.getMemoryBounds())
@patch("builtins.open", MockFileRead(PPC64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="ppc64")
- def memory_bound_test_ppc64(self, _mock_read):
+ def test_memory_bound_ppc64(self, _mock_read):
self.assertEqual((256, 64 * 1024 - 1024, 1), common.getMemoryBounds())
diff --git a/test/unittests/test_installation.py b/test/unit_tests/test_installation.py
similarity index 89%
rename from test/unittests/test_installation.py
rename to test/unit_tests/test_installation.py
index 9c52bfe..b2deb4b 100644
--- a/test/unittests/test_installation.py
+++ b/test/unit_tests/test_installation.py
@@ -7,7 +7,7 @@ from com_redhat_kdump.service.installation import KdumpConfigurationTask, KdumpI
class KdumpInstallationTestCase(TestCase):
@patch("com_redhat_kdump.service.installation.STORAGE")
- def configuration_kdump_disabled_test(self, mock_storage):
+ def test_configuration_kdump_disabled(self, mock_storage):
bootloader_proxy = mock_storage.get_proxy.return_value
bootloader_proxy.ExtraArguments = [
"a=1", "b=2", "c=3", "crashkernel=128M"
@@ -25,7 +25,7 @@ class KdumpInstallationTestCase(TestCase):
])
@patch("com_redhat_kdump.service.installation.STORAGE")
- def configuration_kdump_enabled_test(self, mock_storage):
+ def test_configuration_kdump_enabled(self, mock_storage):
bootloader_proxy = mock_storage.get_proxy.return_value
bootloader_proxy.ExtraArguments = [
"a=1", "b=2", "c=3", "crashkernel=128M"
@@ -44,7 +44,7 @@ class KdumpInstallationTestCase(TestCase):
@patch("com_redhat_kdump.service.installation.os")
@patch("com_redhat_kdump.service.installation.STORAGE")
- def configuration_fadump_enabled_test(self, mock_storage, mock_os):
+ def test_configuration_fadump_enabled(self, mock_storage, mock_os):
bootloader_proxy = mock_storage.get_proxy.return_value
bootloader_proxy.ExtraArguments = [
"a=1", "b=2", "c=3", "crashkernel=128M"
@@ -63,7 +63,7 @@ class KdumpInstallationTestCase(TestCase):
])
@patch("com_redhat_kdump.service.installation.util")
- def installation_kdump_disabled_test(self, mock_util):
+ def test_installation_kdump_disabled(self, mock_util):
task = KdumpInstallationTask(
sysroot="/mnt/sysroot",
kdump_enabled=False
@@ -72,7 +72,7 @@ class KdumpInstallationTestCase(TestCase):
mock_util.execWithRedirect.assert_not_called()
@patch("com_redhat_kdump.service.installation.util")
- def installation_kdump_enabled_test(self, mock_util):
+ def test_installation_kdump_enabled(self, mock_util):
task = KdumpInstallationTask(
sysroot="/mnt/sysroot",
kdump_enabled=True
diff --git a/test/unittests/test_interface.py b/test/unit_tests/test_interface.py
similarity index 94%
rename from test/unittests/test_interface.py
rename to test/unit_tests/test_interface.py
index fbf36fa..dbac003 100644
--- a/test/unittests/test_interface.py
+++ b/test/unit_tests/test_interface.py
@@ -38,17 +38,17 @@ class KdumpInterfaceTestCase(TestCase):
[]
)
- def kdump_enabled_test(self):
+ def test_kdump_enabled(self):
self._interface.KdumpEnabled = True
self._check_properties_changed("KdumpEnabled", True)
self.assertEqual(self._interface.KdumpEnabled, True)
- def fadump_enabled_test(self):
+ def test_fadump_enabled(self):
self._interface.FadumpEnabled = True
self._check_properties_changed("FadumpEnabled", True)
self.assertEqual(self._interface.FadumpEnabled, True)
- def reserved_memory_test(self):
+ def test_reserved_memory(self):
self._interface.ReservedMemory = "256"
self._check_properties_changed("ReservedMemory", "256")
self.assertEqual(self._interface.ReservedMemory, "256")
diff --git a/test/unittests/test_kickstart.py b/test/unit_tests/test_kickstart.py
similarity index 94%
rename from test/unittests/test_kickstart.py
rename to test/unit_tests/test_kickstart.py
index 3637264..0dd78ed 100644
--- a/test/unittests/test_kickstart.py
+++ b/test/unit_tests/test_kickstart.py
@@ -25,7 +25,7 @@ class KdumpKickstartTestCase(TestCase):
output = self._service.generate_kickstart()
self.assertEqual(output.strip(), dedent(ks_out).strip())
- def ks_default_test(self):
+ def test_ks_default(self):
self.assertEqual(self._service.kdump_enabled, False)
self.assertEqual(self._service.fadump_enabled, False)
self.assertEqual(self._service.reserved_memory, "128")
@@ -36,7 +36,7 @@ class KdumpKickstartTestCase(TestCase):
%end
""")
- def ks_enable_test(self):
+ def test_ks_enable(self):
self._check_ks_input("""
%addon com_redhat_kdump --enable
%end
@@ -52,7 +52,7 @@ class KdumpKickstartTestCase(TestCase):
%end
""")
- def ks_disable_test(self):
+ def test_ks_disable(self):
self._check_ks_input("""
%addon com_redhat_kdump --disable
%end
@@ -68,7 +68,7 @@ class KdumpKickstartTestCase(TestCase):
%end
""")
- def ks_reserve_mb_test(self):
+ def test_ks_reserve_mb(self):
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=256
%end
@@ -84,7 +84,7 @@ class KdumpKickstartTestCase(TestCase):
%end
""")
- def ks_reserve_mb_invalid_test(self):
+ def test_ks_reserve_mb_invalid(self):
ks_in = """
%addon com_redhat_kdump --reserve-mb=
%end
@@ -99,7 +99,7 @@ class KdumpKickstartTestCase(TestCase):
ks_err = "Invalid value 'invalid' for --reserve-mb"
self._check_ks_input(ks_in, [ks_err])
- def ks_enablefadump_test(self):
+ def test_ks_enablefadump(self):
self._check_ks_input("""
%addon com_redhat_kdump --disable --enablefadump
%end
--
2.33.0