Exemple #1
0
def test_get_points(game):
    """prints points"""
    assert "you have:" in repl._evaluate("points", game)[0]
    game = types.Game()
    game.points = 0
    result = game._get_points()
    assert "Booooooo! you suck.\nYou have 0 points." in result
Exemple #2
0
def test_fight_prompt(run, mocker):
    """Tests fight prompt
    """
    mocked_fight_prompt = mocker.patch('dork.cli.fight')

    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    run(dork.cli.fight_prompt, game, input_values=['punch'])
    assert mocked_fight_prompt.call_count == 1
    mocked_fight_prompt.call_count = 0
    run(dork.cli.fight_prompt, game, input_values=['swing'])
    assert mocked_fight_prompt.call_count == 1
    game.player.inventory = ['sword']
    mocked_fight_prompt.call_count = 0
    run(dork.cli.fight_prompt, game, input_values=['swing', 'sword'])
    assert mocked_fight_prompt.call_count == 1
    game.player.inventory = ['sword']
    mocked_fight_prompt.call_count = 0
    run(dork.cli.fight_prompt, game, input_values=['swing', 'skull', 'sword'])
    assert mocked_fight_prompt.call_count == 1
    mocked_fight_prompt.call_count = 0
    run(dork.cli.fight_prompt, game, input_values=['reach', 'punch'])
    assert mocked_fight_prompt.call_count == 1
Exemple #3
0
def test_end_game(run):
    """Test end game function
    """
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    out, _ = run(dork.cli.end_game, game)
    assert "Thank you" in out
Exemple #4
0
def test_points():
    """testing _points for: add, remove, and no points"""
    game = types.Game()
    result = game._points('_get_points')
    assert result == 10, "points where not added"
    result = game._points('_take')
    assert result == 11, "points where not added"
    result = game._points('_repl_error')
    assert result == 0, "points where not added"
Exemple #5
0
def test_last_room(run):
    """Tests last room
    """
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    game.player.position['location'] = 'entrance'
    run(dork.cli.last_room, game)
    assert True
Exemple #6
0
def test_save_game(run, mocker):
    """Tests save game
    """
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    mocked = mocker.patch('dork.saveload.save')
    run(dork.cli.save_game, game)
    assert mocked.call_count == 1
Exemple #7
0
def game_state():
    """
    First, data is loaded using load() and then returned as a game sate.
    This function starts by assigning to data using load(), and then
    immediately returns the game state.

    Returns:
        types.Game(data): A dictionary containing the game state.
    """
    data = load()
    return types.Game(data)
Exemple #8
0
def test_player_move(run, mocker):
    """This will test the player_move function
    """
    mocked_lock_check = mocker.patch('dork.cli.lock_check')
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    user_action = ["move north"]
    run(dork.cli.player_move, game, user_action)
    assert mocked_lock_check.call_count == 0
Exemple #9
0
def test_room_examine(run):
    """Tests room examine
    """
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    out, _ = run(dork.cli.room_examine, game)
    assert 'contains' in out
    game.rooms['cell'].door['item'] = []
    out, _ = run(dork.cli.room_examine, game)
    assert 'useful' in out
Exemple #10
0
def test_removeitem(run, mocker):
    """Tests the remove_item function.
    """
    mocked_remove = mocker.patch('dork.cli.remove_item')
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())

    # remove_item uses game as an arg
    game = types.Game(data)
    game.player.inventory = ['key']
    run(dork.cli.remove_item, game)
    assert mocked_remove.call_count == 1
Exemple #11
0
def test_fight(run):
    """This will test the fight function
    """
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    game.player.position['location'] = 'Jail hallway'
    damage = 2
    out, _ = run(dork.cli.fight, game, damage)
    assert 'killed' in out
    game.player.position['location'] = 'Jail hallway'
    damage = 0
    out, _ = run(dork.cli.fight, game, damage)
    assert 'died' in out
Exemple #12
0
def test_unlockroom(run, mocker):
    """Tests the unlock_room function.
    """
    mocked_unlock = mocker.patch('dork.cli.unlock_room')
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())

    # unlock_room uses game, user_action, and direction (in order)
    game = types.Game(data)
    game.player.inventory = ['key']
    user_action = ['use key']
    direction = 'Jail hallway'
    run(dork.cli.unlock_room, game, user_action, direction)
    assert mocked_unlock.call_count == 1
