Beispiel #1
0
    def setUp(self):

        self.inventory = Inventory(
            0, 0x1,
            Labels("Main Inventory", "in the main inventory",
                   ", where items live usually."), 3)
        self.book = Item(1105, 0x2,
                         Labels("book", "a book", "a book of fairytales"), 2,
                         "The Pied Piper", {})
        self.lamp = Item(1043, 0x10101A,
                         Labels("lamp", "a lamp", "a small lamp"), 2, None, {})
        self.coin = Item(1000, 0x2, Labels("coin", "a coin", "a silver coin"),
                         1, None, {})
        self.medal = Item(1001, 0x2, Labels("medal", "a medal",
                                            "a gold medal"), 1, None, {})
        self.suit = UsableItem(1046, 0x402,
                               Labels("suit", "a suit", "a space-suit"), 2,
                               None, {}, Item.ATTRIBUTE_GIVES_AIR)
        self.water = Item(1109, 0x22902,
                          Labels("water", "some water", "some water"), 1, None,
                          {})
        self.basket = ContainerItem(
            1107, 0x3, Labels("basket", "a basket", "a large basket"), 6, None,
            {})
        self.non_essential_drop_location = Location(
            12, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
        self.essential_drop_location = Location(
            9, 0x0, Labels("Cave", "in a cave", ". It is dark"))
Beispiel #2
0
	def setup_items(self):
		self.book = self.book = Item(1043, 0x2, Labels("book", "a book", "a book of fairytales"), 2, "The Pied Piper", {})
		self.bread = Item(1109, 0x2, Labels("bread", "some bread", "a loaf of bread"), 2, None, {})
		self.items_by_id = {
			1043 : self.book,
			1044 : self.bread,
		}
Beispiel #3
0
	def setUp(self):
		extended_descriptions = [". The walls are dark and cold", ". The walls are glowing"]
		self.lighthouse_location = Location(12, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
		self.mine_location = Location(11, 0x0, Labels("Mines", "in the mines", ". There are dark passages everywhere", extended_descriptions))
		self.lower_mine_location = Location(10, 0x200, Labels("Lower mines", "in the lower mines", ". This is the bottom of the mines", extended_descriptions))

		self.book = Item(1105, 2, Labels("book", "a book", "a book of fairytales"), 2, "The Pied Piper", {})
		self.desk = Item(1000, 0x20000, Labels("desk", "a desk", "a large mahogany desk"), 6, None, {})
		self.obstruction = Item(1000, 0x4, Labels("obstruction", "an obstruction", "an obstruction blocking you"), 8, None, {})
		self.basket = ContainerItem(1107, 0x3, Labels("basket", "a basket", "a large basket"), 6, None, {})
		self.box = ContainerItem(1108, 0x3, Labels("box", "a box", "a small box"), 3, None, {})
	def setup_items(self):
		self.book = Item(1105, 0x2, Labels("book", "a book", "a book of fairytales"), 2, "The Pied Piper", {})
		self.box = ContainerItem(1106, 0x3, Labels("box", "a box", "a small box"), 3, None, {})
		lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off", "on")
		self.lamp = SwitchableItem(1043, 0x101A, Labels("lamp", "a lamp", "a small lamp"), 2, None, {}, lamp_switching_info)
		self.salt = Item(1110, 0x102, Labels("salt", "some salt", "some salt"), 1, None, {})

		self.data.get_item_list_by_name.side_effect = lambda x: {
			"book" : [self.book],
			"box" : [self.box],
			"lamp" : [self.lamp],
			"salt" : [self.salt],
		}.get(x)
Beispiel #5
0
 def __init__(self,
              name,
              abbreviation,
              targetNever=False,
              targetOptional=False,
              targetInventory=True,
              targetInRoom=True):
     Item.__init__(self, name, abbreviation)
     self.targetNever = targetNever
     self.targetOptional = targetOptional
     self.targetInventory = targetInventory
     self.targetInRoom = targetInRoom
     self.responses = ()
    def test_validate_item_liquid_container_not_liquid(self):
        water = Item(1111, 0x22902, Labels("water", "some water",
                                           "some water"), 1, None, {})
        water.add_container(self.basket)
        self.items_by_id[1111] = water

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is a liquid, but has container {2} \"{3}\", which is not a liquid container.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "water", 1107, "basket"), validation_line.args)
    def test_validate_item_liquid_non_copyable_container_location(self):
        water = Item(1111, 0x2102, Labels("water", "some water", "some water"),
                     1, None, {})
        water.add_container(self.lighthouse_location)
        self.items_by_id[1111] = water

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is a liquid, and has location container {2} \"{3}\". Liquids may only be contained at locations if they are copyable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "water", 12, "Lighthouse"),
                         validation_line.args)
 def setup_items(self):
     self.bean = Item(1003, 0x2, Labels("bean", "a bean", "a magic bean"),
                      2, None, {})
     self.bottle = ContainerItem(
         1108, 0x203, Labels("bottle", "a bottle", "a small bottle"), 3,
         None, {})
     lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off",
                                      "on")
     self.lamp = SwitchableItem(1043, 0x101A,
                                Labels("lamp", "a lamp", "a small lamp"), 2,
                                None, {}, lamp_switching_info)
     self.potion = Item(
         1058, 0x800, Labels("potion", "some potion",
                             "some magical potion"), 1, None, {})
     self.wand = Item(1203, 0x2, Labels("wand", "a wand", "a magical wand"),
                      2, None, {})
