def test_aliases(self): wizard = self.exchange.get_object('wizard') wizard.add_alias('The Wiz') p = parser.TransactionParser(parser.Lexer("@eval the Wiz from 'bag under stairs' with tongs in wizard's bag"), wizard, self.exchange) self.assertEqual(p.get_dobj(), wizard) wizard.remove_alias('The Wiz') p = parser.TransactionParser(parser.Lexer("@eval the Wiz from 'bag under stairs' with tongs in wizard's bag"), wizard, self.exchange) self.assertEqual(p.has_dobj(), False)
def test_inventory(self): wizard = self.exchange.get_object('wizard') box = self.exchange.instantiate('object', name='box') box.set_location(wizard) p = parser.TransactionParser(parser.Lexer("@eval my box"), wizard, self.exchange) self.assertTrue(p.has_dobj()) user = self.exchange.get_object('user') box.set_location(user) p = parser.TransactionParser(parser.Lexer("@eval user's box"), wizard, self.exchange) self.assertTrue(p.has_dobj())
def test_complex(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval the wizard from 'bag under stairs' with tongs in wizard's bag"), wizard, self.exchange) self.assertRaises(errors.NoSuchObjectError, p.get_pobj, "from") self.assertRaises(errors.NoSuchObjectError, p.get_pobj, "with") self.assertEqual(p.get_pobj_str('from'), 'bag under stairs') self.assertEqual(p.get_dobj(), wizard) self.assertEqual(p.get_pobj_str("with"), "tongs")
def test_parse_verb_dobj_pobj(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval glasses from wizard with tongs"), wizard, self.exchange) self.assertRaises(errors.NoSuchObjectError, p.get_dobj) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj, "under") self.assertEqual(p.get_dobj_str(), "glasses") self.assertEqual(p.get_pobj_str("with"), "tongs") self.assertEqual(p.get_pobj("from"), wizard) self.assertEqual(p.get_pobj_str("from"), "wizard")
def test_parse_verb_dobj(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval wizard"), wizard, self.exchange) assert p.has_dobj(), "dobj 'wizard' not found" assert p.has_dobj_str(), "dobj string 'wizard' not found" assert not p.prepositions, "unexpected prepositional objects/strings found" self.assertEqual(p.get_dobj(), wizard) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj, "on") self.assertEqual(p.get_dobj_str().lower(), wizard.get_name().lower()) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj_str, "on")
def test_parse_verb(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval"), wizard, self.exchange) assert not p.has_dobj(), "unexpected object found for dobj" assert not p.has_dobj_str(), "unexpected string found for dobj" assert not p.prepositions, "unexpected prepositional objects found" self.assertRaises(errors.NoSuchObjectError, p.get_dobj) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj, "on") self.assertRaises(errors.NoSuchObjectError, p.get_dobj_str) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj_str, "on")
def test_parse_verb_pobj_pobj(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval through peephole with wizard"), wizard, self.exchange) assert not p.has_dobj(), "unexpected object found for dobj" assert not p.has_dobj_str(), "unexpected string found for dobj" self.assertRaises(errors.NoSuchObjectError, p.get_dobj) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj, "from") self.assertEqual(p.get_pobj("with"), wizard) self.assertEqual(p.get_pobj_str("with"), "wizard") self.assertRaises(errors.NoSuchObjectError, p.get_dobj_str) self.assertEqual(p.get_pobj_str("through"), "peephole")
def openaccess(user_id, object_id, type, name): with tasks.get_exchange(user_id) as x: origin = x.get_object(object_id) caller = x.get_object(user_id) if (type == 'object'): item = origin else: item = getattr(origin, 'get_' + type)(name) p = parser.TransactionParser(parser.Lexer(''), caller, x) from antioch.plugins import editors editors.access(p, item) return {'response': True}
def test_wizard_edit(self): caller = self.exchange.get_object('wizard') l = parser.Lexer('edit me') p = parser.TransactionParser(l, caller, self.exchange) v = p.get_verb() self.assertEqual(p.this, caller) def push(user_id, msg): self.assertEqual(user_id, 2) self.assertEqual(msg['details']['name'], 'Wizard') self.exchange.queue.push = push v.execute(p)
def test_player_look(self): caller = self.exchange.get_object('wizard') l = parser.Lexer('look here') p = parser.TransactionParser(l, caller, self.exchange) v = p.get_verb() self.assertEqual(p.this, caller) def push(user_id, msg): self.assertEqual(user_id, caller.get_id()) self.assertEqual(msg['observations']['name'], 'The Laboratory') self.exchange.queue.push = push v.execute(p)
def openeditor(user_id, object_id, type, name): with tasks.get_exchange(user_id) as x: if (type == 'object'): item = x.get_object(object_id) else: item = getattr(x, 'get_' + type)(object_id, name) if (item is None): item = x.instantiate(type, owner_id=user_id, origin_id=object_id, name=name) caller = x.get_object(user_id) p = parser.TransactionParser(parser.Lexer(''), caller, x) from antioch.plugins import editors editors.edit(p, item) return {'response': True}
def test_player_write(self): self.skipTest("Test broken without celery support") caller = self.exchange.get_object('wizard') l = parser.Lexer('exec write(caller, "test")') p = parser.TransactionParser(l, caller, self.exchange) v = p.get_verb() self.assertEqual(p.this, caller) self._test_player_write_ran = False def push(user_id, msg): self._test_player_write_ran = True self.assertEqual(user_id, 2) self.assertEqual(msg['text'], 'test') self.exchange.queue.push = push v.execute(p) self.assertEqual(self._test_player_write_ran, True)
def test_bug_9(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval here as 'Large amounts of chalkdust lay all over the objects in this room, and a large chalkboard at one end has become coated with a thick layer of Queen Anne\\'s lace. Strange semi-phosphorescant orbs are piled all around this ancient hall.'"), wizard, self.exchange) self.assertRaises(errors.NoSuchPrepositionError, p.get_pobj_str, 'around') assert "\\" not in p.get_pobj_str('as')
def test_quoted_strings(self): wizard = self.exchange.get_object('wizard') p = parser.TransactionParser(parser.Lexer("@eval wizard to 'something here'"), wizard, self.exchange) self.assertEqual(p.get_pobj_str('to'), 'something here')