Exemple #13
0
def testsave(run):
    """Save data should actually work no matter what
    type of data is used.
    """
    assert isinstance(dork.saveload.save, FunctionType)
    try:
        with open('./dork/yaml/default.yml') as file:
            # Should not call load directly
            data = yaml.safe_load(file.read())
        game = types.Game(data)
        run(dork.saveload.save, game, input_values=['roomdatatest'])
        run(dork.saveload.save, game, input_values=['default', 'roomdatatest'])
        run(dork.saveload.save, game, input_values=['\0', 'roomdatatest'])
    except:  # noqa: E722
        raise AssertionError("cannot run 'dork' command")
Exemple #14
0
def test_player_use(run, mocker):
    """This will test the player_use function
    """
    mocked = mocker.patch('dork.cli.unlock_room')
    mocker.patch('dork.cli.next_room')
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    user_action = ['use', 'key']
    game.player.inventory = ['key']
    run(dork.cli.player_use, game, user_action)
    assert mocked.call_count == 1
    user_action = ["use", "sword"]
    out, _ = run(dork.cli.player_use, game, user_action)
    assert 'You do not have that item.' in out
Exemple #15
0
def test_player_examine(run, mocker):
    """Tests player examine
    """
    mocked = mocker.patch('dork.cli.room_examine')
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    user_action = 'room'
    run(dork.cli.player_examine, game, user_action)
    assert mocked.call_count == 1
    user_action = ['key']
    game.player.inventory = ['key']
    out, _ = run(dork.cli.player_examine, game, user_action)
    assert 'key' in out
    user_action = ['car']
    out, _ = run(dork.cli.player_examine, game, user_action)
    assert 'unknown' in out
Exemple #16
0
def test_fight_check(run, mocker):
    """This tests the fight check
    """
    mocked_fight_prompt = mocker.patch('dork.cli.fight_prompt')

    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    # jail hallway has a fight
    game.player.position['location'] = 'Jail hallway'
    game.rooms['Jail hallway'].fight['fight'] = True
    run(dork.cli.fight_check, game)
    assert mocked_fight_prompt.call_count == 1
    game.rooms['Jail hallway'].fight['fight'] = False
    mocked_fight_prompt.call_count = 0
    run(dork.cli.fight_check, game)
    assert mocked_fight_prompt.call_count == 0
Exemple #17
0
def test_lock_check(run, mocker):
    """Tests lock check
    """
    mocked = mocker.patch('dork.cli.movement_handler')
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    game.player.position['location'] = 'cell'
    direction = 'Jail hallway'
    run(dork.cli.lock_check, game, direction)
    assert mocked.call_count == 0
    mocked.call_count = 0
    game.player.position['location'] = 'Stairwell'
    direction = 'Jail Tower'
    run(dork.cli.lock_check, game, direction)
    assert mocked.call_count == 1
    mocked.call_count = 0
    game.player.position['location'] = 'cell'
    direction = ''
    out, _ = run(dork.cli.lock_check, game, direction)
    assert 'wall' in out
Exemple #18
0
def test_prompt(run, mocker):
    """This will test the prompt function
    """
    with open('./dork/yaml/default.yml') as file:
        # Should not call load directly
        data = yaml.safe_load(file.read())
    game = types.Game(data)
    player_actions = {
        'move': 'dork.cli.player_move',
        'examine': 'dork.cli.player_examine',
        'pick': 'dork.cli.player_take',
        'use': 'dork.cli.player_use',
        'drop': 'dork.cli.drop_item',
        'user': '******',
        'help': 'dork.cli.help_menu',
        'save': 'dork.cli.save_game',
        'quit': 'dork.cli.end_game'
    }
    for name, fstr in player_actions.items():
        mocked = mocker.patch(fstr)
        run(dork.cli.prompt, game, input_values=[name])
    assert mocked.call_count == 1
    out, _ = run(dork.cli.prompt, game, input_values=['run north', 'quit'])
    assert "Enter a valid command. " in out
Exemple #19
0
def game_state():
    """Creates and stores the game state.
    """
    data = load()
    return types.Game(data)