コード例 #1
0
    def __init__(
        self,
        values_type: Type[T_AC],
        items: Mapping[str, Any],
    ) -> None:
        """
        Initialize the dictionary.

        Args:
            values_type: a type for the items of the dict
            items: initial items to be added to the dict

        Raises:
            AttributesError: if an item is invalid
        """
        self.values_type = values_type
        errors = {}
        new_items: Dict[str, T_AC] = {}
        for key, item in items.items():
            try:
                if isinstance(item, values_type):
                    new_items[key] = item
                elif item is not None:
                    new_items[key] = self._init_item(item=item, )
            except BaseAttributeError as e:
                errors[key] = e
        if errors:
            raise AttributesError(
                message='Invalid items',
                context=self,
                errors=errors,
            )
        super().__init__(new_items)
コード例 #2
0
ファイル: github.py プロジェクト: yeswehack/ywh2bugtracker
    def validate(self) -> None:
        """
        Validate the container.

        # noqa: DAR401, DAR402

        Raises:
            AttributesError: if the container is not valid
        """
        super_error: Optional[AttributesError] = None
        try:
            super().validate()
        except AttributesError as e:
            super_error = e

        errors = {}
        if self.github_cdn_on:
            errors.update(self._ensure_login_password(), )

        if errors:
            if not super_error:
                super_error = AttributesError(
                    message='Validation error',
                    errors={},
                    context=self,
                )
            super_error.errors.update(errors)

        if super_error:
            raise super_error
コード例 #3
0
    def validate(self) -> None:
        """
        Validate the list.

        Raises:
            AttributesError: if the list is not valid
        """
        errors: Dict[str, BaseAttributeError] = {}
        for i, item in enumerate(self):
            if not isinstance(item, self.values_type):
                item_type = type(item)
                item_repr = repr(item)
                errors[str(i)] = InvalidAttributeError(
                    message=(f'Expecting {self.values_type} for item {i} ; ' +
                             f'got {item_type} ({item_repr})'),
                    context=self,
                )
            elif isinstance(item, Validatable):
                try:
                    item.validate()
                except BaseAttributeError as e:
                    errors[str(i)] = e
        if errors:
            raise AttributesError(
                message='Validation failed',
                errors=errors,
                context=self,
            )
コード例 #4
0
ファイル: root.py プロジェクト: yeswehack/ywh2bugtracker
 def _ensure_bugtrackers_name(
     self,
     trackers: Trackers,
     programs: Programs,
 ) -> Dict[str, AttributesError]:
     errors = {}
     for i, program in enumerate(programs):
         if not program.bugtrackers_name:
             continue
         for j, bugtracker_name in enumerate(program.bugtrackers_name):
             if bugtracker_name not in trackers:
                 errors[f'programs[{i}].bugtrackers_name[{j}]'] = AttributesError(
                     message=
                     f'Bugtracker not {repr(bugtracker_name)} declared in bugtrackers',
                     errors={},
                     context=self,
                 )
     return errors
コード例 #5
0
    def validate(self) -> None:
        """
        Validate the dictionary.

        Raises:
            AttributesError: if the list is not valid
        """
        errors: Dict[str, BaseAttributeError] = {}
        for key, container in self.items():
            try:
                container.validate()
            except BaseAttributeError as e:
                errors[key] = e
        if errors:
            raise AttributesError(
                message='Validation failed',
                errors=errors,
                context=self,
            )
コード例 #6
0
    def validate(self) -> None:
        """
        Validate the container.

        Raises:
            AttributesError: if the container is not valid
        """
        errors: Dict[str, BaseAttributeError] = {}
        for attribute, value in self._values.items():
            try:
                attribute.validate(value=value, )
            except BaseAttributeError as e:
                errors[attribute.name] = e
        for extra_key, _ in self._extra.items():
            errors[extra_key] = UnsupportedAttributeError(
                message='Unsupported attribute',
                context=self,
            )
        if errors:
            raise AttributesError(
                message='Validation failed',
                errors=errors,
                context=self,
            )
コード例 #7
0
ファイル: root.py プロジェクト: yeswehack/ywh2bugtracker
    def validate(self) -> None:
        """
        Validate the configuration.

        Raises:
            AttributesError: if the configuration is invalid

        # noqa: DAR401
        # noqa: DAR402
        """
        super_error: Optional[AttributesError] = None
        try:
            super().validate()
        except AttributesError as e:
            super_error = e

        errors = {}
        if self.yeswehack:
            errors.update(
                self._ensure_declared_trackers(
                    trackers=cast(Trackers, self.bugtrackers or {}),
                    yeswehack=cast(YesWeHackConfigurations, self.yeswehack
                                   or {}),
                ), )

        if errors:
            if not super_error:
                super_error = AttributesError(
                    message='Validation error',
                    errors={},
                    context=self,
                )
            super_error.errors.update(errors)

        if super_error:
            raise super_error