Beispiel #9
0
    def init_item(
        self,
        item_id,
        attributes,
        labels,
        size,
        writing,
        switched_element_id,
        switched_element_ids,
        switch_info,
        attribute_when_used,
        list_templates,
    ):

        if bool(attributes & Item.ATTRIBUTE_SENTIENT):
            item = SentientItem(item_id=item_id,
                                attributes=attributes,
                                labels=labels,
                                size=size,
                                writing=writing,
                                list_templates=list_templates)

        elif bool(attributes & Item.ATTRIBUTE_CONTAINER):
            item = ContainerItem(
                item_id=item_id,
                attributes=attributes,
                labels=labels,
                size=size,
                writing=writing,
                list_templates=list_templates,
            )

        elif switch_info:
            item = SwitchableItem(item_id=item_id,
                                  attributes=attributes,
                                  labels=labels,
                                  size=size,
                                  writing=writing,
                                  list_templates=list_templates,
                                  switch_info=switch_info)
            switched_element_ids[item] = switched_element_id

        elif self.item_is_usable(attributes):
            item = UsableItem(item_id=item_id,
                              attributes=attributes,
                              labels=labels,
                              size=size,
                              writing=writing,
                              list_templates=list_templates,
                              attribute_activated=attribute_when_used)

        else:
            item = Item(item_id=item_id,
                        attributes=attributes,
                        labels=labels,
                        size=size,
                        writing=writing,
                        list_templates=list_templates)

        return item
Beispiel #10
0
    def test_run_item_args(self):
        resolver_functions = [
            self.arg_function_non_movement, self.vision_function,
            self.handler_function
        ]
        command_non_movement = Command(1, 0x9, 0x0, resolver_functions, [""],
                                       {})
        book = Item(1105, 2, Labels("book", "a book", "a book of fairytales"),
                    2, "The Pied Piper", {})

        result = self.runner.run(command_non_movement, None, [book])

        self.assertEqual("Action \"book\" successful.", result)
