From 33ea34a12feb1fca4dd0489e15b03ecbb2633daa Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Thu, 21 Sep 2017 12:01:18 -0400 Subject: [PATCH] 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: Cleber Rosa --- selftests/unit/test_job.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/selftests/unit/test_job.py b/selftests/unit/test_job.py index a45d2861..1fad48a0 100644 --- a/selftests/unit/test_job.py +++ b/selftests/unit/test_job.py @@ -4,6 +4,11 @@ import shutil import tempfile import unittest +try: + from unittest import mock +except ImportError: + import mock + from avocado.core import data_dir from avocado.core import exceptions from avocado.core import exit_codes @@ -157,6 +162,15 @@ class JobTest(unittest.TestCase): empty_job = job.Job(args) 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): data_dir._tmp_tracker.unittest_refresh_dir_tracker() shutil.rmtree(self.tmpdir) -- GitLab