def test_take_valid_item(capsys):

    # GIVEN: The player's current location and a valid item
    adventure.PLAYER.place = 'shire'
    adventure.PLAYER.inventory = {}
    adventure.PLACES["shire"] = Place(key="shire",
                                      name="The Shire",
                                      description="Buncha hobbits.",
                                      contents=['grass'])

    adventure.ITEMS = {
        "grass":
        Item(
            key="grass",
            name="grass blades",
            description="It's grass.",
            can_take=True,
            price=-10,
        )
    }

    # WHEN: The player tries to take a valid item
    Take(['grass']).do()
    output = capsys.readouterr().out

    # THEN: The player aquires the item
    assert 'grass' in adventure.PLAYER.inventory, "The tooken item should be in the player's inventory"

    # AND: the item is removed from the place
    assert 'grass' not in adventure.PLACES[
        "shire"].contents, "the tooken item should no longer be at the place"

    # AND: the player is informed
    assert "You pick up" in output, "The player should be told they have aquired the item"
def test_look_items(capsys):

    # GIVEN: The player's current location
    adventure.PLAYER.place = 'shire'
    adventure.PLACES["shire"] = Place(key="shire",
                                      name="The Shire",
                                      description="Buncha hobbits.",
                                      contents=['grass'])

    adventure.ITEMS = {
        "grass":
        Item(
            key="grass",
            name="grass blades",
            description="It's grass.",
            price=-10,
        )
    }

    # WHEN: The player activates Look
    Look('args').do()
    output = capsys.readouterr().out

    # THEN: The player is told the list of items present in the location
    assert "grass blades" in output, "The names of the items in the current locations should print"
def test_examine_full(capsys):
    # GIVEN: The player is in a place that exists and tries to examine an item that is present,
    adventure.PLAYER.place = 'shire'
    adventure.PLACES = {
        "shire":
        Place(key="shire",
              name="The Shire",
              description="Buncha hobbits.",
              contents=['grass', 'hills'])
    }
    adventure.ITEMS = {
        "grass":
        Item(
            key="grass",
            name="grass blades",
            description="It's grass.",
            price=-10,
        )
    }

    # WHEN: The player examines that item
    Examine(['grass']).do()
    output = capsys.readouterr().out

    # THEN: The player should be told the description of the item.
    assert "It's grass." in output, \
        "A valid Examine target should print the item description."
def test_look_nearby(capsys):

    # GIVEN: The player's current location
    adventure.PLAYER.place = 'shire'
    adventure.PLACES = {
        "shire":
        Place(
            key="shire",
            name="The Shire",
            description="Buncha hobbits.",
            east="mordor",
            west="sea",
        ),
        "mordor":
        Place(
            key="mordor",
            name="Mordor",
            description="Buncha orcs.",
            west="shire",
        ),
        "sea":
        Place(
            key="sea",
            name="The Sea",
            description="Buncha water.",
            east="shire",
        )
    }

    # WHEN: The player activates Look
    Look('args').do()
    output = capsys.readouterr().out

    # THEN: The player is told the list of nearby places
    assert "Mordor" in output, "The names of the nearby locations should print"
    assert "The Sea" in output, "The names of the nearby locations should print"
def test_look_no_nearby(capsys):

    # GIVEN: The player's current location
    adventure.PLAYER.place = 'shire'
    adventure.PLACES["shire"] = Place(
        key="shire",
        name="The Shire",
        description="Buncha hobbits.",
    )

    # WHEN: The player activates Look
    Look('args').do()
    output = capsys.readouterr().out

    # THEN: The player is told the list of nearby places
    assert "To the" not in output, "If there is nothing nearby, the names of the nearby locations should not print"
def test_look_no_items(capsys):

    # GIVEN: The player's current location
    adventure.PLAYER.place = 'shire'
    adventure.PLACES["shire"] = Place(
        key="shire",
        name="The Shire",
        description="Buncha hobbits.",
    )

    # WHEN: The player activates Look
    Look('args').do()
    output = capsys.readouterr().out

    # THEN: The player is told the list of items present in the location
    assert "You see" not in output, "If there are no items in the location, you can't see anything"
def test_look_place(capsys):

    # GIVEN: The player's current location
    adventure.PLAYER.place = 'shire'
    adventure.PLACES["shire"] = Place(
        key="shire",
        name="The Shire",
        description="Buncha hobbits.",
    )

    # WHEN: The player activates Look
    Look('args').do()
    output = capsys.readouterr().out

    # THEN: The player is told the description of the current location
    assert "Buncha hobbits" in output, "The description of the current location should print"
def test_examine_missing_item(capsys):
    adventure.PLAYER.place = 'shire'
    adventure.PLACES = {
        "shire":
        Place(key="shire",
              name="The Shire",
              description="Buncha hobbits.",
              contents=['grass', 'hills'])
    }
    adventure.ITEMS = {}

    Examine(['hills']).do()
    output = capsys.readouterr().out

    assert 'Hmmm, "hills" seems to be missing from my files.' in output, \
        "An Examine target not in the the ITEMS dictionary should throw an error"
def test_examine_missing_from_place(capsys):
    # GIVEN: That the item the player wants to examine is not in the current
    #        place
    adventure.PLAYER.place = 'shire'
    adventure.PLACES = {
        "shire":
        Place(key="shire",
              name="The Shire",
              description="Buncha hobbits.",
              contents=['grass', 'hills'])
    }

    # WHEN: The player tries to examine it
    Examine(['castle']).do()
    output = capsys.readouterr().out

    # THEN: The player should be told they can't
    assert "Error: There is no castle in the shire." in output, \
        "An Examine target not in the current location should throw an error"