提交 33ea34a1 编写于 作者: C Cleber Rosa

Job: make sure a job can be created without an explicit base_logdir

One of the premises of the Job class is that it can be created without
any mandatory information set in the args parameter.  But, because of
the way we're testing it, we always pass a base_logdir.

This test is about making sure the job gets a base_logdir, and
consequently a logdir, even when a base_logdir is not set in the args.
The implementation of this test is based on the fact that there's
already a tmpdir that can be used for playing the role of a base_logdir.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 69bf621c
...@@ -4,6 +4,11 @@ import shutil ...@@ -4,6 +4,11 @@ import shutil
import tempfile import tempfile
import unittest import unittest
try:
from unittest import mock
except ImportError:
import mock
from avocado.core import data_dir from avocado.core import data_dir
from avocado.core import exceptions from avocado.core import exceptions
from avocado.core import exit_codes from avocado.core import exit_codes
...@@ -157,6 +162,15 @@ class JobTest(unittest.TestCase): ...@@ -157,6 +162,15 @@ class JobTest(unittest.TestCase):
empty_job = job.Job(args) empty_job = job.Job(args)
self.assertIsNotNone(empty_job.args.unique_job_id) self.assertIsNotNone(empty_job.args.unique_job_id)
def test_job_no_base_logdir(self):
args = argparse.Namespace()
with mock.patch('avocado.core.job.data_dir.get_logs_dir',
return_value=self.tmpdir):
empty_job = job.Job(args)
self.assertTrue(os.path.isdir(empty_job.logdir))
self.assertEqual(os.path.dirname(empty_job.logdir), self.tmpdir)
self.assertTrue(os.path.isfile(os.path.join(empty_job.logdir, 'id')))
def tearDown(self): def tearDown(self):
data_dir._tmp_tracker.unittest_refresh_dir_tracker() data_dir._tmp_tracker.unittest_refresh_dir_tracker()
shutil.rmtree(self.tmpdir) shutil.rmtree(self.tmpdir)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册