pickleable.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # testing/pickleable.py
  2. # Copyright (C) 2005-2024 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. """Classes used in pickling tests, need to be at the module level for
  8. unpickling.
  9. """
  10. from . import fixtures
  11. from ..schema import Column
  12. from ..types import String
  13. class User(fixtures.ComparableEntity):
  14. pass
  15. class Order(fixtures.ComparableEntity):
  16. pass
  17. class Dingaling(fixtures.ComparableEntity):
  18. pass
  19. class EmailUser(User):
  20. pass
  21. class Address(fixtures.ComparableEntity):
  22. pass
  23. # TODO: these are kind of arbitrary....
  24. class Child1(fixtures.ComparableEntity):
  25. pass
  26. class Child2(fixtures.ComparableEntity):
  27. pass
  28. class Parent(fixtures.ComparableEntity):
  29. pass
  30. class Screen(object):
  31. def __init__(self, obj, parent=None):
  32. self.obj = obj
  33. self.parent = parent
  34. class Mixin(object):
  35. email_address = Column(String)
  36. class AddressWMixin(Mixin, fixtures.ComparableEntity):
  37. pass
  38. class Foo(object):
  39. def __init__(self, moredata, stuff="im stuff"):
  40. self.data = "im data"
  41. self.stuff = stuff
  42. self.moredata = moredata
  43. __hash__ = object.__hash__
  44. def __eq__(self, other):
  45. return (
  46. other.data == self.data
  47. and other.stuff == self.stuff
  48. and other.moredata == self.moredata
  49. )
  50. class Bar(object):
  51. def __init__(self, x, y):
  52. self.x = x
  53. self.y = y
  54. __hash__ = object.__hash__
  55. def __eq__(self, other):
  56. return (
  57. other.__class__ is self.__class__
  58. and other.x == self.x
  59. and other.y == self.y
  60. )
  61. def __str__(self):
  62. return "Bar(%d, %d)" % (self.x, self.y)
  63. class OldSchool:
  64. def __init__(self, x, y):
  65. self.x = x
  66. self.y = y
  67. def __eq__(self, other):
  68. return (
  69. other.__class__ is self.__class__
  70. and other.x == self.x
  71. and other.y == self.y
  72. )
  73. class OldSchoolWithoutCompare:
  74. def __init__(self, x, y):
  75. self.x = x
  76. self.y = y
  77. class BarWithoutCompare(object):
  78. def __init__(self, x, y):
  79. self.x = x
  80. self.y = y
  81. def __str__(self):
  82. return "Bar(%d, %d)" % (self.x, self.y)
  83. class NotComparable(object):
  84. def __init__(self, data):
  85. self.data = data
  86. def __hash__(self):
  87. return id(self)
  88. def __eq__(self, other):
  89. return NotImplemented
  90. def __ne__(self, other):
  91. return NotImplemented
  92. class BrokenComparable(object):
  93. def __init__(self, data):
  94. self.data = data
  95. def __hash__(self):
  96. return id(self)
  97. def __eq__(self, other):
  98. raise NotImplementedError
  99. def __ne__(self, other):
  100. raise NotImplementedError