class TestShopping(unittest.TestCase): def setUp(self): self.shopkeeper = Shopkeeper("lucy", "f") shop = ShopBehavior() shop.open_hours = [(9, 17), (22, 3)] # from 9 to 17 and in the night from 22 to 03 self.shopkeeper.set_shop(shop) def test_open_hours(self): self.shopkeeper.validate_open_hours(current_time=datetime.time(9, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(9, 1)) self.shopkeeper.validate_open_hours(current_time=datetime.time(13, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(16, 59)) self.shopkeeper.validate_open_hours(current_time=datetime.time(22, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(23, 59)) self.shopkeeper.validate_open_hours(current_time=datetime.time(0, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(0, 1)) self.shopkeeper.validate_open_hours(current_time=datetime.time(2, 59)) wiz = NPC("wizard", "m") wiz.privileges.add("wizard") self.shopkeeper.validate_open_hours(wiz, current_time=datetime.time(2, 59)) def test_closed_hours(self): with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(6, 30)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(8, 59)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(17, 0)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(21, 59)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(3, 0)) wiz = NPC("wizard", "m") wiz.privileges.add("wizard") self.shopkeeper.validate_open_hours(wiz, current_time=datetime.time(21, 59))
class TestShopping(unittest.TestCase): def setUp(self): self.shopkeeper = Shopkeeper("lucy", "f") shop = ShopBehavior() shop.open_hours = [(9, 17), (22, 3)] # from 9 to 17 and in the night from 22 to 03 self.shopkeeper.set_shop(shop) def test_open_hours(self): self.shopkeeper.validate_open_hours(current_time=datetime.time(9, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(9, 1)) self.shopkeeper.validate_open_hours(current_time=datetime.time(13, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(16, 59)) self.shopkeeper.validate_open_hours(current_time=datetime.time(22, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(23, 59)) self.shopkeeper.validate_open_hours(current_time=datetime.time(0, 0)) self.shopkeeper.validate_open_hours(current_time=datetime.time(0, 1)) self.shopkeeper.validate_open_hours(current_time=datetime.time(2, 59)) wiz = Living("wizard", "m") wiz.privileges.add("wizard") self.shopkeeper.validate_open_hours(wiz, current_time=datetime.time(2, 59)) def test_closed_hours(self): with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(6, 30)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(8, 59)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(17, 0)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(21, 59)) with self.assertRaises(ActionRefused): self.shopkeeper.validate_open_hours(current_time=datetime.time(3, 0)) wiz = Living("wizard", "m") wiz.privileges.add("wizard") self.shopkeeper.validate_open_hours(wiz, current_time=datetime.time(21, 59))
shop.insert(shopkeeper, shop) shop.add_exits([ Exit(["door", "out"], "town.lane", "A fancy door provides access back to the lane outside.") ]) # provide some items in the shop clock = clone(gameclock) clock.value = 500 paper = clone(newspaper) gem2 = clone(diamond) gem2.value = 80000 gem3 = clone(gem) gem3.value = 9055 shopkeeper.init_inventory([gem2, gem3, toothpick]) shopkeeper.set_shop(shopinfo) shop.insert(clock, shop) shop.insert(paper, shop) lamp = Item("lamp", "rather small lamp") lamp.value = 600 class James(NPC, Listener): """The customer trying to sell a Lamp, and helpful as rat deterrent.""" def pubsub_event(self, topicname, event): if topicname[0] == "wiretap-location": if "Rat arrives" in event[1]: mud_context.driver.defer(2, self.rat_scream, "frown") mud_context.driver.defer(4, self.rat_kick) def rat_scream(self, action, ctx):
shopkeeper.money = 14000 shop = Location("Curiosity Shoppe", "A weird little shop. It sells odd stuff.") shop.insert(shopkeeper, shop) shop.add_exits([Exit(["door", "out"], "town.lane", "A fancy door provides access back to the lane outside.")]) # provide some items in the shop clock = clone(gameclock) clock.value = 500 paper = clone(newspaper) gem2 = clone(diamond) gem2.value = 80000 gem3 = clone(gem) gem3.value = 9055 shopkeeper.init_inventory([gem2, gem3, toothpick]) shopkeeper.set_shop(shopinfo) shop.insert(clock, shop) shop.insert(paper, shop) lamp = Item("lamp", "rather small lamp") lamp.value = 600 class James(NPC, Listener): """The customer trying to sell a Lamp, and helpful as rat deterrent.""" def pubsub_event(self, topicname, event): if topicname[0] == "wiretap-location": if "Rat arrives" in event[1]: mud_context.driver.defer(2, self.rat_scream, "frown") mud_context.driver.defer(4, self.rat_kick) def rat_scream(self, action, ctx):