module.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """Contains classes for tests for basic demonstration of tool."""
  2. class Base:
  3. """Base class with a few attributes and couple methods."""
  4. base_attr = 'Attribute og base class'
  5. def first_method(self):
  6. """Method to be inherited."""
  7. print('1th method of Base')
  8. return 1
  9. def second_method(self):
  10. """Method to be overidden."""
  11. print('2th method of Base, not implemented')
  12. raise NotImplementedError
  13. from functools import wraps
  14. def decorator(function):
  15. # XXX: without this there will be bugs!!!
  16. @wraps(function)
  17. def wrapper(*args, **kwargs):
  18. return function(*args, **kwargs)
  19. return wrapper
  20. class Mixin:
  21. """Mixin class to override stub method from base class."""
  22. @decorator
  23. def second_method(self):
  24. """Implement base's stub function."""
  25. print('3th method of Mixin')
  26. return 2
  27. class Example(Mixin, Base):
  28. """Class with inheritance."""
  29. attr = '1st attribute of Example'
  30. def __init__(self, one=None):
  31. self.one = one
  32. def third_method(self):
  33. """Method defined right here, not inherited, not overriden."""
  34. print('3th method of Ex3')
  35. return 3
  36. class Example2(Base, Mixin):
  37. attr = '1st attribute of Example2'
  38. def third_method(self):
  39. print('4th method of Ex2')
  40. return 4
  41. class Example3(Base, Mixin):
  42. attr = '1st attr of Ex3 class'
  43. def fourth_method(self):
  44. print('4th method of Ex3')
  45. return 4
  46. class MethodHolder:
  47. """Do not change anything in this class!
  48. This is the class which holds single method."""
  49. def call_me(self):
  50. """What is my crc32?"""
  51. print("You've did it!")
  52. # detect overriden __init__ method
  53. class WithCustomInit:
  54. """Define custom init function"""
  55. def __init__(self, one=1):
  56. """Get one argument"""
  57. self.one = one
  58. class InheritCustomInit(WithCustomInit):
  59. """The __init__ method should not be listed."""
  60. class OverrideCustomInit(WithCustomInit):
  61. """The __init__ method should be listed, because it's overriden."""
  62. def __init__(self, one=2):
  63. """Overriden __init__ method"""
  64. self.one = one + 1