Debian Codegraph @

tests/issues/test_issue_148.py

raw symbols SCIP
1 """
2 Regression test for GitHub Issue #148
3 """
4
5
6 def test_should_compare_dict_with_non_orderable_key_types():
7 # given
8 class Foo(object):
9 def __eq__(self, other):
10 return isinstance(other, Foo)
11
12 def __hash__(self):
13 return hash("Foo")
14
15 class Bar(object):
16 def __eq__(self, other):
17 return isinstance(other, Bar)
18
19 def __hash__(self):
20 return hash("Bar")
21
22 # when
23 foo = Foo()
24 bar = Bar()
25
26 # then
27 {foo: 0, bar: 1}.should.equal({foo: 0, bar: 1})
28
29
30 def test_should_compare_dict_with_enum_keys():
31 try:
32 from enum import Enum
33 except ImportError: # Python 2 environment
34 # skip this test
35 return
36
37 # given
38 class SomeEnum(Enum):
39 A = 'A'
40 B = 'B'
41
42 # when & then
43 {SomeEnum.A: 0, SomeEnum.B: 1}.should.equal({SomeEnum.A: 0, SomeEnum.B: 1})