-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from honno/use-dtype-eq
Implement `EqualityMapping` and use for relevant dtype helpers
- Loading branch information
Showing
3 changed files
with
180 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
from ..dtype_helpers import EqualityMapping | ||
|
||
|
||
def test_raises_on_distinct_eq_key(): | ||
with pytest.raises(ValueError): | ||
EqualityMapping([(float("nan"), "value")]) | ||
|
||
|
||
def test_raises_on_indistinct_eq_keys(): | ||
class AlwaysEq: | ||
def __init__(self, hash): | ||
self._hash = hash | ||
|
||
def __eq__(self, other): | ||
return True | ||
|
||
def __hash__(self): | ||
return self._hash | ||
|
||
with pytest.raises(ValueError): | ||
EqualityMapping([(AlwaysEq(0), "value1"), (AlwaysEq(1), "value2")]) | ||
|
||
|
||
def test_key_error(): | ||
mapping = EqualityMapping([("key", "value")]) | ||
with pytest.raises(KeyError): | ||
mapping["nonexistent key"] | ||
|
||
|
||
def test_iter(): | ||
mapping = EqualityMapping([("key", "value")]) | ||
it = iter(mapping) | ||
assert next(it) == "key" | ||
with pytest.raises(StopIteration): | ||
next(it) |