test_core.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:deb-python-warlock 作者: openstack 项目源码 文件源码
def test_resolver(self):
        from jsonschema import RefResolver
        dirname = os.path.dirname(__file__)
        schemas_path = 'file://' + os.path.join(dirname, 'schemas/')
        resolver = RefResolver(schemas_path, None)

        country_schema_file = \
            open(os.path.join(dirname, 'schemas/') + 'country.json')
        person_schema_file = \
            open(os.path.join(dirname, 'schemas/') + 'person.json')

        country_schema = json.load(country_schema_file)
        person_schema = json.load(person_schema_file)
        Country = warlock.model_factory(country_schema, resolver)
        Person = warlock.model_factory(person_schema, resolver)

        england = Country(
            name="England",
            population=53865800,
            overlord=Person(
                title="Queen",
                firstname="Elizabeth",
                lastname="Windsor"
            )
        )
        expected = {
            'name': 'England',
            'population': 53865800,
            'overlord': {
                'title': 'Queen',
                'lastname': 'Windsor',
                'firstname': 'Elizabeth'
             }
        }
        self.assertEqual(england, expected)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号