| 1 | """ |
|---|
| 2 | |
|---|
| 3 | some objects used for pickle tests, declared in their own module so that they |
|---|
| 4 | are easily pickleable. |
|---|
| 5 | |
|---|
| 6 | """ |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | class Foo(object): |
|---|
| 10 | def __init__(self, moredata): |
|---|
| 11 | self.data = 'im data' |
|---|
| 12 | self.stuff = 'im stuff' |
|---|
| 13 | self.moredata = moredata |
|---|
| 14 | __hash__ = object.__hash__ |
|---|
| 15 | def __eq__(self, other): |
|---|
| 16 | return other.data == self.data and other.stuff == self.stuff and other.moredata==self.moredata |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | class Bar(object): |
|---|
| 20 | def __init__(self, x, y): |
|---|
| 21 | self.x = x |
|---|
| 22 | self.y = y |
|---|
| 23 | __hash__ = object.__hash__ |
|---|
| 24 | def __eq__(self, other): |
|---|
| 25 | return other.__class__ is self.__class__ and other.x==self.x and other.y==self.y |
|---|
| 26 | def __str__(self): |
|---|
| 27 | return "Bar(%d, %d)" % (self.x, self.y) |
|---|
| 28 | |
|---|
| 29 | class OldSchool: |
|---|
| 30 | def __init__(self, x, y): |
|---|
| 31 | self.x = x |
|---|
| 32 | self.y = y |
|---|
| 33 | def __eq__(self, other): |
|---|
| 34 | return other.__class__ is self.__class__ and other.x==self.x and other.y==self.y |
|---|
| 35 | |
|---|
| 36 | class OldSchoolWithoutCompare: |
|---|
| 37 | def __init__(self, x, y): |
|---|
| 38 | self.x = x |
|---|
| 39 | self.y = y |
|---|
| 40 | |
|---|
| 41 | class BarWithoutCompare(object): |
|---|
| 42 | def __init__(self, x, y): |
|---|
| 43 | self.x = x |
|---|
| 44 | self.y = y |
|---|
| 45 | def __str__(self): |
|---|
| 46 | return "Bar(%d, %d)" % (self.x, self.y) |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | class NotComparable(object): |
|---|
| 50 | def __init__(self, data): |
|---|
| 51 | self.data = data |
|---|
| 52 | |
|---|
| 53 | def __hash__(self): |
|---|
| 54 | return id(self) |
|---|
| 55 | |
|---|
| 56 | def __eq__(self, other): |
|---|
| 57 | return NotImplemented |
|---|
| 58 | |
|---|
| 59 | def __ne__(self, other): |
|---|
| 60 | return NotImplemented |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | class BrokenComparable(object): |
|---|
| 64 | def __init__(self, data): |
|---|
| 65 | self.data = data |
|---|
| 66 | |
|---|
| 67 | def __hash__(self): |
|---|
| 68 | return id(self) |
|---|
| 69 | |
|---|
| 70 | def __eq__(self, other): |
|---|
| 71 | raise NotImplementedError |
|---|
| 72 | |
|---|
| 73 | def __ne__(self, other): |
|---|
| 74 | raise NotImplementedError |
|---|
| 75 | |
|---|