Skip to content

Commit

Permalink
Move OSError raising out of replay.dump (raise in make_sure_path_exists)
Browse files Browse the repository at this point in the history
  • Loading branch information
insspb committed Jun 9, 2022
1 parent 886cc82 commit 68cdeb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions cookiecutter/replay.py
Expand Up @@ -16,10 +16,9 @@ def get_file_name(replay_dir, template_name):
return os.path.join(replay_dir, file_name)


def dump(replay_dir, template_name, context):
def dump(replay_dir: "os.PathLike[str]", template_name: str, context: dict):
"""Write json data to file."""
if not make_sure_path_exists(replay_dir):
raise OSError(f'Unable to create replay dir at {replay_dir}')
make_sure_path_exists(replay_dir)

if not isinstance(template_name, str):
raise TypeError('Template name is required to be of type str')
Expand Down
6 changes: 4 additions & 2 deletions tests/replay/test_dump.py
Expand Up @@ -57,7 +57,9 @@ def mock_ensure_failure(mocker):
Used to mock internal function and limit test scope.
Always return expected value: False
"""
return mocker.patch('cookiecutter.replay.make_sure_path_exists', return_value=False)
return mocker.patch(
'cookiecutter.replay.make_sure_path_exists', side_effect=OSError
)


@pytest.fixture
Expand All @@ -72,7 +74,7 @@ def mock_ensure_success(mocker):

def test_ioerror_if_replay_dir_creation_fails(mock_ensure_failure, replay_test_dir):
"""Test that replay.dump raises when the replay_dir cannot be created."""
with pytest.raises(IOError):
with pytest.raises(OSError):
replay.dump(replay_test_dir, 'foo', {'cookiecutter': {'hello': 'world'}})

mock_ensure_failure.assert_called_once_with(replay_test_dir)
Expand Down

0 comments on commit 68cdeb8

Please sign in to comment.