# -*- coding: utf-8 -*-

"""
test_load
-----------
"""

import json
import os
import pytest

from cookiecutter import replay


@pytest.fixture
def template_name():
    """Fixture to return a valid template_name."""
    return 'cookiedozer_load'


@pytest.fixture
def replay_file(replay_test_dir, template_name):
    """Fixture to return a actual file name of the dump."""
    file_name = '{}.json'.format(template_name)
    return os.path.join(replay_test_dir, file_name)


def test_type_error_if_no_template_name():
    """Test that replay.load raises if the tempate_name is not a valid str."""
    with pytest.raises(TypeError):
        replay.load(None)


def test_value_error_if_key_missing_in_context(mocker):
    """Test that replay.load raises if the loaded context does not contain
    'cookiecutter'.
    """
    with pytest.raises(ValueError):
        replay.load('invalid_replay')


def test_io_error_if_no_replay_file(mocker, mock_user_config):
    """Test that replay.load raises if it cannot find a replay file."""
    with pytest.raises(IOError):
        replay.load('no_replay')


def test_run_json_load(mocker, mock_user_config, template_name,
                       context, replay_test_dir, replay_file):
    """Test that replay.load runs json.load under the hood and that the context
    is correctly loaded from the file in replay_dir.
    """
    spy_get_replay_file = mocker.spy(replay, 'get_file_name')

    mock_json_load = mocker.patch('json.load', side_effect=json.load)

    loaded_context = replay.load(template_name)

    assert mock_user_config.call_count == 1
    spy_get_replay_file.assert_called_once_with(replay_test_dir, template_name)

    assert mock_json_load.call_count == 1
    (infile_handler,), kwargs = mock_json_load.call_args
    assert infile_handler.name == replay_file
    assert loaded_context == context

@@ -499,32 +499,47 @@
 o_template_name(
+replay_test_dir
 ):%0A    %22%22%22Test t
@@ -659,16 +659,33 @@
 ay.load(
+replay_test_dir, 
 None)%0A%0A%0A
@@ -737,16 +737,33 @@
 t(mocker
+, replay_test_dir
 ):%0A    %22
@@ -916,16 +916,33 @@
 ay.load(
+replay_test_dir, 
 'invalid
@@ -997,32 +997,31 @@
 mocker, 
-mock_user_config
+replay_test_dir
 ):%0A    %22
@@ -1140,16 +1140,33 @@
 ay.load(
+replay_test_dir, 
 'no_repl
@@ -1607,16 +1607,33 @@
 ay.load(
+replay_test_dir, 
 template
@@ -1647,24 +1647,28 @@
 %0A    assert 
+not 
 mock_user_co
@@ -1672,35 +1672,26 @@
 _config.call
-_count == 1
+ed
 %0A    spy_get

Update replay/test_load.py to pass in replay dir