pickleable.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # testing/pickleable.py
  2. # Copyright (C) 2005-2017 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):
  34. self.data = 'im data'
  35. self.stuff = 'im stuff'
  36. self.moredata = moredata
  37. __hash__ = object.__hash__
  38. def __eq__(self, other):
  39. return other.data == self.data and \
  40. other.stuff == self.stuff and \
  41. other.moredata == self.moredata
  42. class Bar(object):
  43. def __init__(self, x, y):
  44. self.x = x
  45. self.y = y
  46. __hash__ = object.__hash__
  47. def __eq__(self, other):
  48. return other.__class__ is self.__class__ and \
  49. other.x == self.x and \
  50. other.y == self.y
  51. def __str__(self):
  52. return "Bar(%d, %d)" % (self.x, self.y)
  53. class OldSchool:
  54. def __init__(self, x, y):
  55. self.x = x
  56. self.y = y
  57. def __eq__(self, other):
  58. return other.__class__ is self.__class__ and \
  59. other.x == self.x and \
  60. other.y == self.y
  61. class OldSchoolWithoutCompare:
  62. def __init__(self, x, y):
  63. self.x = x
  64. self.y = y
  65. class BarWithoutCompare(object):
  66. def __init__(self, x, y):
  67. self.x = x
  68. self.y = y
  69. def __str__(self):
  70. return "Bar(%d, %d)" % (self.x, self.y)
  71. class NotComparable(object):
  72. def __init__(self, data):
  73. self.data = data
  74. def __hash__(self):
  75. return id(self)
  76. def __eq__(self, other):
  77. return NotImplemented
  78. def __ne__(self, other):
  79. return NotImplemented
  80. class BrokenComparable(object):
  81. def __init__(self, data):
  82. self.data = data
  83. def __hash__(self):
  84. return id(self)
  85. def __eq__(self, other):
  86. raise NotImplementedError
  87. def __ne__(self, other):
  88. raise NotImplementedError