mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-06-13 16:00:12 +02:00
[TEST] [TEST (:D)] (elegantly?) fixes patch_clean_configuration
cases
This commit is contained in:
archey
@ -93,3 +93,7 @@ class Configuration(metaclass=Singleton):
|
|||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._close_and_restore_sys_stderr()
|
self._close_and_restore_sys_stderr()
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
"""When used as an iterator, directly yield `_config` elements"""
|
||||||
|
return iter(self._config.items())
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""`archey.test.entries` module initialization file"""
|
"""`archey.test.entries` module initialization file"""
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from functools import partial, wraps
|
from functools import wraps
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
@ -62,8 +62,9 @@ class HelperMethods:
|
|||||||
@wraps(method)
|
@wraps(method)
|
||||||
def wrapper_patch_clean_configuration(*args, **kwargs):
|
def wrapper_patch_clean_configuration(*args, **kwargs):
|
||||||
with patch('archey.entry.Configuration', autospec=True) as config_instance_mock:
|
with patch('archey.entry.Configuration', autospec=True) as config_instance_mock:
|
||||||
# Since `get` is the only "public" method, we only need to mock that.
|
# Mock "publicly" used methods.
|
||||||
config_instance_mock().get = entry_configuration.get
|
config_instance_mock().get = entry_configuration.get
|
||||||
|
config_instance_mock().__iter__ = lambda _: iter(entry_configuration.items())
|
||||||
return method(*args, **kwargs)
|
return method(*args, **kwargs)
|
||||||
|
|
||||||
return wrapper_patch_clean_configuration
|
return wrapper_patch_clean_configuration
|
||||||
@ -150,18 +151,13 @@ class TestHelperMethods(unittest.TestCase, HelperMethods):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Working tests for `patch_clean_configuration`.
|
|
||||||
# Since we don't implement all the container methods in `Configuration`,
|
|
||||||
# it seems like we can't just interpret the `_configuration` `MagicMock` as a `dict`.
|
|
||||||
# Somehow we need to compare using the `.get` method. Is that possible...?
|
|
||||||
|
|
||||||
def test_patch_clean_configuration_defaults(self):
|
def test_patch_clean_configuration_defaults(self):
|
||||||
"""Test the default configuration-setting of `patch_clean_configuration."""
|
"""Test the default configuration-setting of `patch_clean_configuration."""
|
||||||
@HelperMethods.patch_clean_configuration
|
@HelperMethods.patch_clean_configuration
|
||||||
def test(self):
|
def test(self):
|
||||||
simple_entry = TestHelperMethods._SimpleEntry()
|
simple_entry = TestHelperMethods._SimpleEntry()
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
simple_entry._configuration, # pylint: disable=protected-access
|
dict(simple_entry._configuration), # pylint: disable=protected-access
|
||||||
DEFAULT_CONFIG
|
DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -192,7 +188,7 @@ class TestHelperMethods(unittest.TestCase, HelperMethods):
|
|||||||
def test(self):
|
def test(self):
|
||||||
simple_entry = TestHelperMethods._SimpleEntry()
|
simple_entry = TestHelperMethods._SimpleEntry()
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
simple_entry._configuration, # pylint: disable=protected-access
|
dict(simple_entry._configuration), # pylint: disable=protected-access
|
||||||
{
|
{
|
||||||
'a_key': 'a_value',
|
'a_key': 'a_value',
|
||||||
'another_key': 'another_value',
|
'another_key': 'another_value',
|
||||||
|
@ -238,6 +238,14 @@ class TestConfigurationUtil(unittest.TestCase):
|
|||||||
self.assertEqual(configuration.get('ip_settings')['lan_ip_max_count'], 4)
|
self.assertEqual(configuration.get('ip_settings')['lan_ip_max_count'], 4)
|
||||||
self.assertTrue(configuration.get('temperature')['use_fahrenheit'])
|
self.assertTrue(configuration.get('temperature')['use_fahrenheit'])
|
||||||
|
|
||||||
|
def test__iter__(self):
|
||||||
|
"""Very simple method checking our `__iter__` implementation"""
|
||||||
|
configuration = Configuration()
|
||||||
|
self.assertEqual(
|
||||||
|
configuration._config, # pylint: disable=protected-access
|
||||||
|
dict(configuration)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user