pickleable.py 2.8 KB

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