Skip to content

Commit 7b28a12

Browse files
committed
Unbreak CI
1 parent 913572c commit 7b28a12

File tree

3 files changed

+82
-83
lines changed

3 files changed

+82
-83
lines changed

immutables/_testutils.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
class HashKey:
2+
_crasher = None
3+
4+
def __init__(self, hash, name, *, error_on_eq_to=None):
5+
assert hash != -1
6+
self.name = name
7+
self.hash = hash
8+
self.error_on_eq_to = error_on_eq_to
9+
10+
def __repr__(self):
11+
if self._crasher is not None and self._crasher.error_on_repr:
12+
raise ReprError
13+
return '<Key name:{} hash:{}>'.format(self.name, self.hash)
14+
15+
def __hash__(self):
16+
if self._crasher is not None and self._crasher.error_on_hash:
17+
raise HashingError
18+
19+
return self.hash
20+
21+
def __eq__(self, other):
22+
if not isinstance(other, HashKey):
23+
return NotImplemented
24+
25+
if self._crasher is not None and self._crasher.error_on_eq:
26+
raise EqError
27+
28+
if self.error_on_eq_to is not None and self.error_on_eq_to is other:
29+
raise ValueError('cannot compare {!r} to {!r}'.format(self, other))
30+
if other.error_on_eq_to is not None and other.error_on_eq_to is self:
31+
raise ValueError('cannot compare {!r} to {!r}'.format(other, self))
32+
33+
return (self.name, self.hash) == (other.name, other.hash)
34+
35+
36+
class KeyStr(str):
37+
38+
def __hash__(self):
39+
if HashKey._crasher is not None and HashKey._crasher.error_on_hash:
40+
raise HashingError
41+
return super().__hash__()
42+
43+
def __eq__(self, other):
44+
if HashKey._crasher is not None and HashKey._crasher.error_on_eq:
45+
raise EqError
46+
return super().__eq__(other)
47+
48+
def __repr__(self, other):
49+
if HashKey._crasher is not None and HashKey._crasher.error_on_repr:
50+
raise ReprError
51+
return super().__eq__(other)
52+
53+
54+
class HashKeyCrasher:
55+
56+
def __init__(self, *, error_on_hash=False, error_on_eq=False,
57+
error_on_repr=False):
58+
self.error_on_hash = error_on_hash
59+
self.error_on_eq = error_on_eq
60+
self.error_on_repr = error_on_repr
61+
62+
def __enter__(self):
63+
if HashKey._crasher is not None:
64+
raise RuntimeError('cannot nest crashers')
65+
HashKey._crasher = self
66+
67+
def __exit__(self, *exc):
68+
HashKey._crasher = None
69+
70+
71+
class HashingError(Exception):
72+
pass
73+
74+
75+
class EqError(Exception):
76+
pass
77+
78+
79+
class ReprError(Exception):
80+
pass

tests/test_map.py

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,88 +7,7 @@
77
import weakref
88

99
from immutables.map import Map as PyMap
10-
11-
12-
class HashKey:
13-
_crasher = None
14-
15-
def __init__(self, hash, name, *, error_on_eq_to=None):
16-
assert hash != -1
17-
self.name = name
18-
self.hash = hash
19-
self.error_on_eq_to = error_on_eq_to
20-
21-
def __repr__(self):
22-
if self._crasher is not None and self._crasher.error_on_repr:
23-
raise ReprError
24-
return '<Key name:{} hash:{}>'.format(self.name, self.hash)
25-
26-
def __hash__(self):
27-
if self._crasher is not None and self._crasher.error_on_hash:
28-
raise HashingError
29-
30-
return self.hash
31-
32-
def __eq__(self, other):
33-
if not isinstance(other, HashKey):
34-
return NotImplemented
35-
36-
if self._crasher is not None and self._crasher.error_on_eq:
37-
raise EqError
38-
39-
if self.error_on_eq_to is not None and self.error_on_eq_to is other:
40-
raise ValueError('cannot compare {!r} to {!r}'.format(self, other))
41-
if other.error_on_eq_to is not None and other.error_on_eq_to is self:
42-
raise ValueError('cannot compare {!r} to {!r}'.format(other, self))
43-
44-
return (self.name, self.hash) == (other.name, other.hash)
45-
46-
47-
class KeyStr(str):
48-
49-
def __hash__(self):
50-
if HashKey._crasher is not None and HashKey._crasher.error_on_hash:
51-
raise HashingError
52-
return super().__hash__()
53-
54-
def __eq__(self, other):
55-
if HashKey._crasher is not None and HashKey._crasher.error_on_eq:
56-
raise EqError
57-
return super().__eq__(other)
58-
59-
def __repr__(self, other):
60-
if HashKey._crasher is not None and HashKey._crasher.error_on_repr:
61-
raise ReprError
62-
return super().__eq__(other)
63-
64-
65-
class HashKeyCrasher:
66-
67-
def __init__(self, *, error_on_hash=False, error_on_eq=False,
68-
error_on_repr=False):
69-
self.error_on_hash = error_on_hash
70-
self.error_on_eq = error_on_eq
71-
self.error_on_repr = error_on_repr
72-
73-
def __enter__(self):
74-
if HashKey._crasher is not None:
75-
raise RuntimeError('cannot nest crashers')
76-
HashKey._crasher = self
77-
78-
def __exit__(self, *exc):
79-
HashKey._crasher = None
80-
81-
82-
class HashingError(Exception):
83-
pass
84-
85-
86-
class EqError(Exception):
87-
pass
88-
89-
90-
class ReprError(Exception):
91-
pass
10+
from immutables._testutils import * # NoQA
9211

9312

9413
class BaseMapTest:

tests/test_none_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22

33
from immutables.map import map_hash, map_mask, Map as PyMap
4-
from tests.test_map import HashKey
4+
from immutables._testutils import * # NoQA
55

66

77
none_hash = map_hash(None)

0 commit comments

Comments
 (0)