def test_attrerror(self): d = Dict() with self.assertRaises(AttributeError): value = d.empty
def test_attr(self): d = Dict() d['key'] = 'value' self.assertTrue('key' in d) self.assertEqual(d['key'], 'value')
def test_keyerror(self): d = Dict() with self.assertRaises(KeyError): value = d['empty']
def test_init(self): d = Dict(a=1, b='test') self.assertEqual(d.a, 1) # 测试key是否正确 self.assertEqual(d.b, 'test') # 测试value是否正确 self.assertTrue(isinstance(d, dict)) #测试d对象是否是dict
def test_key(self): d = Dict() d['key'] = 'value' self.assertEqual(d.key, 'value')
def test_key(self): d = Dict() d['hong'] = 1 self.assertEqual(d.hong,1)
def test_init(self): d = Dict(a=1, b='test') self.assertEquals(d.a, 1) self.assertEquals(d.b, 'test') self.assertTrue(isinstance(d, dict))
def test_attr(self): d = Dict() d.fox = 'fox' self.assertEqual(d['fox'],'fox')
def test_keyerror(self): d = Dict() with self.assertRaises(KeyError): value = d['none'] with self.assertRaises(AttributeError): value = d.none
def test_init(self): d = Dict(a=1, b='test') # 断言assertEqual() 断言函数返回的结果与1相等 self.assertEqual(d.a, 1) self.assertEqual(d.b, 'test') self.assertTrue(isinstance(d, dict))
def test_init(self): a, b = 1, 'test' d = Dict(a=a, b=b) self.assertEqual(d.a, a, ('value is err,d.a not equal %s', a)) self.assertEqual(d.b, 'test', ('value is err,d.a not equal %s', a)) self.assertTrue(isinstance(d, Dict))
def test_attr_error(self): d = Dict() with self.assertRaises(AttributeError): value = d.notExistKey
def test_key_error(self): d = Dict() with self.assertRaises(KeyError): value = d['notExistKey']
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))