From a4070345c5418f78bdfe8c7f3753bf27c5240f4b Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Fri, 4 Jun 2021 14:53:37 +0200 Subject: [PATCH] Minor tests covering unreached exec branches. Tests cover branches of the __init__ and __exit__ methods that were not covered by existing tests. Signed-off-by: Jiri Podivin Change-Id: I1944a5a9dbd115f49e3fe0514d82af6f98f4556f --- tripleoclient/tests/test_utils.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tripleoclient/tests/test_utils.py b/tripleoclient/tests/test_utils.py index 659d7b9b6..25ed001f4 100644 --- a/tripleoclient/tests/test_utils.py +++ b/tripleoclient/tests/test_utils.py @@ -1870,3 +1870,44 @@ class TestGeneralUtils(base.TestCommand): limit_hosts_expected = 'controller0:compute0:compute1:!compute2' limit_hosts_actual = utils.playbook_limit_parse(limit_nodes) self.assertEqual(limit_hosts_actual, limit_hosts_expected) + + +class TestTempDirs(base.TestCase): + + @mock.patch('tripleoclient.utils.tempfile.mkdtemp', + autospec=True, + return_value='foo') + @mock.patch('tripleoclient.utils.Pushd', autospec=True) + def test_init_dirpath(self, mock_pushd, mock_mkdtemp): + + utils.TempDirs(dir_path='bar') + + mock_pushd.assert_called_once_with(directory='foo') + mock_mkdtemp.assert_called_once_with( + dir='bar', + prefix='tripleo') + + @mock.patch('tripleoclient.utils.tempfile.mkdtemp', + autospec=True, + return_value='foo') + @mock.patch('tripleoclient.utils.Pushd', autospec=True,) + def test_init_no_prefix(self, mock_pushd, mock_mkdtemp): + + utils.TempDirs(dir_prefix=None) + + mock_pushd.assert_called_once_with(directory='foo') + mock_mkdtemp.assert_called_once_with() + + @mock.patch('tripleoclient.utils.LOG.warning', autospec=True,) + @mock.patch('tripleoclient.utils.tempfile.mkdtemp', + autospec=True, + return_value='foo') + @mock.patch('tripleoclient.utils.Pushd', autospec=True) + def test_exit_warning(self, mock_pushd, mock_mkdtemp, mock_log): + + temp_dirs = utils.TempDirs(cleanup=False, chdir=False) + + temp_dirs.__exit__() + + mock_log.assert_called_once_with( + "Not cleaning temporary directory [ foo ]")