def runTest(self, mock_template, mock_yaml, mock_isdir, mock_isfile, mock_open):
''' Execute test '''
self.config = mock.MagicMock(spec_set={'runbook_path' : '/path/'})
mock_isfile.return_value = True
mock_isdir.return_value = True
mock_template = mock.MagicMock(**{
'render.return_value' : """
'*':
- book
'target':
- book1
- book2
"""
})
mock_yaml.return_value = {'*':['book'], 'target':['book1', 'book2']}
mock_open.return_value = mock.MagicMock(spec=file)
result = cache_runbooks(self.config, self.logger)
self.assertEqual(result.keys(), ['*', 'target'], "Expected dictionary keys not found")
self.assertTrue(mock_open.called, "open not called")
self.assertTrue(mock_yaml.called, "yaml.safe_load not called")
self.assertTrue(mock_isdir.called, "os.path.isdir not called")
self.assertEqual(mock_isfile.call_count, 4,
"mock_open.call_count {0} is not 4".format(mock_open.call_count))
test_runbooks_cache_runbooks.py 文件源码
python
阅读 15
收藏 0
点赞 0
评论 0
评论列表
文章目录