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

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

Besides the obvious port, I reckon that using a more obvious fake
return value for the return of `time.strftime` improves the legibility
of the test.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 a73716c6
...@@ -65,20 +65,21 @@ class DataDirTest(unittest.TestCase): ...@@ -65,20 +65,21 @@ class DataDirTest(unittest.TestCase):
unique results. unique results.
""" """
from avocado.core import data_dir from avocado.core import data_dir
flexmock(data_dir.time).should_receive('strftime').and_return("date") with mock.patch('avocado.core.data_dir.time.strftime',
logdir = os.path.join(self.mapping['base_dir'], "foor", "bar", "baz") return_value="date_would_go_here"):
path_prefix = os.path.join(logdir, "job-date-") logdir = os.path.join(self.mapping['base_dir'], "foor", "bar", "baz")
uid = "1234567890"*4 path_prefix = os.path.join(logdir, "job-date_would_go_here-")
for i in range(7, 40): uid = "1234567890"*4
for i in range(7, 40):
path = data_dir.create_job_logs_dir(logdir, uid)
self.assertEqual(path, path_prefix + uid[:i])
self.assertTrue(os.path.exists(path))
path = data_dir.create_job_logs_dir(logdir, uid) path = data_dir.create_job_logs_dir(logdir, uid)
self.assertEqual(path, path_prefix + uid[:i]) self.assertEqual(path, path_prefix + uid + ".0")
self.assertTrue(os.path.exists(path))
path = data_dir.create_job_logs_dir(logdir, uid)
self.assertEqual(path, path_prefix + uid + ".1")
self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.exists(path))
path = data_dir.create_job_logs_dir(logdir, uid)
self.assertEqual(path, path_prefix + uid + ".0")
self.assertTrue(os.path.exists(path))
path = data_dir.create_job_logs_dir(logdir, uid)
self.assertEqual(path, path_prefix + uid + ".1")
self.assertTrue(os.path.exists(path))
def test_settings_dir_alternate_dynamic(self): def test_settings_dir_alternate_dynamic(self):
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册