Skip to content

Commit

Permalink
ruff linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopamaral committed Feb 15, 2024
1 parent dbdd011 commit 2d39177
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions singer_sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,7 @@ def __init__(self, error_message: str, record: dict) -> None:
super().__init__(f"Record Message Validation Error: {error_message}")
self.error_message = error_message
self.record = record


class InvalidFlatteningRecordsParameter(Exception):
"""Raised when the flattening_records parameter is invalid."""
7 changes: 4 additions & 3 deletions singer_sdk/helpers/_flattening.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import inflection
import simplejson as json

from exceptions import InvalidFlatteningRecordsParameter

DEFAULT_FLATTENING_SEPARATOR = "__"


Expand Down Expand Up @@ -376,9 +378,8 @@ def flatten_record(
Returns:
A flattened version of the record.
"""
assert (flattened_schema is not None) or (
max_level is not None
), "flattened_schema or max_level must be provided"
if (flattened_schema is not None) or (max_level is not None):
raise InvalidFlatteningRecordsParameter("flattened_schema or max_level must be provided")
max_level = max_level or 0

return _flatten_record(
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_flattening.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from exceptions import InvalidFlatteningRecordsParameter
from singer_sdk.helpers._flattening import flatten_record


Expand Down Expand Up @@ -38,7 +39,7 @@
id="flattened schema not provided",
),
pytest.param(
None, None, None, AssertionError, id="no schema or max level provided"
None, None, None, InvalidFlatteningRecordsParameter, id="no schema or max level provided"
),
],
)
Expand All @@ -57,5 +58,4 @@ def test_flatten_record(flattened_schema, max_level, expected, expected_exceptio
result = flatten_record(
record, max_level=max_level, flattened_schema=flattened_schema
)
print(result)
assert expected == result

0 comments on commit 2d39177

Please sign in to comment.