Skip to content

Instantly share code, notes, and snippets.

@avian2
Created June 24, 2015 14:23
Show Gist options
  • Save avian2/3c7522e5ff55fd17ee44 to your computer and use it in GitHub Desktop.
Save avian2/3c7522e5ff55fd17ee44 to your computer and use it in GitHub Desktop.
### Hettinger's way
# robot.py
class Robot(object):
def move(self):
print('Movement')
class CleaningRobot(Robot):
def clean(self):
for i in range(3):
super().move()
# test.py
class MockBot(Robot):
def move(self):
print('Simulated movement')
class MockedCleaningRobot(CleaningRobot, MockBot):
pass
MockedCleaningRobot().clean()
### How I usually do it
# robot.py
class CleaningRobot(object):
def clean(self):
for i in range(3):
self.move()
def move(self):
print('Movement')
# test.py
class MockedCleaningRobot(CleaningRobot):
def move(self):
print('Simulated movement')
MockedCleaningRobot().clean()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment