codekingpro/portable-devtools
115k
1# testing/pickleable.py
2# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: https://www.opensource.org/licenses/mit-license.php
7# mypy: ignore-errors
8
9
10"""Classes used in pickling tests, need to be at the module level for
11unpickling.
12"""
13
14from __future__ import annotations
15
16from .entities import ComparableEntity
17from ..schema import Column
18from ..types import String
19
20
21class User(ComparableEntity):
22 pass
23
24
25class Order(ComparableEntity):
26 pass
27
28
29class Dingaling(ComparableEntity):
30 pass
31
32
33class EmailUser(User):
34 pass
35
36
37class Address(ComparableEntity):
38 pass
39
40
41# TODO: these are kind of arbitrary....
42class Child1(ComparableEntity):
43 pass
44
45
46class Child2(ComparableEntity):
47 pass
48
49
50class Parent(ComparableEntity):
51 pass
52
53
54class Screen:
55 def __init__(self, obj, parent=None):
56 self.obj = obj
57 self.parent = parent
58
59
60class Mixin:
61 email_address = Column(String)
62
63
64class AddressWMixin(Mixin, ComparableEntity):
65 pass
66
67
68class Foo:
69 def __init__(self, moredata, stuff="im stuff"):
70 self.data = "im data"
71 self.stuff = stuff
72 self.moredata = moredata
73
74 __hash__ = object.__hash__
75
76 def __eq__(self, other):
77 return (
78 other.data == self.data
79 and other.stuff == self.stuff
80 and other.moredata == self.moredata
81 )
82
83
84class Bar:
85 def __init__(self, x, y):
86 self.x = x
87 self.y = y
88
89 __hash__ = object.__hash__
90
91 def __eq__(self, other):
92 return (
93 other.__class__ is self.__class__
94 and other.x == self.x
95 and other.y == self.y
96 )
97
98 def __str__(self):
99 return "Bar(%d, %d)" % (self.x, self.y)
100
101
102class OldSchool:
103 def __init__(self, x, y):
104 self.x = x
105 self.y = y
106
107 def __eq__(self, other):
108 return (
109 other.__class__ is self.__class__
110 and other.x == self.x
111 and other.y == self.y
112 )
113
114
115class OldSchoolWithoutCompare:
116 def __init__(self, x, y):
117 self.x = x
118 self.y = y
119
120
121class BarWithoutCompare:
122 def __init__(self, x, y):
123 self.x = x
124 self.y = y
125
126 def __str__(self):
127 return "Bar(%d, %d)" % (self.x, self.y)
128
129
130class NotComparable:
131 def __init__(self, data):
132 self.data = data
133
134 def __hash__(self):
135 return id(self)
136
137 def __eq__(self, other):
138 return NotImplemented
139
140 def __ne__(self, other):
141 return NotImplemented
142
143
144class BrokenComparable:
145 def __init__(self, data):
146 self.data = data
147
148 def __hash__(self):
149 return id(self)
150
151 def __eq__(self, other):
152 raise NotImplementedError
153
154 def __ne__(self, other):
155 raise NotImplementedError
156 