You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
2.6KB

  1. # testing/pickleable.py
  2. # Copyright (C) 2005-2021 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: http://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