提交 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):
unique results.
"""
from avocado.core import data_dir
flexmock(data_dir.time).should_receive('strftime').and_return("date")
logdir = os.path.join(self.mapping['base_dir'], "foor", "bar", "baz")
path_prefix = os.path.join(logdir, "job-date-")
uid = "1234567890"*4
for i in range(7, 40):
with mock.patch('avocado.core.data_dir.time.strftime',
return_value="date_would_go_here"):
logdir = os.path.join(self.mapping['base_dir'], "foor", "bar", "baz")
path_prefix = os.path.join(logdir, "job-date_would_go_here-")
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)
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))
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):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册