Пример #1
0
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
Пример #2
0
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')
Пример #3
0
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)