def test_mkdir_p(self, path_mocker_stopall):
# mock
mock_logger_info = path_mocker_stopall.MagicMock(name="mock_logger_info")
mock_dir_exists = path_mocker_stopall.MagicMock(name="mock_dir_exists")
mock_path = path_mocker_stopall.MagicMock(name="mock_path")
# patch
path_mocker_stopall.patch.object(scarlett_os.subprocess.logging.Logger, 'info', mock_logger_info)
path_mocker_stopall.patch.object(scarlett_os.internal.path, 'dir_exists', mock_dir_exists)
path_mocker_stopall.patch.object(scarlett_os.internal.path, 'Path', mock_path)
path = '/home/pi/dev/bossjones-github/scarlett_os/_debug'
mock_dir_exists.return_value = True
# run test
s_path.mkdir_p(path)
# assert
assert mock_logger_info.call_count == 1
mock_path.assert_called_once_with(path)
# from scarlett_os.internal.debugger import dump
mock_path().mkdir.assert_any_call(parents=True, exist_ok=True)
mock_logger_info.assert_any_call("Verify mkdir_p ran: {}".format(mock_dir_exists.return_value))
评论列表
文章目录