用于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第三方库


热门话题
记录打印JAVA控制台客户端的SOAP消息   java camunda异常找不到id为空的任务任务   java如何将json文件转换为以下格式{“Description”:“Cmd是一个开源工具”,数据{“别名”:“xCmd”,“软件”:“xCmd”,“_raw”:“}   java在Hibernate期间清理连接池花费的时间太长   用Java实现基本FTP客户端的socket   Java生成文本文件格式的格式化报告   java hibernate createQuery vs get   TriggerBuilder<Trigger>类型中带有Schedule(ScheduleBuilder<SBT>)的java不适用于参数(可变触发器)   JavaSwing:GlassPane防止鼠标指针更改   java使用for循环创建上下三角形   maven“Java Home”在cmd中运行“mvn v”时不显示   java客户端无法联机连接到服务器   java面向对象程序设计问题   java如何按升序和降序对hashmap数据进行排序   java为什么JPanel从不调用reapint