Beispiel #1
0
 def __init__(self,
              name: str,
              service_name: ServiceName,
              boto3_client: BaseClient,
              docstring: str = ""):
     super().__init__(name=name, docstring=docstring)
     self.service_name = service_name
     self.boto3_client = boto3_client
     self.exceptions_class = ClassRecord(name="Exceptions")
     self.client_error_class = ClassRecord(
         name="BotocoreClientError",
         attributes=[
             Attribute("MSG_TEMPLATE", Type.str),
         ],
         bases=[TypeClass(BaseException)],
         methods=[
             Method(
                 name="__init__",
                 arguments=[
                     Argument("self", None),
                     Argument(
                         "error_response",
                         TypeSubscript(Type.Dict, [Type.str, Type.Any])),
                     Argument("operation_name", Type.str),
                 ],
                 return_type=Type.none,
                 body_lines=[
                     "self.response: Dict[str, Any]",
                     "self.operation_name: str",
                 ],
             ),
         ],
     )
Beispiel #2
0
class TestClassRecord:
    class_record: ClassRecord

    def setup_method(self):
        self.class_record = ClassRecord(
            name="Name",
            methods=[
                Method(
                    name="my_method",
                    arguments=[
                        Argument("self", None),
                        Argument("my_str", Type.str, TypeConstant("test")),
                        Argument("lst", Type.ListAny),
                    ],
                    return_type=Type.none,
                )
            ],
            attributes=[Attribute("attr", Type.Any, Type.none)],
            bases=[Type.Any],
            docstring="my doc",
            use_alias=True,
        )

    def test_init(self) -> None:
        assert self.class_record.name == "Name"
        assert self.class_record.alias_name == "_Name"

        self.class_record.use_alias = False
        with pytest.raises(ValueError):
            self.class_record.alias_name

    def test_render_alias(self) -> None:
        assert self.class_record.render_alias() == "_Name = Name"

    def test_get_types(self) -> None:
        assert self.class_record.get_types() == {
            Type.Any,
            Type.none,
            Type.List,
            Type.str,
            TypeConstant("test"),
        }

    def test_get_required_import_records(self) -> None:
        assert self.class_record.get_required_import_records() == {
            ImportRecord(ImportString("typing"), "Any"),
            ImportRecord(ImportString("typing"), "List"),
        }

    def test_get_internal_imports(self) -> None:
        assert self.class_record.get_internal_imports() == []
Beispiel #3
0
 def setup_method(self):
     self.class_record = ClassRecord(
         name="Name",
         methods=[
             Method(
                 name="my_method",
                 arguments=[
                     Argument("self", None),
                     Argument("my_str", Type.str, TypeConstant("test")),
                     Argument("lst", Type.ListAny),
                 ],
                 return_type=Type.none,
             )
         ],
         attributes=[Attribute("attr", Type.Any, Type.none)],
         bases=[Type.Any],
         use_alias=True,
     )
 def _get_resource_meta_class(self, service_name: ServiceName) -> ClassRecord:
     return ClassRecord(
         name=f"{service_name.class_name}ResourceMeta",
         bases=[
             ExternalImport(
                 source=ImportString("boto3", "resources", "base"),
                 name="ResourceMeta",
             )
         ],
         attributes=[Attribute("client", self._get_client_import(service_name))],
     )
 def __init__(
         self,
         data: type[BasePackageData],
         session_class: ClassRecord | None = None,
         service_names: Iterable[ServiceName] = tuple(),
         service_packages: Iterable[ServicePackage] = tuple(),
         init_functions: Iterable[Function] = tuple(),
 ):
     super().__init__(data)
     self.session_class = session_class or ClassRecord("Session")
     self.service_names = list(service_names)
     self.service_packages = list(service_packages)
     self.init_functions = list(init_functions)
Beispiel #6
0
 def __init__(
         self,
         name: str = BOTO3_STUBS_NAME,
         pypi_name: str = BOTO3_STUBS_NAME,
         session_class: Optional[ClassRecord] = None,
         service_names: Iterable[ServiceName] = tuple(),
         service_packages: Iterable[ServicePackage] = tuple(),
         init_functions: Iterable[Function] = tuple(),
 ):
     super().__init__(name=name, pypi_name=pypi_name)
     self.session_class = session_class or ClassRecord("Session")
     self.service_names = list(service_names)
     self.service_packages = list(service_packages)
     self.init_functions = list(init_functions)
Beispiel #7
0
class Client(ClassRecord):
    """
    Boto3 Client.
    """

    name: str = "Client"
    alias_name: str = "Client"
    service_name: ServiceName = ServiceNameCatalog.ec2
    boto3_client: BaseClient = None
    exceptions_class: ClassRecord = field(
        default_factory=lambda: ClassRecord(name="Exceptions"))

    def __hash__(self) -> int:
        return hash(self.service_name)

    def get_all_names(self) -> List[str]:
        return [self.name]