Beispiel #11
0
    def setUp(self):
        self.library_location = Location(
            80, 0x1,
            Labels("Library", "in the Library", ", a tall, bright room"))
        self.lighthouse_location = Location(
            81, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
        self.box = ContainerItem(1108, 0x3,
                                 Labels("box", "a box", "a small box"), 3,
                                 None, {})
        self.ash = Item(1109, 0x2, Labels("ash", "some ash", "some black ash"),
                        1, None, {})
        self.candle = Item(1110, 0x2,
                           Labels("candle", "a candle", "a small candle"), 2,
                           None, {})
        self.kindling = Item(
            1111, 0x2, Labels("kindling", "some kindling", "some kindling"), 2,
            None, {})
        self.desk = Item(1112, 0x20000,
                         Labels("desk", "a desk", "a large mahogany desk"), 6,
                         None, {})
        self.elements = {
            80: self.library_location,
            81: self.lighthouse_location,
            1108: self.box,
            1109: self.ash,
            1110: self.candle,
            1111: self.kindling,
            1112: self.desk,
        }

        self.burn_command = Command(6, 0x0, 0x0, [], ["burn"], {})
        self.non_switching_command = Command(17, 0x0, 0x0, [], ["throw"], {})
        self.switching_command = Command(19, 0x200, 0x0, [], ["switch"], {})
        self.commands_by_id = {
            6: self.burn_command,
            17: self.non_switching_command,
            19: self.switching_command,
        }
    def test_validate_item_fragile_no_smash_command(self):
        self.items_by_id[1017] = Item(
            1017, 0xC203, Labels("vial", "a vial", "a small glass vial"), 2,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Fragile item(s) found, but no command specified with the handler \"smash\".",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((), validation_line.args)
    def test_validate_item_below_min_size_negative(self):
        self.items_by_id[1111] = Item(
            1111, 0x2, Labels("pebble", "a pebble", "a small pebble"), -6,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has a size of {2}. The minimum possible is {3}.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "pebble", -6, 1), validation_line.args)
    def test_validate_item_fragile_no_smash_transformation(self):
        self.smash_command_ids.append(37)
        self.items_by_id[1017] = Item(
            1017, 0xC203, Labels("vial", "a vial", "a small glass vial"), 2,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is fragile, but does not have a \"smash\" command replacement.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1017, "vial"), validation_line.args)
    def test_validate_item_obstruction_non_location_container(self):
        self.items_by_id[1111] = Item(
            1111, 0x80006, Labels("lion", "a lion", "a ferocious lioness"), 4,
            None, {}, None)
        self.items_by_id[1111].add_container(self.basket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Obstruction item {0} \"{1}\" has a parent container that is not a location.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "lion"), validation_line.args)
    def test_validate_item_copyable_non_liquid(self):
        self.items_by_id[1042] = Item(
            1042, 0x2802,
            Labels("kohlrabi", "some kohlrabi",
                   "some kohlrabi, a cabbage cultivar"), 3, None, {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has been specified as both copyable and non-liquid. This is not supported.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1042, "kohlrabi"), validation_line.args)
    def test_validate_item_non_usable_with_list_template_using(self):
        kohlrabi_list_templates = {ListTemplateType.USING, "(using) {0}"}
        self.items_by_id[1042] = Item(
            1042, 0x2002,
            Labels("kohlrabi", "some kohlrabi",
                   "some kohlrabi, a cabbage cultivar"), 3, None,
            kohlrabi_list_templates)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Invalid list template \"using\" found for item {0} \"{1}\". This field is only valid for usable items and will be ignored here.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1042, "kohlrabi"), validation_line.args)
 def setup_items(self):
     self.book = Item(1105, 0x2,
                      Labels("book", "a book", "a book of fairytales"), 2,
                      "The Pied Piper", {}, None)
     lamp_list_templates = {ListTemplateType.DEFAULT, "{0} (currently {1})"}
     lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off",
                                      "on")
     self.lamp = SwitchableItem(1043, 0x100A,
                                Labels("lamp", "a lamp",
                                       "a small lamp"), 3, None,
                                lamp_list_templates, lamp_switching_info)
     suit_list_templates = {ListTemplateType.USING, "(wearing) {0}"}
     self.suit = UsableItem(1046, 0x402,
                            Labels("suit", "a suit",
                                   "a space-suit"), 2, None,
                            suit_list_templates, Item.ATTRIBUTE_GIVES_AIR)
     self.basket = ContainerItem(
         1107, 0x3, Labels("basket", "a basket", "a large basket"), 8, None,
         {})
     self.desk = Item(1000, 0x20000,
                      Labels("desk", "a desk", "a large mahogany desk"), 6,
                      None, {})
     self.desk.add_container(self.lighthouse_location)
     self.wolf = Item(1080, 0x80006,
                      Labels("wolf", "a wolf", "a vicious wolf"), 4, None,
                      {}, None)
     self.wolf.add_container(self.lighthouse_location)
     self.items_by_id = {
         1105: self.book,
         1043: self.lamp,
         1046: self.suit,
         1107: self.basket,
         1000: self.desk,
         1080: self.wolf,
     }
     self.item_collection = ItemCollection({}, self.items_by_id)
Beispiel #19
0
class TestItem(unittest.TestCase):
    def setUp(self):
        self.book = Item(1105, 0x2,
                         Labels("book", "a book", "a book of fairytales"), 2,
                         "The Pied Piper", {})
        self.desk = Item(1106, 0x20000,
                         Labels("desk", "a desk", "a large mahogany desk"), 6,
                         None, {})

        rope_list_templates = {
            ListTemplateType.LOCATION: "{0} (coiled neatly)",
            ListTemplateType.CARRYING: "{0} (tied safely)"
        }
        self.rope = Item(1123, 0x2,
                         Labels("rope", "some rope", "a small length of rope"),
                         2, None, rope_list_templates)

        basket_list_templates = {ListTemplateType.DEFAULT: "{0} (upright)"}
        self.basket = ContainerItem(
            1107, 0x3, Labels("basket", "a basket", "a large basket"), 6, None,
            basket_list_templates)
        box_list_templates = {ListTemplateType.DEFAULT: "{0} (open)"}
        self.box = ContainerItem(1108, 0x3,
                                 Labels("box", "a box", "a small box"), 3,
                                 None, box_list_templates)

        lamp_list_templates = {ListTemplateType.DEFAULT: "{0} ({1})"}
        lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off",
                                         "on")
        self.lamp = SwitchableItem(1043, 0x100A,
                                   Labels("lamp", "a lamp",
                                          "a small lamp"), 2, None,
                                   lamp_list_templates, lamp_switching_info)

        button_list_templates = {ListTemplateType.DEFAULT: "{0} ({1})"}
        button_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "up",
                                           "down")
        self.button = SwitchableItem(
            1044, 0x8,
            Labels("button", "a button", "a red button",
                   [". It is dark", ". It is glowing"]), 2, None,
            button_list_templates, button_switching_info)

        lever_list_templates = {ListTemplateType.DEFAULT: "{0} ({1})"}
        lever_switching_info = SwitchInfo(Location.ATTRIBUTE_GIVES_LIGHT,
                                          "down", "up")
        self.lever = SwitchableItem(
            1045, 0x8, Labels("lever", "a lever", "a mysterious lever"), 2,
            None, lever_list_templates, lever_switching_info)

        suit_list_templates = {ListTemplateType.USING: "{0} (being worn)"}
        self.suit = UsableItem(1046, 0x402,
                               Labels("suit", "a suit",
                                      "a space-suit"), 2, None,
                               suit_list_templates, Item.ATTRIBUTE_GIVES_AIR)

        self.cat = SentientItem(1047, 0x80002,
                                Labels("cat", "a cat", "a black cat"), 3, None,
                                {})
        self.water = Item(
            1109, 0x22902,
            Labels("water", "some water", "some water",
                   [". It is cold", ". It is hot"]), 1, None, {})
        self.mine_location = Location(
            11, 0x0,
            Labels("Mines", "in the mines",
                   ". There are dark passages everywhere."))
        self.inventory = Inventory(
            0, 0x1,
            Labels("Main Inventory", "in the main inventory",
                   ", where items live usually."), 100)

        self.steam = Item(1117, 0x2,
                          Labels("steam", "some steam", "some hot steam"), 1,
                          None, {})
        self.water.transformations[98] = self.steam

    def test_copy(self):
        water_copy = copy(self.water)
        self.assertEqual(self.water.data_id, water_copy.data_id)
        self.assertEqual(self.water.shortname, water_copy.shortname)
        self.assertEqual(self.water.longname, water_copy.longname)
        self.assertEqual(self.water.description, water_copy.description)
        self.assertEqual(self.water.extended_descriptions,
                         water_copy.extended_descriptions)
        self.assertFalse(water_copy.is_copyable())
        self.assertIs(self.steam, water_copy.transformations[98])
        self.assertIs(self.water, water_copy.copied_from)
        self.assertTrue(water_copy in self.water.copied_to)

    def test_get_original_not_copied(self):
        self.assertEqual(self.book, self.book.get_original())

    def test_get_original_copied_once(self):
        water_copy = copy(self.water)

        self.assertEqual(self.water, water_copy.get_original())

    def test_get_original_copied_twice(self):
        water_copy = copy(self.water)
        water_copy_copy = copy(water_copy)

        self.assertEqual(self.water, water_copy_copy.get_original())

    def test_break_open_non_container(self):
        self.assertIsNone(self.lamp.break_open())

    def test_get_list_name_location_no_list_templates(self):
        self.assertEqual("\n\ta book", self.book.get_list_name_location())

    def test_get_list_name_inventory_no_list_templates(self):
        self.assertEqual("\n\ta book", self.book.get_list_name_inventory())

    def test_get_list_name_location_with_list_template(self):
        self.assertEqual("\n\tsome rope (coiled neatly)",
                         self.rope.get_list_name_location())

    def test_get_list_name_inventory_with_list_template(self):
        self.assertEqual("\n\tsome rope (tied safely)",
                         self.rope.get_list_name_inventory())

    def test_get_full_description_without_extended_descriptions(self):
        self.assertEqual(["a book of fairytales"],
                         self.book.get_full_description())

    def test_get_full_description_with_extended_descriptions(self):
        self.assertEqual(["some water. It is cold"],
                         self.water.get_full_description())

    def test_break_open_container(self):
        self.box.insert(self.book)

        self.assertEqual(self.book, self.box.break_open())

    def test_get_list_name_location_empty(self):
        self.assertEqual("\n\ta box (open) (---)",
                         self.box.get_list_name_location())

    def test_get_list_name_location_container_nonempty_single(self):
        self.box.insert(self.book)

        self.assertEqual("\n\ta box (open) +\n\t\ta book",
                         self.box.get_list_name_location())

    def test_get_list_name_location_container_nonempty_multi(self):
        self.basket.insert(self.box)
        self.box.insert(self.book)

        self.assertEqual(
            "\n\ta basket (upright) +\n\t\ta box (open) +\n\t\t\ta book",
            self.basket.get_list_name_location())

    def test_contains_simple(self):
        self.assertFalse(self.desk.contains(self.book))

    def test_contains_container_empty(self):
        self.assertFalse(self.basket.contains(self.book))

    def test_contains_container_nonempty_single(self):
        self.box.insert(self.book)

        self.assertTrue(self.box.contains(self.book))

    def test_contains_container_nonempty_multi(self):
        self.basket.insert(self.box)
        self.box.insert(self.book)

        self.assertTrue(self.basket.contains(self.box))
        self.assertTrue(self.box.contains(self.book))
        self.assertTrue(self.basket.contains(self.book))

    def test_get_allow_copy_single(self):
        book_copy = copy(self.book)
        self.box.insert(book_copy)

        self.assertFalse(self.box.contains(self.book))
        self.assertEqual(book_copy, self.box.get_allow_copy(self.book))

    def test_get_allow_copy_multi(self):
        book_copy = copy(self.book)
        self.box.insert(book_copy)
        self.basket.insert(self.box)

        self.assertFalse(self.basket.contains(self.book))
        self.assertEqual(book_copy, self.basket.get_allow_copy(self.book))

    def test_get_outermost_container_location(self):
        self.mine_location.insert(self.book)

        self.assertEqual(self.mine_location,
                         self.book.get_outermost_container())

    def test_get_outermost_container_inventory(self):
        self.inventory.insert(self.book)

        self.assertEqual(self.inventory, self.book.get_outermost_container())

    def test_get_outermost_container_multi(self):
        self.mine_location.insert(self.basket)
        self.basket.insert(self.box)
        self.box.insert(self.book)

        self.assertEqual(self.mine_location,
                         self.book.get_outermost_container())

    def test_get_list_name_location_sentient(self):
        self.assertEqual("\n\ta cat", self.cat.get_list_name_location())

    def test_get_list_name_sentient_carrying_item(self):
        self.cat.insert(self.book)

        self.assertEqual("\n\ta cat +\n\t\ta book",
                         self.cat.get_list_name_location())

    def test_switch_on_self(self):
        self.lamp.switched_element = self.lamp

        self.lamp.switch_on()

        self.assertTrue(self.lamp.gives_light())

    def test_switch_off_self(self):
        self.lamp.switched_element = self.lamp

        self.lamp.switch_off()

        self.assertFalse(self.lamp.gives_light())

    def test_switch_on_other_item(self):
        self.button.switched_element = self.lamp

        self.button.switch_on()

        self.assertTrue(self.lamp.gives_light())

    def test_switch_off_other_item(self):
        self.button.switched_element = self.lamp

        self.button.switch_off()

        self.assertFalse(self.lamp.gives_light())

    def test_switch_on_other_location(self):
        self.lever.switched_element = self.mine_location

        self.lever.switch_on()

        self.assertTrue(self.mine_location.gives_light())

    def test_switch_off_other_location(self):
        self.lever.switched_element = self.mine_location

        self.lever.switch_off()

        self.assertFalse(self.mine_location.gives_light())

    def test_get_list_name_location_switchable_off(self):
        self.lamp.switched_element = self.lamp
        self.lamp.switch_off()

        self.assertEqual("\n\ta lamp (off)",
                         self.lamp.get_list_name_location())

    def test_get_list_name_location_switchable_on(self):
        self.lever.switched_element = self.mine_location
        self.lever.switch_on()

        self.assertEqual("\n\ta lever (up)",
                         self.lever.get_list_name_location())

    def test_get_full_description_switchable_without_extended_descriptions(
            self):
        self.lamp.switched_element = self.lamp
        self.lamp.switch_off()

        self.assertEqual(["a small lamp", "off"],
                         self.lamp.get_full_description())

    def test_get_full_description_switchable_with_extended_descriptions(self):
        self.button.switched_element = self.lamp
        self.button.switch_off()

        self.assertEqual(["a red button. It is dark", "up"],
                         self.button.get_full_description())

    def test_has_attribute_wearable_not_being_used(self):
        self.suit.being_used = False

        self.assertFalse(self.suit.gives_air())

    def test_has_attribute_wearable_being_used(self):
        self.suit.being_used = True

        self.assertTrue(self.suit.gives_air())

    def test_list_name_inventory_wearable_not_being_used(self):
        self.suit.being_used = False

        self.assertEqual("\n\ta suit", self.suit.get_list_name_inventory())

    def test_list_name_inventory_wearable_being_used(self):
        self.suit.being_used = True

        self.assertEqual("\n\ta suit (being worn)",
                         self.suit.get_list_name_inventory())
