Python--unittest

Source: Internet
Author: User

#https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 00143191629979802b566644aa84656b50cd484ec4a7838000

mydict.py

#!/usr/bin/env Python3#-*-coding:utf-8-*-"""Created on Sat Jan 16:32:34 2018@author:k"""classDict (Dict):def __init__(self,**kw): Super ().__init__(**kw)def __getattr__(Self,key):Try:            returnSelf[key]exceptKeyerror:RaiseAttributeerror (R"' Dict ' object has no attribute '%s '"%key)def __setattr__(Self,key,value): Self[key]=value

test.py

#!/usr/bin/env Python3#-*-coding:utf-8-*-"""Created on Sat Jan 22:51:23 2018@author:k"""ImportUnitTest fromMydictImportDictclasstestdict (unittest. TestCase):defTest_init (self): D= Dict (a=1,b='Test') self.assertequal (D.A,1) self.assertequal (d.b,'Test') self.asserttrue (isinstance (d,dict) )defTest_key (self): D=Dict () d['Key'] ='value'self.assertequal (D.key,'value')            deftest_attr (self): D=Dict () D.key='value'Self.asserttrue ('Key' inchd) self.assertequal (d['Key'],'value')            defTest_keyerror (self): D=Dict () with Self.assertraises (keyerror): Value= d['Empty']    defTest_attrerror (self): D=Dict () with Self.assertraises (attributeerror): Value=D.emptyif __name__=='__main__': Unittest.main ()

Python  test.py

Python--unittest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.