Skip to content

Commit

Permalink
remove unused setattr function, and improve unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfromearth committed Jul 1, 2024
1 parent 9780428 commit 159d542
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
13 changes: 0 additions & 13 deletions concatenator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,3 @@ def __getattr__(name): # type: ignore
return _options.coord_delim
else:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __setattr__(name, value): # type: ignore
"""Module-level setattr to handle setting of `concatenator.options`.
Other unhandled attributes raise as `AttributeError` as expected.
"""
if name == "group_delim":
_options.group_delim = value
elif name == "coord_delim":
_options.coord_delim = value
else:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
20 changes: 18 additions & 2 deletions tests/unit/test_attribute_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,24 @@ def test_coordinate_attribute_regrouping():
)


def test_concatenator_options_access():
def test_concatenator_options_getting():
assert concatenator.group_delim == "__"
assert concatenator.coord_delim == " "
assert concatenator.__options__.group_delim == "__"
with pytest.raises(AttributeError):
_ = concatenator.unknown_attribute
_ = concatenator.nonexistent_attribute


def test_concatenator_options_setting():
"""Test setting attributes for the concatenator module.
Note that currently, new attributes can be defined dynamically.
"""
concatenator.group_delim = "%"
assert concatenator.group_delim == "%"

concatenator.coord_delim = "---"
assert concatenator.coord_delim == "---"

concatenator.nonexistent_attribute = "---"
assert concatenator.nonexistent_attribute == "---"

0 comments on commit 159d542

Please sign in to comment.