提交 a73716c6 编写于 作者: C Cleber Rosa

selftests/unit/test_datadir.py: port test_datadir_from_config to mock

The context manager feature of mock.patch replaces a lot of the code
that restores the original state.  Besides that, one explicit assert
was added to make sure that the non-patched state is what we expect.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 2a4e9a85
......@@ -3,6 +3,10 @@ import os
import shutil
import tempfile
try:
from unittest import mock
except ImportError:
import mock
from flexmock import flexmock
from six.moves import xrange as range
......@@ -43,21 +47,17 @@ class DataDirTest(unittest.TestCase):
"""
When avocado.conf is present, honor the values coming from it.
"""
stg_orig = settings.settings
stg = settings.Settings(self.config_file_path)
try:
# Trick the module to think we're on a system wide install
stg.intree = False
flexmock(settings, settings=stg)
with mock.patch('avocado.core.data_dir.settings.settings', stg):
from avocado.core import data_dir
flexmock(data_dir.settings, settings=stg)
self.assertFalse(data_dir.settings.settings.intree)
for key in self.mapping.keys():
data_dir_func = getattr(data_dir, 'get_%s' % key)
self.assertEqual(data_dir_func(), stg.get_value('datadir.paths', key))
finally:
flexmock(settings, settings=stg_orig)
del data_dir
# make sure that without the patch, we have a different value here
self.assertTrue(data_dir.settings.settings.intree)
def test_unique_log_dir(self):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册