示例#1
0
 def test_getsetattr(self):
     life = _RecursiveAttrDict(self.INITIAL)
     life['universe.galaxy'] = 'milky way'
     self.assertEqual(life.universe.galaxy, 'milky way')
     life['universe.a.b.c.d.e'] = 4
     self.assertEqual(life.universe.a.b.c.d.e, 4)
     self.assertEqual(life.universe.a.b.c.d, {'e': 4})
     self.assertEqual(life['universe.a.b.c.d.e'], 4)
示例#2
0
 def test_builtin_getsetattr(self):
     life = _RecursiveAttrDict(self.INITIAL)
     self.assertEqual(getattr(life.bigbang.stars, 'planet'), 'earth')
     setattr(life, 'planet.stars', 'sol')
     self.assertEqual(getattr(life, 'planet.stars'), 'sol')
示例#3
0
 def test_init(self):
     life = _RecursiveAttrDict(self.INITIAL)
     self.assertEqual(life.bigbang.stars.planet, 'earth')
     self.assertEqual(life.bigbang.center, 'sol')
     self.assertEqual(life.bigbang, life['bigbang'])
示例#4
0
 def test_contains(self):
     life = _RecursiveAttrDict(self.INITIAL)
     self.assertTrue('bigbang.stars.planet' in life)
     self.assertFalse('bigbang.stars.planet.earth' in life)
     self.assertFalse('bigbang.d.x' in life)