Skip to content

Commit

Permalink
chore: Do not add methods to warning classes per style guide. Use war…
Browse files Browse the repository at this point in the history
…nings.warn(..., category=...) style.
  • Loading branch information
jpmckinney committed May 9, 2024
1 parent f2b9235 commit 41644b3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 41 deletions.
5 changes: 3 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Changelog
=========

Unreleased
----------
0.7.0 (2024-05-08)
------------------

Changed
~~~~~~~

- :func:`ocdsmerge.util.get_tags` raises an error if it encounters an HTTP error.
- :exc:`ocdsmerge.exceptions.DuplicateIdValueWarning` has no custom attributes.
- Drop support for Python 3.6 and 3.7.

Added
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
author = "Open Contracting Partnership"

# The short X.Y version
version = "0.6.6"
version = "0.7.0"
# The full version, including alpha/beta/rc tags
release = version

Expand Down
11 changes: 0 additions & 11 deletions ocdsmerge/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from typing import Tuple


class OCDSMergeError(Exception):
"""Base class for exceptions from within this package"""

Expand Down Expand Up @@ -38,11 +35,3 @@ class OCDSMergeWarning(UserWarning):

class DuplicateIdValueWarning(OCDSMergeWarning):
"""Used when at least two objects in the same array have the same value for the 'id' field"""

def __init__(self, path: Tuple[str, ...], id, message: str):
self.path = path
self.id = id
self.message = message

def __str__(self) -> str:
return str(self.message)
6 changes: 4 additions & 2 deletions ocdsmerge/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ def _enumerate(
if default_path not in identifiers:
identifiers[default_path] = key
elif identifiers[default_path] != key:
warnings.warn(DuplicateIdValueWarning(rule_path, default_key, 'Multiple objects have the `id` '
f"value {default_key!r} in the `{'.'.join(map(str, rule_path))}` array"))
warnings.warn(
f'Multiple objects have the `id` value {default_key!r} in the `{".".join(map(str, rule_path))}` array',
category=DuplicateIdValueWarning,
)

yield new_key, value

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ocdsmerge
version = 0.6.6
version = 0.7.0
author = Open Contracting Partnership
author_email = data@open-contracting.org
license = BSD
Expand Down
28 changes: 4 additions & 24 deletions tests/test_collisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ def test_warn(empty_merger):
assert len(records) == 2

for i, record in enumerate(records):
message = string.format(fields[i])

assert record.message.path == ('nested', fields[i],)
assert record.message.id == '1'
assert record.message.message == message
assert str(record.message) == message
assert str(record.message) == string.format(fields[i])


def test_raise(empty_merger):
Expand All @@ -34,12 +29,7 @@ def test_raise(empty_merger):
warnings.filterwarnings('error', category=DuplicateIdValueWarning)
empty_merger.create_compiled_release(releases)

message = "Multiple objects have the `id` value '1' in the `nested.identifierMerge` array"

assert excinfo.value.path == ('nested', 'identifierMerge',)
assert excinfo.value.id == '1'
assert excinfo.value.message == message
assert str(excinfo.value) == message
assert str(excinfo.value) == "Multiple objects have the `id` value '1' in the `nested.identifierMerge` array"


def test_ignore(empty_merger):
Expand All @@ -64,12 +54,7 @@ def test_merge_by_position():
assert len(records) == 4

for i, record in enumerate(records):
message = string.format(fields[i])

assert record.message.path == ('nested', fields[i],)
assert record.message.id == '1'
assert record.message.message == message
assert str(record.message) == message
assert str(record.message) == string.format(fields[i])


def test_append():
Expand All @@ -86,12 +71,7 @@ def test_append():
assert len(records) == 4

for i, record in enumerate(records):
message = string.format(fields[i])

assert record.message.path == ('nested', fields[i],)
assert record.message.id == '1'
assert record.message.message == message
assert str(record.message) == message
assert str(record.message) == string.format(fields[i])


def test_append_no_id():
Expand Down

0 comments on commit 41644b3

Please sign in to comment.