def test_key(self): d = Dict() # 这个语句不是取值,而是设值,表示我往d里放了一个值,key是'key',值是'value' d['key'] = 'value' self.assertEqual(d.key, 'value') # 如果看不懂上面的。我这么写。你应该就懂了 d['a'] = 4 self.assertEqual(d.a, 4)
def test_init(self): d = Dict(a=1, b='test') self.assertEqual(d.a, 1) self.assertEqual(d.b, 'test') self.assertTrue(isinstance(d, dict))
def test_attrerror(self): d = Dict() with self.assertRaises(AttributeError): value = d.empty
def test_keyerror(self): d = Dict() with self.assertRaises(KeyError): value = d['empty']
def test_attr(self): d = Dict() d.key = 'value' self.assertTrue('key' in d) self.assertEqual(d['key'], 'value')
def test_key(self): d = Dict() d['key'] = 'value' self.assertEqual(d.key, 'value')
def test_attr(self): d = Dict() d.key = 'value' self.assertEqual(d.key, 'value')
def test_something(self): d = Dict(a=1,b='test') self.assertEqual(d.a, 1) self.assertEqual(d.b, 'test')