Commit 52432e27 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño

Testcase module typed and formatted.

- Type hints for testcase module are completed.
- Type comments (to be compatible with Python 2) have been added to
  other parts of slapos.core only when necessary to achieve full type
  checking in the testcase module, with Pyright in strict mode.
- Docstrings added/completed for the testcase module.
- Source is formatted with ruff.

See merge request !693
parent 2e08776e
Pipeline #37339 failed with stage
in 0 seconds
......@@ -3,4 +3,4 @@ include slapos/proxy/schema.sql
include slapos/slapos-client.cfg.example
include slapos/slapos-proxy.cfg.example
include slapos/slapos.cfg.example
recursive-include slapos *.in *.txt *.xsd *.rst
recursive-include slapos *.in *.txt *.xsd *.rst py.typed
[tool.ruff]
line-length = 80
indent-width = 2
\ No newline at end of file
......@@ -211,6 +211,7 @@ class SlapPopen(subprocess.Popen):
def md5digest(url):
# type: (str) -> str
return hashlib.md5(url.encode('utf-8')).hexdigest()
......
......@@ -45,6 +45,11 @@ import warnings
import json
import six
try:
from typing import Mapping, Sequence
except ImportError: # XXX to be removed once we depend on typing
pass
from .exception import ResourceNotReady, ServerError, NotFoundError, \
ConnectionError
from .hateoas import SlapHateoasNavigator, ConnectionHelper
......@@ -178,6 +183,7 @@ class SoftwareRelease(SlapDocument):
return self._computer_guid
def getURI(self):
# type: () -> str
if not self._software_release:
raise NameError('software_release has not been defined.')
else:
......@@ -384,6 +390,7 @@ class Computer(SlapDocument):
@_syncComputerInformation
def getComputerPartitionList(self):
# type: (...) -> Sequence[ComputerPartition]
for computer_partition in self._computer_partition_list:
computer_partition._connection_helper = self._connection_helper
computer_partition._hateoas_navigator = self._hateoas_navigator
......@@ -596,6 +603,7 @@ class ComputerPartition(SlapRequester):
return software_instance
def getId(self):
# type: (...) -> str
if not getattr(self, '_partition_id', None):
raise ResourceNotReady()
return self._partition_id
......@@ -629,9 +637,11 @@ class ComputerPartition(SlapRequester):
return software_type
def getInstanceParameterDict(self):
# type: (...) -> Mapping[str, object]
return getattr(self, '_parameter_dict', None) or {}
def getConnectionParameterDict(self):
# type: (...) -> Mapping[str, str]
connection_dict = getattr(self, '_connection_dict', None)
if connection_dict is None:
# XXX Backward compatibility for older slapproxy (<= 1.0.0)
......@@ -640,6 +650,7 @@ class ComputerPartition(SlapRequester):
return connection_dict or {}
def getSoftwareRelease(self):
# type: (...) -> SoftwareRelease
"""
Returns the software release associate to the computer partition.
"""
......
......@@ -44,7 +44,7 @@ except ImportError:
import subprocess
try:
from typing import TYPE_CHECKING, Optional, Iterable, Dict, Union
from typing import TYPE_CHECKING, Iterable, Mapping, Optional, Union
if TYPE_CHECKING:
import subprocess
except ImportError: # XXX to be removed once we depend on typing
......@@ -501,7 +501,13 @@ class StandaloneSlapOS(object):
self._initBaseDirectory(software_root, instance_root, shared_part_root)
def _initBaseDirectory(self, software_root, instance_root, shared_part_root):
def _initBaseDirectory(
self,
software_root, # type: str
instance_root, # type: str
shared_part_root, # type: str
):
# type: (...) -> None
"""Create the directory after checking it's not too deep.
"""
base_directory = self._base_directory
......@@ -619,10 +625,12 @@ class StandaloneSlapOS(object):
def format(
self,
partition_count,
ipv4_address,
ipv6_address,
partition_base_name="slappart"):
partition_count, # type: int
ipv4_address, # type: str
ipv6_address, # type: str
partition_base_name="slappart", # type: str
):
# type: (...) -> None
"""Creates `partition_count` partitions.
All partitions have the same `ipv4_address` and use the current system
......@@ -728,7 +736,13 @@ class StandaloneSlapOS(object):
self._logger.error(e.output)
raise
def supply(self, software_url, computer_guid=None, state="available"):
def supply(
self,
software_url, # type: str
computer_guid=None, # type: str | None
state="available", # type: str
):
# type: (...) -> None
"""Supply a software, see ISupply.supply
Software can only be supplied on this embedded computer.
......@@ -742,14 +756,15 @@ class StandaloneSlapOS(object):
)
def request(
self,
software_release,
partition_reference,
software_type=None,
shared=False,
partition_parameter_kw=None,
filter_kw=None,
state=None):
self,
software_release, # type: str
partition_reference, # type: str
software_type=None, # type: str | None
shared=False, # type: bool
partition_parameter_kw=None, # type: Mapping[str, object] | None
filter_kw=None, # type: Mapping[str, object] | None
state=None, # type: str | None
):
"""Request an instance, see IRequester.request
Instance can only be requested on this embedded computer.
......
This diff is collapsed.
......@@ -46,7 +46,7 @@ from ..grid.utils import getPythonExecutableFromSoftwarePath
try:
import typing
if typing.TYPE_CHECKING:
from PIL import Image # pylint:disable=unused-import
from PIL.Image import Image # pylint:disable=unused-import
from .testcase import SlapOSInstanceTestCase
except ImportError:
pass
......
......@@ -94,8 +94,12 @@ class SafeXMLUnmrshaller(Unmarshaller, object):
loads = SafeXMLUnmrshaller().loads
def mkdir_p(path, mode=0o700):
"""\
def mkdir_p(
path, # type: str
mode=0o700, # type: int
):
# type: (...) -> None
"""
Creates a directory and its parents, if needed.
NB: If the directory already exists, it does not change its permission.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment