Example #1
0
def test_tojson():
    """
    Test the ported tojson filter. Non-ascii unicode content should be
    dumped with ensure_ascii=True.
    """
    data = {"Non-ascii words": ["süß", "спам", "яйца"]}
    result = tojson(data)
    expected = ('{"Non-ascii words": ["s\\u00fc\\u00df", '
                '"\\u0441\\u043f\\u0430\\u043c", '
                '"\\u044f\\u0439\\u0446\\u0430"]}')
    assert result == expected, result
Example #2
0
def test_tojson_should_ascii_sort_keys_when_told():
    data = {"z": "zzz", "y": "yyy", "x": "xxx"}
    expected = '{"x": "xxx", "y": "yyy", "z": "zzz"}'

    actual = tojson(data, sort_keys=True)
    assert actual == expected
Example #3
0
            'errors': errors,
            'warnings': warnings,
            'count':    count,
            'passed':   passed,
            'failed':   failed
        }
    })
    return ret


if __name__ == "__main__":
    s = {
        "definitions": {
            "roles-config": {
                "propertyNames": "$ref:role-name", 
                "properties": {
                    "purpose": "$string"
                }
            }, 
            "role-name": "$pattern:^([A-Za-z0-9][-_A-Za-z0-9]*)$"
        }, 
        "$schema": "http://json-schema.org/draft-07/schema#", 
        "$ref": "#/definitions/roles-config"
    }

    sc=SchemaComplexifier()
    
    print("test results:")
    print(tojson(sc.complexify(s)))