Skip to content

Add hash capabilities to OUI#225

Merged
jstasiak merged 4 commits intonetaddr:masterfrom
amitmi704:b-oui_hashable
Feb 8, 2021
Merged

Add hash capabilities to OUI#225
jstasiak merged 4 commits intonetaddr:masterfrom
amitmi704:b-oui_hashable

Conversation

@amitmi704
Copy link
Contributor

Closes #224

Copy link
Contributor

@jstasiak jstasiak left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the patch. Can you provide a unit test for this?

raise NotRegisteredError('OUI %r not registered!' % (oui,))

def __hash__(self):
""":return: hash of this OUI object suitable for dict keys, sets etc"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's drop this comment, the meaning of the value returned by __hash__() is rather standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. That was a copy-and-paste from the EUI.__hash__.

def test_oui_constructor():
oui = OUI(524336)
assert str(oui) == '08-00-30'
assert hash(oui) == 524336
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a real-world hash-capability demonstration here. If the original issue is about using OUI objects as dictionary keys let's use that to check if it works, we shouldn't be hardcoding specific hash values (those can't be depended on etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, let me know if you want me to drop the hash asserts in the new one. Broke it out into a different func to not clutter the test_oui_constructor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! Yes, please drop those two asserts and I'm happy to merge this.

@codecov-io
Copy link

codecov-io commented Feb 7, 2021

Codecov Report

Merging #225 (0b6e563) into master (606a44b) will increase coverage by 3.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #225      +/-   ##
==========================================
+ Coverage   86.74%   89.78%   +3.03%     
==========================================
  Files          48       44       -4     
  Lines        4558     3190    -1368     
  Branches      659      381     -278     
==========================================
- Hits         3954     2864    -1090     
+ Misses        424      254     -170     
+ Partials      180       72     -108     
Impacted Files Coverage Δ
netaddr/tests/eui/test_eui.py 100.00% <100.00%> (ø)
netaddr/fbsocket.py 40.00% <0.00%> (-39.32%) ⬇️
netaddr/tests/ip/test_platform_osx.py 60.00% <0.00%> (-28.24%) ⬇️
netaddr/tests/strategy/test_ipv6_strategy.py 97.10% <0.00%> (-2.90%) ⬇️
netaddr/strategy/ipv4.py 73.78% <0.00%> (-1.95%) ⬇️
netaddr/strategy/ipv6.py 89.62% <0.00%> (-1.89%) ⬇️
netaddr/tests/core/test_compat.py 96.00% <0.00%> (-0.16%) ⬇️
netaddr/tests/ip/test_ip_v4.py 99.24% <0.00%> (-0.01%) ⬇️
netaddr/ip/sets.py 97.42% <0.00%> (-0.01%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 606a44b...0b6e563. Read the comment docs.

@jstasiak jstasiak merged commit b6c4203 into netaddr:master Feb 8, 2021
@jstasiak
Copy link
Contributor

jstasiak commented Feb 8, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OUI hashability

3 participants