class TestPostParseValidator(unittest.TestCase):
    def setUp(self):
        self.setup_commands()
        self.setup_inventories()
        self.setup_locations()
        self.setup_items()
        self.data_collection = DataCollection(
            commands=self.command_collection,
            inventories=self.inventory_collection,
            locations=self.location_collection,
            elements_by_id=None,
            items=self.item_collection,
            item_related_commands=None,
            hints=None,
            explanations=None,
            responses=None,
            inputs=None,
            events=None,
        )
        self.validator = PostParseValidator()

    def setup_commands(self):
        self.commands_by_id = {}
        self.commands_by_id[56] = Command(56, 0x0, [], [], ["take", "t"], {})
        self.smash_command_ids = []
        self.command_collection = CommandCollection({}, self.commands_by_id,
                                                    "command_list",
                                                    self.smash_command_ids)

    def setup_inventories(self):
        self.inventories_by_id = {}
        self.inventories_by_id[0] = Inventory(
            0, 0x1,
            Labels("Main Inventory", "in the main inventory",
                   ", where items live usually."), 3)
        self.inventory_collection = InventoryCollection(self.inventories_by_id)

    def setup_locations(self):
        self.lighthouse_location = Location(
            12, 0x603, Labels("Lighthouse", "at a lighthouse", " by the sea."))
        self.beach_location = Location(
            13, 0x603, Labels("Beach", "on a beach", " of black sand"))
        self.locations_by_id = {}
        self.locations_by_id[12] = self.lighthouse_location
        self.locations_by_id[13] = self.beach_location
        self.location_collection = LocationCollection(self.locations_by_id)

    def setup_items(self):
        self.book = Item(1105, 0x2,
                         Labels("book", "a book", "a book of fairytales"), 2,
                         "The Pied Piper", {}, None)
        lamp_list_templates = {ListTemplateType.DEFAULT, "{0} (currently {1})"}
        lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off",
                                         "on")
        self.lamp = SwitchableItem(1043, 0x100A,
                                   Labels("lamp", "a lamp",
                                          "a small lamp"), 3, None,
                                   lamp_list_templates, lamp_switching_info)
        suit_list_templates = {ListTemplateType.USING, "(wearing) {0}"}
        self.suit = UsableItem(1046, 0x402,
                               Labels("suit", "a suit",
                                      "a space-suit"), 2, None,
                               suit_list_templates, Item.ATTRIBUTE_GIVES_AIR)
        self.basket = ContainerItem(
            1107, 0x3, Labels("basket", "a basket", "a large basket"), 8, None,
            {})
        self.desk = Item(1000, 0x20000,
                         Labels("desk", "a desk", "a large mahogany desk"), 6,
                         None, {})
        self.desk.add_container(self.lighthouse_location)
        self.wolf = Item(1080, 0x80006,
                         Labels("wolf", "a wolf", "a vicious wolf"), 4, None,
                         {}, None)
        self.wolf.add_container(self.lighthouse_location)
        self.items_by_id = {
            1105: self.book,
            1043: self.lamp,
            1046: self.suit,
            1107: self.basket,
            1000: self.desk,
            1080: self.wolf,
        }
        self.item_collection = ItemCollection({}, self.items_by_id)

    def test_validate_valid(self):
        validation = self.validator.validate(self.data_collection)

        self.assertFalse(validation)

    def test_validate_command_teleport_no_teleport_info(self):
        self.commands_by_id.clear()
        self.commands_by_id[51] = Command(51, 0x2, [], [], ["teleport"], {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Command {0} \"{1}\" is a teleport command, but no teleport info has been given. No teleports will be possible.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((51, "teleport"), validation_line.args)

    def test_validate_command_non_teleport_with_teleport_info(self):
        self.commands_by_id.clear()
        take_command = Command(56, 0x0, [], [], ["take", "t"], {})
        self.commands_by_id[56] = take_command
        take_command.teleport_info[6] = self.lighthouse_location

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Command {0} \"{1}\" is not a teleport command, but teleport info has been given. This teleport info will be ignored.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((56, "take"), validation_line.args)

    def test_validate_command_switchable_no_switch_info(self):
        self.commands_by_id.clear()
        self.commands_by_id[63] = Command(63, 0x100, [], [], ["verbose"], {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Command {0} \"{1}\" is a switchable command, but no switch info has been given.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((63, "verbose"), validation_line.args)

    def test_validate_command_non_switchable_with_switch_info(self):
        self.commands_by_id.clear()
        switch_info = {"off": False, "on": True}
        self.commands_by_id[56] = Command(56, 0x0, [], [], ["take", "t"],
                                          switch_info)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Command {0} \"{1}\" is not a switchable command, but switch info has been given. This switch info will be ignored.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((56, "take"), validation_line.args)

    def test_validate_command_multiple_smash(self):
        self.smash_command_ids.append(17)
        self.smash_command_ids.append(81)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Multiple commands specified with the handler \"smash\". This is not supported.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((), validation_line.args)

    def test_validate_inventory_no_inventories(self):
        self.inventories_by_id.clear()

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "No inventories specified. At least one inventory must be given.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((), validation_line.args)

    def test_validate_inventory_no_default(self):
        self.inventories_by_id.clear()
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3, [12])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "No default inventory found. Exactly one inventory must be marked as default.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((), validation_line.args)

    def test_validate_inventory_multiple_defaults(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x1,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(2, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Multiple default inventories found ({0}). Exactly one inventory must be marked as default.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual(([0, 1], ), validation_line.args)

    def test_validate_inventory_default_with_locations(self):
        self.inventories_by_id.clear()
        self.inventories_by_id[1] = Inventory(
            0, 0x1,
            Labels("Main Inventory", "in the main inventory",
                   ", where items live usually."), 3, [12])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Default inventory {0} \"{1}\" has location ids specified. This is redundant.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((0, "Main Inventory"), validation_line.args)

    def test_validate_inventory_non_default_no_locations(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(2, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-default inventory {0} \"{1}\" has no location ids specified. It will not be used anywhere.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1, "Special Inventory"), validation_line.args)

    def test_validate_inventory_non_default_unknown_location(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3, [888])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(2, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-default inventory {0} \"{1}\" references location with id {2}, but this does not reference a valid location.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1, "Special Inventory", 888), validation_line.args)

    def test_validate_inventory_non_default_duplicate_location(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3, [12, 12])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(2, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-default inventory {0} \"{1}\" references location with id {2} multiple times.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1, "Special Inventory", 12), validation_line.args)

    def test_validate_inventory_non_default_shared_location(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3, [12])
        self.inventories_by_id[2] = Inventory(
            2, 0x0,
            Labels("Occasional Inventory", "in the occasional inventory",
                   ", where items live occasionally."), 3, [12])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(3, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-default inventory {0} \"{1}\" references location with id {2}, but this location is referenced by at least one other inventory.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((2, "Occasional Inventory", 12), validation_line.args)

    def test_validate_location_no_floor_no_down(self):
        self.locations_by_id[17] = Location(
            17, 0x50F,
            Labels("Precipice", "on a precipice", ", high in the air"))

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Location {0} has no floor, but does not specify a link in direction {1}.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((17, "DOWN"), validation_line.args)

    def test_validate_location_no_land_no_floor(self):
        mid_air_location = Location(
            19, 0x10F,
            Labels("Mid-air", "in mid-air", "; you are not sure how high"))
        mid_air_location.directions[Direction.DOWN] = self.lighthouse_location
        self.locations_by_id[19] = mid_air_location

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Location {0} has no land, but also no floor. Locations without land must have a floor.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((19, ), validation_line.args)

    def test_validate_item_below_min_size_zero(self):
        self.items_by_id[1111] = Item(
            1111, 0x2, Labels("pebble", "a pebble", "a small pebble"), 0, None,
            {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has a size of {2}. The minimum possible is {3}.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "pebble", 0, 1), validation_line.args)

    def test_validate_item_below_min_size_negative(self):
        self.items_by_id[1111] = Item(
            1111, 0x2, Labels("pebble", "a pebble", "a small pebble"), -6,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has a size of {2}. The minimum possible is {3}.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "pebble", -6, 1), validation_line.args)

    def test_validate_item_container_below_min_size(self):
        self.items_by_id[1111] = ContainerItem(
            1111, 0x3, Labels("locket", "a locket", "a small locket"), 1, None,
            {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Container item {0} \"{1}\" has a size of only {2}. As the minimum item size is {3}, nothing will be able to fit in it.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1111, "locket", 1, 1), validation_line.args)

    def test_validate_item_container_shared(self):
        self.book.add_container(self.basket)
        self.lamp.add_container(self.basket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Container item {0} \"{1}\" contains multiple items. This is not supported.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1107, "basket"), validation_line.args)

    def test_validate_item_container_too_small_equal(self):
        locket = ContainerItem(1111, 0x3,
                               Labels("locket", "a locket", "a small locket"),
                               2, None, {})
        self.items_by_id[1111] = locket
        self.book.add_container(locket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" with size {2} is contained in {3} \"{4}\" with size {5}. A container must be strictly greater in size than the item it contains.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1105, "book", 2, 1111, "locket", 2),
                         validation_line.args)

    def test_validate_item_container_too_small_smaller(self):
        locket = ContainerItem(1111, 0x3,
                               Labels("locket", "a locket", "a small locket"),
                               2, None, {})
        self.items_by_id[1111] = locket
        self.lamp.add_container(locket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" with size {2} is contained in {3} \"{4}\" with size {5}. A container must be strictly greater in size than the item it contains.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1043, "lamp", 3, 1111, "locket", 2),
                         validation_line.args)

    def test_validate_item_liquid_container_not_liquid(self):
        water = Item(1111, 0x22902, Labels("water", "some water",
                                           "some water"), 1, None, {})
        water.add_container(self.basket)
        self.items_by_id[1111] = water

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is a liquid, but has container {2} \"{3}\", which is not a liquid container.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "water", 1107, "basket"), validation_line.args)

    def test_validate_item_non_liquid_container_liquid(self):
        bottle = ContainerItem(
            1111, 0x203, Labels("bottle", "a bottle", "a small glass bottle"),
            3, None, {})
        self.book.add_container(bottle)
        self.items_by_id[1111] = bottle

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is non-liquid, but has container {2} \"{3}\", which is a liquid container.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1105, "book", 1111, "bottle"), validation_line.args)

    def test_validate_item_liquid_non_copyable_container_location(self):
        water = Item(1111, 0x2102, Labels("water", "some water", "some water"),
                     1, None, {})
        water.add_container(self.lighthouse_location)
        self.items_by_id[1111] = water

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is a liquid, and has location container {2} \"{3}\". Liquids may only be contained at locations if they are copyable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "water", 12, "Lighthouse"),
                         validation_line.args)

    def test_validate_item_switchable_no_list_templates(self):
        button_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "up",
                                           "down")
        self.items_by_id[1044] = SwitchableItem(
            1044, 0x8,
            Labels("button", "a button", "a red button",
                   [". It is dark", ". It is glowing"]), 2, None, {},
            button_switching_info)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Missing or incomplete list templates found for switchable item {0} \"{1}\". While not mandatory, this will lead to incomplete descriptions of this item when listed. Switchable items should specify either \"default\" or both \"location\" and \"carrying\" list templates.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1044, "button"), validation_line.args)

    def test_validate_item_switchable_incomplete_list_templates(self):
        button_list_templates = {
            ListTemplateType.LOCATION, "{0} (currently {1})"
        }
        button_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "up",
                                           "down")
        self.items_by_id[1044] = SwitchableItem(
            1044, 0x8,
            Labels("button", "a button", "a red button",
                   [". It is dark", ". It is glowing"]), 2, None,
            button_list_templates, button_switching_info)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Missing or incomplete list templates found for switchable item {0} \"{1}\". While not mandatory, this will lead to incomplete descriptions of this item when listed. Switchable items should specify either \"default\" or both \"location\" and \"carrying\" list templates.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1044, "button"), validation_line.args)

    def test_validate_item_usable_no_list_template_using(self):
        self.items_by_id[1118] = UsableItem(
            1118, 0x10002, Labels("raft", "a raft", "a rickety raft"), 6, None,
            {}, Item.ATTRIBUTE_GIVES_LAND)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Mandatory list template \"using\" not found for usable item {0} \"{1}\".",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1118, "raft"), validation_line.args)

    def test_validate_item_non_usable_with_list_template_using(self):
        kohlrabi_list_templates = {ListTemplateType.USING, "(using) {0}"}
        self.items_by_id[1042] = Item(
            1042, 0x2002,
            Labels("kohlrabi", "some kohlrabi",
                   "some kohlrabi, a cabbage cultivar"), 3, None,
            kohlrabi_list_templates)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Invalid list template \"using\" found for item {0} \"{1}\". This field is only valid for usable items and will be ignored here.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1042, "kohlrabi"), validation_line.args)

    def test_validate_item_non_mobile_non_location_container(self):
        self.desk.add_container(self.basket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-mobile item {0} \"{1}\" has at least one parent container that is not a location.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1000, "desk"), validation_line.args)

    def test_validate_item_non_mobile_sailable(self):
        self.items_by_id[1118] = UsableItem(
            1118, 0x10000, Labels("raft", "a raft", "a rickety raft"), 6, None,
            {ListTemplateType.USING, "(sailing) {0}"},
            Item.ATTRIBUTE_GIVES_LAND)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is marked as both non-mobile and sailable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1118, "raft"), validation_line.args)

    def test_validate_item_non_mobile_wearable(self):
        self.items_by_id[1046] = UsableItem(
            1046, 0x400, Labels("suit", "a suit", "a space-suit"), 2, None,
            {ListTemplateType.USING, "(wearing) {0}"},
            Item.ATTRIBUTE_GIVES_AIR)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is marked as both non-mobile and wearable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1046, "suit"), validation_line.args)

    def test_validate_item_obstruction_multiple_containers(self):
        self.wolf.add_container(self.beach_location)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Obstruction item {0} \"{1}\" has multiple containers.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1080, "wolf"), validation_line.args)

    def test_validate_item_obstruction_non_location_container(self):
        self.items_by_id[1111] = Item(
            1111, 0x80006, Labels("lion", "a lion", "a ferocious lioness"), 4,
            None, {}, None)
        self.items_by_id[1111].add_container(self.basket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Obstruction item {0} \"{1}\" has a parent container that is not a location.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "lion"), validation_line.args)

    def test_validate_item_usable_liquid(self):
        self.items_by_id[1118] = UsableItem(
            1118, 0x10102, Labels("raft", "a raft", "a rickety raft"), 6, None,
            {ListTemplateType.USING, "(sailing) {0}"},
            Item.ATTRIBUTE_GIVES_LAND)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual("Usable item {0} \"{1}\" is marked as liquid.",
                         validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1118, "raft"), validation_line.args)

    def test_validate_item_wearable_sailable(self):
        self.items_by_id[1118] = UsableItem(
            1118, 0x10402, Labels("raft", "a raft", "a rickety raft"), 6, None,
            {ListTemplateType.USING, "(sailing) {0}"},
            Item.ATTRIBUTE_GIVES_LAND)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Usable item {0} \"{1}\" is marked as both wearable and sailable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1118, "raft"), validation_line.args)

    def test_validate_item_copyable_non_liquid(self):
        self.items_by_id[1042] = Item(
            1042, 0x2802,
            Labels("kohlrabi", "some kohlrabi",
                   "some kohlrabi, a cabbage cultivar"), 3, None, {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has been specified as both copyable and non-liquid. This is not supported.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1042, "kohlrabi"), validation_line.args)

    def test_validate_item_fragile_no_smash_command(self):
        self.items_by_id[1017] = Item(
            1017, 0xC203, Labels("vial", "a vial", "a small glass vial"), 2,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Fragile item(s) found, but no command specified with the handler \"smash\".",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((), validation_line.args)

    def test_validate_item_fragile_no_smash_transformation(self):
        self.smash_command_ids.append(37)
        self.items_by_id[1017] = Item(
            1017, 0xC203, Labels("vial", "a vial", "a small glass vial"), 2,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is fragile, but does not have a \"smash\" command replacement.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1017, "vial"), validation_line.args)
Beispiel #21
0
 def __init__(self, abbreviation, name, moves, response=None):
     Item.__init__(self, name, abbreviation)
     self.moves = list(moves)
     self.responses = response
Beispiel #22
0
    def setUp(self):
        self.book = Item(1105, 0x2,
                         Labels("book", "a book", "a book of fairytales"), 2,
                         "The Pied Piper", {})
        self.desk = Item(1106, 0x20000,
                         Labels("desk", "a desk", "a large mahogany desk"), 6,
                         None, {})

        rope_list_templates = {
            ListTemplateType.LOCATION: "{0} (coiled neatly)",
            ListTemplateType.CARRYING: "{0} (tied safely)"
        }
        self.rope = Item(1123, 0x2,
                         Labels("rope", "some rope", "a small length of rope"),
                         2, None, rope_list_templates)

        basket_list_templates = {ListTemplateType.DEFAULT: "{0} (upright)"}
        self.basket = ContainerItem(
            1107, 0x3, Labels("basket", "a basket", "a large basket"), 6, None,
            basket_list_templates)
        box_list_templates = {ListTemplateType.DEFAULT: "{0} (open)"}
        self.box = ContainerItem(1108, 0x3,
                                 Labels("box", "a box", "a small box"), 3,
                                 None, box_list_templates)

        lamp_list_templates = {ListTemplateType.DEFAULT: "{0} ({1})"}
        lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off",
                                         "on")
        self.lamp = SwitchableItem(1043, 0x100A,
                                   Labels("lamp", "a lamp",
                                          "a small lamp"), 2, None,
                                   lamp_list_templates, lamp_switching_info)

        button_list_templates = {ListTemplateType.DEFAULT: "{0} ({1})"}
        button_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "up",
                                           "down")
        self.button = SwitchableItem(
            1044, 0x8,
            Labels("button", "a button", "a red button",
                   [". It is dark", ". It is glowing"]), 2, None,
            button_list_templates, button_switching_info)

        lever_list_templates = {ListTemplateType.DEFAULT: "{0} ({1})"}
        lever_switching_info = SwitchInfo(Location.ATTRIBUTE_GIVES_LIGHT,
                                          "down", "up")
        self.lever = SwitchableItem(
            1045, 0x8, Labels("lever", "a lever", "a mysterious lever"), 2,
            None, lever_list_templates, lever_switching_info)

        suit_list_templates = {ListTemplateType.USING: "{0} (being worn)"}
        self.suit = UsableItem(1046, 0x402,
                               Labels("suit", "a suit",
                                      "a space-suit"), 2, None,
                               suit_list_templates, Item.ATTRIBUTE_GIVES_AIR)

        self.cat = SentientItem(1047, 0x80002,
                                Labels("cat", "a cat", "a black cat"), 3, None,
                                {})
        self.water = Item(
            1109, 0x22902,
            Labels("water", "some water", "some water",
                   [". It is cold", ". It is hot"]), 1, None, {})
        self.mine_location = Location(
            11, 0x0,
            Labels("Mines", "in the mines",
                   ". There are dark passages everywhere."))
        self.inventory = Inventory(
            0, 0x1,
            Labels("Main Inventory", "in the main inventory",
                   ", where items live usually."), 100)

        self.steam = Item(1117, 0x2,
                          Labels("steam", "some steam", "some hot steam"), 1,
                          None, {})
        self.water.transformations[98] = self.steam