Skip to content

Commit

Permalink
✅(tests) unify sync/async tests for lrs data backend
Browse files Browse the repository at this point in the history
The behavior of the sync and async versions of the lrs data backend
are very similar.
Thus, to keep both implementations inline, we tests both of them in
the same file.
  • Loading branch information
SergioSim committed Nov 16, 2023
1 parent f21be1a commit da71183
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 205 deletions.
27 changes: 6 additions & 21 deletions src/ralph/backends/data/lrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ralph.backends.lrs.base import LRSStatementsQuery
from ralph.conf import BaseSettingsConfig, HeadersParameters
from ralph.exceptions import BackendException
from ralph.utils import async_parse_dict_to_bytes, iter_by_batch, parse_to_dict
from ralph.utils import iter_by_batch, parse_dict_to_bytes, parse_to_dict


class LRSHeaders(HeadersParameters):
Expand Down Expand Up @@ -159,7 +159,7 @@ def _read_bytes(
) -> Iterator[bytes]:
"""Method called by `self.read` yielding bytes. See `self.read`."""
statements = self._read_dicts(query, target, chunk_size, ignore_errors)
yield from async_parse_dict_to_bytes(
yield from parse_dict_to_bytes(
statements, self.settings.LOCALE_ENCODING, ignore_errors, self.logger
)

Expand Down Expand Up @@ -202,9 +202,9 @@ def _read_dicts(
for statement in statements_generator:
yield statement
except HTTPError as error:
msg = "Failed to fetch statements."
self.logger.error("%s. %s", msg, error)
raise BackendException(msg, *error.args) from error
msg = "Failed to fetch statements: %s"
self.logger.error(msg, error)
raise BackendException(msg % (error,)) from error

def write( # noqa: PLR0913
self,
Expand All @@ -213,8 +213,6 @@ def write( # noqa: PLR0913
chunk_size: Optional[int] = None,
ignore_errors: bool = False,
operation_type: Optional[BaseOperationType] = None,
simultaneous: bool = False,
max_num_simultaneous: Optional[int] = None,
) -> int:
"""Write `data` records to the `target` endpoint and return their count.
Expand All @@ -231,21 +229,8 @@ def write( # noqa: PLR0913
operation_type (BaseOperationType or None): The mode of the write operation.
If `operation_type` is `None`, the `default_operation_type` is used
instead. See `BaseOperationType`.
simultaneous (bool): If `True`, chunks requests will be made concurrently.
If `False` (default), chunks will be sent sequentially
max_num_simultaneous (int or None): If simultaneous is `True`, the maximum
number of chunks to POST concurrently. If `None` (default), no limit is
set.
"""
return super().write(
data,
target,
chunk_size,
ignore_errors,
operation_type,
simultaneous,
max_num_simultaneous,
)
return super().write(data, target, chunk_size, ignore_errors, operation_type)

def _write_bytes( # noqa: PLR0913
self,
Expand Down
Loading

0 comments on commit da71183

Please sign in to comment.