-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some reserve-mb adjusts #35
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from unittest.case import TestCase | ||
from unittest.mock import patch | ||
from unittest.mock import Mock | ||
|
||
from com_redhat_kdump import common | ||
from .mock import MockBuiltinRead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MockBuiltinRead is no longer used. |
||
from com_redhat_kdump.constants import KDUMP | ||
from com_redhat_kdump.service.kdump import KdumpService | ||
from com_redhat_kdump.service.kdump_interface import KdumpInterface | ||
|
@@ -48,7 +50,15 @@ def test_fadump_enabled(self): | |
self._check_properties_changed("FadumpEnabled", True) | ||
self.assertEqual(self._interface.FadumpEnabled, True) | ||
|
||
def test_reserved_memory(self): | ||
@patch("com_redhat_kdump.service.kdump.KdumpService.check_reserved_memory", return_value="256") | ||
def test_reserved_memory(self, _mock_read): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems there is no need to change |
||
self._interface.ReservedMemory = "256" | ||
self._check_properties_changed("ReservedMemory", "256") | ||
self.assertEqual(self._interface.ReservedMemory, "256") | ||
|
||
@patch("com_redhat_kdump.common.getMemoryBounds", return_value=(500, 800, 1)) | ||
def test_check_reserved_memory(self, _mock_read): | ||
self._service._lower , self._service._upper, self._service._step = common.getMemoryBounds() | ||
self.assertEqual(self._service.check_reserved_memory("900"), "800") | ||
self.assertEqual(self._service.check_reserved_memory("400"), "500") | ||
self.assertEqual(self._service.check_reserved_memory("600"), "600") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this test, you should patch @patch("com_redhat_kdump.service.kdump.getMemoryBounds", return_value = (500, 800, 1))
def test_check_reserved_memory(self, mocker):
service1 = KdumpService()
for memory, reserved in [("900", "800"), ("400", "500"), ("600", "600")]:
self.assertEqual(service1.check_reserved_memory(memory), reserved) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from textwrap import dedent | ||
from unittest.case import TestCase | ||
from unittest.mock import patch | ||
from com_redhat_kdump import common | ||
from .mock import MockBuiltinRead | ||
from com_redhat_kdump.service.kdump import KdumpService | ||
|
||
|
||
|
@@ -68,7 +70,10 @@ def test_ks_disable(self): | |
%end | ||
""") | ||
|
||
def test_ks_reserve_mb(self): | ||
@patch("com_redhat_kdump.common.getMemoryBounds", return_value=(160, 800, 1)) | ||
def test_ks_reserve_mb(self, _mock_read): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this test, I would suggest to patch for diff --git a/test/unit_tests/test_kickstart.py b/test/unit_tests/test_kickstart.py
index 4f063de..66817ac 100644
--- a/test/unit_tests/test_kickstart.py
+++ b/test/unit_tests/test_kickstart.py
@@ -2,13 +2,13 @@ from textwrap import dedent
from unittest.case import TestCase
from unittest.mock import patch
from com_redhat_kdump import common
-from .mock import MockBuiltinRead
from com_redhat_kdump.service.kdump import KdumpService
class KdumpKickstartTestCase(TestCase):
- def setUp(self):
+ @patch("com_redhat_kdump.service.kdump.getMemoryBounds", return_value=(160, 800, 1))
+ def setUp(self, mocker):
# Show unlimited diff.
self.maxDiff = None
@@ -70,10 +70,7 @@ class KdumpKickstartTestCase(TestCase):
%end
""")
- @patch("com_redhat_kdump.common.getMemoryBounds", return_value=(160, 800, 1))
- def test_ks_reserve_mb(self, _mock_read):
- self._service._lower , self._service._upper, self._service._step = common.getMemoryBounds()
- self.assertEqual((self._service._lower , self._service._upper), (160, 800))
+ def test_ks_reserve_mb(self):
self._check_ks_input(""" |
||
self._service._lower , self._service._upper, self._service._step = common.getMemoryBounds() | ||
self.assertEqual((self._service._lower , self._service._upper), (160, 800)) | ||
self._check_ks_input(""" | ||
%addon com_redhat_kdump --enable --reserve-mb=256 | ||
%end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reserved_memory
is architecture-independent so there is no need to create fixtures for each architecture. You shall be able to simplify the tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/rhinstaller/kdump-anaconda-addon/blob/master/com_redhat_kdump/common.py#L71-L82, it make diffrent architecture lowerBound , so to test diffrent architecture is need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for correcting me! But I think my point still stands. Although different architectures have different lowerBound and minUsable values, you only need to test one arch if choose a proper testing strategy. If you partition ReservedMemory by a) ReservedMemory <= lowerBound b) b) lowerBound < ReservedMemory < upperBound ReservedMemory >= upperBound, you only need to mock one arch.