用于json模式验证的PyHamcrest matchers扩展

json-schema-matchers的Python项目详细描述


json架构匹配器

用于json模式验证的PyHamcrest matchers扩展

架构应该按照Draft-07 to 2019-09版本的语法实现。 架构示例:

single_user_schema={"title":"Single User Info","type":"object","properties":{"first_name":{"type":"string","minLength":3},"last_name":{"type":"string","minLength":3},"phone_number":{"type":"number"}},"required":["first_name","last_name",]}all_users_info_schema={"title":"All Users Info","type":"array","items":single_user_schema}

然后您可以将matches_json_schema匹配器与所有hamcrest匹配器一起使用:

^{pr2}$

如果验证失败,匹配器将迭代返回所有不匹配项:

users_list_json_obj=[{"first_name":'John',"last_name":"Johnson","phone_number":'123456789'},{"first_name":None,"last_name":'Je'}]assert_that(users_list_json_obj,matches_json_schema(all_users_info_schema))
AssertionError:Expected:JSONobjectshouldmatchschema"All Users Info"but:mismatchesoccurred:'123456789'isnotoftype'number'Failedvalidating'type'inschema['items']['properties']['phone_number']:{'type':'number'}Oninstance[0]['phone_number']:'123456789'------------'Je'istooshortFailedvalidating'minLength'inschema['items']['properties']['last_name']:{'minLength':3,'type':'string'}Oninstance[1]['last_name']:'Je'------------Noneisnotoftype'string'Failedvalidating'type'inschema['items']['properties']['first_name']:{'minLength':3,'type':'string'}Oninstance[1]['first_name']:None------------

依赖关系:

jsonschema==3.2.0
PyHamcrest==2.0.2

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

推荐PyPI第三方库


热门话题
javascript节点js require()和Rhino Shell load()之间的区别是什么?   While循环中的java If语句   java GXT如何在XTemplate中显示treeobject?   如何将黑白图像加载到二进制文件中?   java ORMLite不知道如何存储班级航班。扫描仪。modelFX。机场航空公司的AirlineFx。使用另一个类或自定义持久器   java组织。阿帕奇。德比。客户是SqlException JSP和JSTL查询   spring如何将clob数据分配给java变量   java从上的表获取数据(Spring)   javaphp使用Exec执行带有用户定义参数的Jar文件   java jsonschema2pojo:引用相同类型的对象   使用原语从Scala调用Java vararg方法   java ClassNotFoundException:ClientBuilder Jersey 2.25.1 Tomcat 9.0   Android(Java)cr_BindingManager:无法调用determinedVisibility()从未看到pid的连接:   Java使用LocalTime类比较没有日期的时间   Java如何初始化对象的参数?