def testTwoArgs(self): m = Map() m.put(KVPair('foo', NameRef('arg1'))) m.put(KVPair('bar', NameRef('arg2'))) f = Function(m, ['arg1', 'arg2']) r = f.call(42, 'ackup') self.assertEqual(r, {'foo': 42,'bar':'ackup'})
def setUp(self): self.stream = ItemStream([ KVPair(42, 'foo'), KVPair('foo', 17), KVPair('umm', List()), ]) self.m = Map()
class TestPairStream(unittest.TestCase): def setUp(self): self.scope = Map() self.scope['var'] = True self.c = Conditional() self.scope.put(self.c) def testStream(self): self.c.put_cond( NameRef('var'), ItemStream([ KVPair('ag', Map()), KVPair('ug', NameRef('var')) ]) ) self.assertEqual(self.scope['ag'], {}) self.assertEqual(self.scope['ug'], True) def testUndefinedHasNoEffect(self): self.scope.set_key('var', False) self.assertEqual(self.scope.eval(), {'var':False}) # and nothing else
def setUp(self): self.scope = Map() self.scope['var'] = True self.m = Map() self.scope['bar'] = self.m self.c = Conditional() self.scope['cond'] = self.c
def testKVPairs(self): self.let = Let() self.let.names['var'] = 3 x = Map() x['bar'] = NameRef('var') self.let.put(KVPair('a', x)) x = List() x.put(NameRef('var')) self.let.put(KVPair('b', x)) root = Map() root.put(self.let) self.assertEqual(root.eval(), {'a':{'bar':3}, 'b':[3]})
def setUp(self): # create functions m0 = Map() m0.put(KVPair('guk', NameRef('foo'))) self.f0 = Function(m0) m1 = Map() m1.put(KVPair('ack', NameRef('arg'))) self.f1 = Function(m1, ['arg']) m2 = Map() m2.put(KVPair('froz', NameRef('arg1'))) m2.put(KVPair('fuzz', NameRef('arg2'))) self.f2 = Function(m2, ['arg1', 'arg2']) # put them in place self.m = Map() self.m.put(KVPair('foo', 42)) self.m.put(KVPair('f0',self.f0)) self.m.put(KVPair('f1',self.f1)) self.m.put(KVPair('f2',self.f2)) self.m.put(KVPair('call0', FunctionCall(NameRef('f0')))) self.m.put(KVPair('call1', FunctionCall(NameRef('f1'), [13]))) self.m.put(KVPair('call2', FunctionCall(NameRef('f2'), ['ack', 17])))
class ItemStreamCompatibility(unittest.TestCase): def setUp(self): self.stream = ItemStream([ KVPair(42, 'foo'), KVPair('foo', 17), KVPair('umm', List()), ]) self.m = Map() def testPut(self): self.m.put(self.stream) self.assertEqual(self.m[42], 'foo') self.assertEqual(self.m['foo'], 17) self.assertEqual(self.m['umm'], []) def testBadPut(self): self.stream.append(14) # non kvpair is an error self.assertRaises(fern.errors.TypeError, self.m.put, self.stream) def testReparentInStream(self): self.m['var'] = 17 self.stream.put(KVPair('ref', NameRef('var'))) self.m.put(self.stream) self.assertEqual(self.m['ref'], 17)
class TestIfItem(unittest.TestCase): def setUp(self): self.scope = Map() self.scope['var'] = True self.m = Map() self.scope['bar'] = self.m self.c = Conditional() self.scope['cond'] = self.c def testOneCond(self): self.c.put_cond(NameRef('var'), 'foo') self.assertEqual(self.c.eval(), 'foo') self.scope.set_key('var', False) self.assertEqual(self.c.eval(), Undefined) def testTwoConds(self): # one self.c.put_cond(NameRef('var'), 'foo') self.c.put_cond(NameRef('bar'), 'fuzz') self.assertEqual(self.c.eval(), 'foo') # two self.scope.set_key('var', False) self.assertEqual(self.c.eval(), Undefined) # three self.m['nothing'] = 42 self.assertEqual(self.c.eval(), 'fuzz') def testElse(self): self.scope.set_key('var', False) self.c.refresh() # make sure setting else works after refresh self.c.else_val = 'guth' self.assertEqual(self.c.eval(), 'guth')
def testNoArgs(self): m = Map() m.put(KVPair('foo', 42)) f = Function(m) r = f.call() self.assertEqual(r, {'foo': 42})
class TestCall(unittest.TestCase): def setUp(self): # create functions m0 = Map() m0.put(KVPair('guk', NameRef('foo'))) self.f0 = Function(m0) m1 = Map() m1.put(KVPair('ack', NameRef('arg'))) self.f1 = Function(m1, ['arg']) m2 = Map() m2.put(KVPair('froz', NameRef('arg1'))) m2.put(KVPair('fuzz', NameRef('arg2'))) self.f2 = Function(m2, ['arg1', 'arg2']) # put them in place self.m = Map() self.m.put(KVPair('foo', 42)) self.m.put(KVPair('f0',self.f0)) self.m.put(KVPair('f1',self.f1)) self.m.put(KVPair('f2',self.f2)) self.m.put(KVPair('call0', FunctionCall(NameRef('f0')))) self.m.put(KVPair('call1', FunctionCall(NameRef('f1'), [13]))) self.m.put(KVPair('call2', FunctionCall(NameRef('f2'), ['ack', 17]))) def testCall0(self): self.assertEqual(self.m['call0'], {'guk':42}) def testCall1(self): self.assertEqual(self.m['call1'], {'ack': 13}) def testCall2(self): self.assertEqual(self.m['call2'], {'froz':'ack', 'fuzz': 17})
def testOneArg(self): m = Map() m.put(KVPair('foo', NameRef('arg'))) f = Function(m, ['arg']) r = f.call(42) self.assertEqual(r, {'foo': 42})
class TestMap(unittest.TestCase): def setUp(self): self.m = Map() def testOnePair(self): self.m.put(KVPair('key', 'value')) self.assertEqual(self.m['key'], 'value') def testTwoPairs(self): self.m.put(KVPair(13, 'value')) self.m.put(KVPair('key', 42)) self.assertEqual(self.m[13], 'value') self.assertEqual(self.m['key'], 42) def testAssign(self): self.m['key'] = 34 self.assertEqual(self.m['key'], 34) def testLaterKeySupersedes(self): self.m.put(KVPair('key', 4)) self.m['key'] = 45 self.m.put(KVPair('key', 13)) self.assertEqual(self.m['key'], 13) def testMissingKeyisUndefined(self): self.assertEqual(self.m['I do not exist'], fern.primitives.Undefined) def testUndefinedValueDeletesKey(self): self.m['foo'] = 17 self.m['foo'] = fern.primitives.Undefined self.failIf('foo' in self.m) def testSetKeyDoesNotAddChildren(self): # we need to have a nice interface for changing keys by # mutating KVPairs self.m.put(KVPair('foo', 42)) self.m.put(KVPair('bar', 17)) self.m.put(KVPair('ggg', 'umm')) self.assertEqual(self.m['bar'], 17) self.assertEqual(len(self.m.children), 3) # now the good part self.m.set_key('bar', 13) self.assertEqual(self.m['bar'], 13) self.assertEqual(len(self.m.children), 3)
def setUp(self): self.m = Map()
def setUp(self): self.scope = Map() self.scope['var'] = True self.c = Conditional() self.scope.put(self.c)