蟒蛇接口

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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java:在迭代器类型(接口/实现类)之间转换?   java“Click Method”不断返回“Stale Element Exceoption”?   Android应用程序/进程的java生命周期?   java在发布消息时收到“无法识别的Windowssocket错误:0:recv失败”   java如何返回第二个值   java将基本授权头添加到一些请求中   使用改型安卓的java Post请求错误   PropertyPlaceHolderConfigure位置内的java Spring占位符   java是导入com的工具。谷歌。安卓gms。gcm无法解决,Google Play服务已经安装   java如何获取JSON数据的多个可选值?   java如何使用ApachePOI从word中的形状读取文本   安卓 java。Eclipse中的lang.NoClassDefFoundError,但不适用于Ant   如何在Java中用stream()将Map<v1,Set<v2>>转换为Map<v2,Set<v1>>   循环在java中循环时,如何从数组列表中删除某些内容?