File: test_issue_148.py

package info (click to toggle)
python-sure 2.0.1%2Bgit.2023.02.06.3aef950b7c-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: python: 3,512; makefile: 255; sh: 12
file content (43 lines) | stat: -rw-r--r-- 892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Regression test for GitHub Issue #148
"""


def test_should_compare_dict_with_non_orderable_key_types():
    # given
    class Foo(object):
        def __eq__(self, other):
            return isinstance(other, Foo)

        def __hash__(self):
            return hash("Foo")

    class Bar(object):
        def __eq__(self, other):
            return isinstance(other, Bar)

        def __hash__(self):
            return hash("Bar")

    # when
    foo = Foo()
    bar = Bar()

    # then
    {foo: 0, bar: 1}.should.equal({foo: 0, bar: 1})


def test_should_compare_dict_with_enum_keys():
    try:
        from enum import Enum
    except ImportError:  # Python 2 environment
        # skip this test
        return

    # given
    class SomeEnum(Enum):
        A = 'A'
        B = 'B'

    # when & then
    {SomeEnum.A: 0, SomeEnum.B: 1}.should.equal({SomeEnum.A: 0, SomeEnum.B: 1})