Browse Source

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 <jpodivin@redhat.com>

Change-Id: I1944a5a9dbd115f49e3fe0514d82af6f98f4556f
changes/36/794836/4
Jiri Podivin 2 months ago
parent
commit
a4070345c5
  1. 41
      tripleoclient/tests/test_utils.py

41
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 ]")
Loading…
Cancel
Save