蟒蛇接口
interface-mixins的Python项目详细描述
若要创建接口,请向其传递接口名称和方法列表 名字。将创建一个类,该类为每个 指定方法名的数目:
AnInterface=Interface('AnInterface',['some','methods','the','interface','should','have'])
要使用此接口,只需从中继承:
classAClass(AnInterface):pass
我们还提供了一种创建抽象测试用例的方法来帮助测试对象 对着界面:
AbstractTestAnInterface=AbstractInterfaceTest('AbstractTestAnInterface',['some','methods','the','interface','should','have'])
这些测试可以通过创建从 抽象测试。这确保每个方法都是在aclass:
中实现的fromunittestimportTestCaseclassTestAClass(AbstractTestAnInterface,TestCase):defsetUp(self):self.obj=AClass()
也可以创建接口和 同时进行抽象接口测试。此外,还可以创建多个 使用以下习惯用法的接口[1]:
interfaces={'AnInterface':['some','methods','the','interface','should','have'],'AnotherInterface':['different','methods']}forinterface_name,methodsininterfaces.iteritems():interface_name+='Interface'globals()[interface_name]=Interface(interface_name,methods)test_name='AbstractTest'+interface_nameglobals()[test_name]=AbstractInterfaceTest(test_name,methods)
[1] | This isn’t very idiomatic Python. The use ^{tt1}$ is ugly. This is just an idiom for using this library. I’m not sure I like it. |