コード例 #1
0
ファイル: test_core.py プロジェクト: rcallen89/airbyte
    def _validate_field_appears_at_least_once_in_stream(
            self, records: List, schema: Dict):
        """
        Get all possible schema paths, then diff with existing record paths.
        In case of `oneOf` or `anyOf` schema props, compare only choice which is present in records.
        """
        expected_paths = get_expected_schema_structure(schema,
                                                       annotate_one_of=True)
        expected_paths = set(flatten(tuple(expected_paths)))

        for record in records:
            record_paths = set(get_object_structure(record))
            paths_to_remove = {
                path
                for path in expected_paths
                if re.sub(r"\([0-9]*\)", "", path) in record_paths
            }
            for path in paths_to_remove:
                path_parts = re.split(r"\([0-9]*\)", path)
                if len(path_parts) > 1:
                    expected_paths -= {
                        path
                        for path in expected_paths if path_parts[0] in path
                    }
            expected_paths -= paths_to_remove

        return sorted(list(expected_paths))
コード例 #2
0
    def gen_type_check(pytypes):
        pytypes = _utils.flatten(pytypes)

        def type_check(checker, instance):
            if isinstance(instance, bool):
                if bool not in pytypes:
                    return False
            return isinstance(instance, pytypes)

        return type_check
コード例 #3
0
ファイル: validators.py プロジェクト: Julian/jsonschema
    def gen_type_check(pytypes):
        pytypes = _utils.flatten(pytypes)

        def type_check(checker, instance):
            if isinstance(instance, bool):
                if bool not in pytypes:
                    return False
            return isinstance(instance, pytypes)

        return type_check
コード例 #4
0
        def is_type(self, instance, type):
            if type not in self._types:
                raise UnknownType(type, instance, self.schema)
            pytypes = self._types[type]

            # bool inherits from int, so ensure bools aren't reported as ints
            if (isinstance(instance, bool) and issubclass(int, pytypes)
                    and bool not in _utils.flatten(pytypes)):
                return False
            return isinstance(instance, pytypes)
コード例 #5
0
ファイル: validators.py プロジェクト: roryma/jsonschema
        def is_type(self, instance, type):
            if type not in self._types:
                raise UnknownType(type, instance, self.schema)
            pytypes = self._types[type]

            # bool inherits from int, so ensure bools aren't reported as ints
            if isinstance(instance, bool):
                pytypes = _utils.flatten(pytypes)
                is_number = any(issubclass(pytype, numbers.Number) for pytype in pytypes)
                if is_number and bool not in pytypes:
                    return False
            return isinstance(instance, pytypes)
コード例 #6
0
        def is_type(self, instance, type):
            if type not in self._types:
                raise UnknownType(type, instance, self.schema)
            pytypes = self._types[type]

            # bool inherits from int, so ensure bools aren't reported as ints
            if isinstance(instance, bool):
                pytypes = _utils.flatten(pytypes)
                is_number = any(
                    issubclass(pytype, numbers.Number) for pytype in pytypes)
                if is_number and bool not in pytypes:
                    return False
            return isinstance(instance, pytypes)