Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All major changes in each released version of the archfx-cloud plugin are listed here.

## 0.17.0

- Made `ArchFxCloudSlug` (and all its derived classes) usable as a mapping key by overriding the `__hash__()` method.
- Made `ArchFxCloudSlug` (and all its derived classes) considered equal if their `slug` attributes are equal by overriding the `__eq__()` method.

## 0.16.0

- Updated `dev` domain in `BaseMain` class to be `http://localhost`.
Expand Down
10 changes: 9 additions & 1 deletion archfx_cloud/utils/slugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ class ArchFxCloudSlug(object):
_slug = None

def __str__(self):
return self._slug
return self._slug or ''

def __hash__(self):
return hash(self._slug)

def __eq__(self, other):
if isinstance(other, ArchFxCloudSlug):
return self._slug == other._slug
return super().__eq__(other)
Comment on lines +44 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable string is a SLUG?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahah yeah everything is a slug at the beginning, and so that's why hashing the slug directly covers all the cases at once...


def formatted_id(self):
parts = gid_split(self._slug)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_slugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ def test_ArchFxVariableID(name, input, formatted, scope, var):
assert result.scope == scope
assert result.scope_hex == f"{scope:04x}"

other = ArchFxVariableID(input)
assert str(result) == str(other)
assert hash(result) == hash(other)
assert result == other

other2 = ArchFxVariableID('9999-9999')
assert str(result) != str(other2)
assert hash(result) != hash(other2)
assert result != other2

mapping = {result: 'value'}
assert mapping[result] == 'value'
assert mapping[other] == 'value'
assert mapping.get(other2) is None


class SlugTestCase(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.16.0'
version = '0.17.0'