<commit_before># -*- coding: utf-8 -*-

""" Unit test for pyKwalify - Rule """

# python std lib
import unittest

# 3rd party imports
import pytest

# pyKwalify imports
import pykwalify
from pykwalify.errors import RuleError, SchemaConflict
from pykwalify.rule import Rule


class TestRule(unittest.TestCase):

    def setUp(self):
        pykwalify.partial_schemas = {}

    def test_schema(self):
        # Test that when using both schema; and include tag that it throw an error because schema; tags should be parsed via Core()
        with pytest.raises(RuleError) as r:
            Rule(schema={"schema;str": {"type": "map", "mapping": {"foo": {"type": "str"}}}, "type": "map", "mapping": {"foo": {"include": "str"}}})
        assert str(r.value) == "<RuleError: error code 4: Schema is only allowed on top level of schema file: Path: '/'>"
        assert r.value.error_key == 'schema.not.toplevel'

    def test_unkknown_key(self):
        # Test that providing an unknown key raises exception
        with pytest.raises(RuleError) as r:
            Rule(schema={"type": "str", "foobar": True})
        assert str(r.value) == "<RuleError: error code 4: Unknown key: foobar found: Path: '/'>"
        assert r.value.error_key == 'key.unknown'

    def test_matching_rule(self):
        # Test that exception is raised when a invalid matching rule is used
        with pytest.raises(RuleError) as r:
            Rule(schema={"type": "map", "matching-rule": "foobar", "mapping": {"regex;.+": {"type": "seq", "sequence": [{"type": "str"}]}}})<commit_msg>Fix broken tests on py3+ versions<commit_after># -*- coding: utf-8 -*-

""" Unit test for pyKwalify - Rule """

# python std lib
import unittest

# 3rd party imports
import pytest

# pyKwalify imports
import pykwalify
from pykwalify.errors import RuleError, SchemaConflict
from pykwalify.rule import Rule
from pykwalify.compat import unicode


class TestRule(unittest.TestCase):

    def setUp(self):
        pykwalify.partial_schemas = {}

    def test_schema(self):
        # Test that when using both schema; and include tag that it throw an error because schema; tags should be parsed via Core()
        with pytest.raises(RuleError) as r:
            Rule(schema={"schema;str": {"type": "map", "mapping": {"foo": {"type": "str"}}}, "type": "map", "mapping": {"foo": {"include": "str"}}})
        assert str(r.value) == "<RuleError: error code 4: Schema is only allowed on top level of schema file: Path: '/'>"
        assert r.value.error_key == 'schema.not.toplevel'

    def test_unkknown_key(self):
        # Test that providing an unknown key raises exception
        with pytest.raises(RuleError) as r:
            Rule(schema={"type": "str", "foobar": True})
        assert str(r.value) == "<RuleError: error code 4: Unknown key: foobar found: Path: '/'>"
        assert r.value.error_key == 'key.unknown'

    def test_matching_rule(self):
        # Test that exception is raised when a invalid matching rule is used
        with pytest.raises(RuleError) as r:
            Rule(schema={"type": "map", "matching-rule": "foobar", "mapping": {"regex;.+": {"type": "seq", "sequence": [{"type": "str"}]}}})
{'fraction_non_alphanumeric': 0.1451562006942253, 'fraction_numerical': 0.002840012622278321, 'mean_word_length': 3.4335664335664338, 'pattern_counts': {'":': 36, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5960206', 'n_tokens_mistral': 987, 'n_tokens_neox': 953, 'n_words': 324}