-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonkeypatch.py
More file actions
executable file
·51 lines (32 loc) · 813 Bytes
/
Copy pathmonkeypatch.py
File metadata and controls
executable file
·51 lines (32 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
class A(object):
def simple_print(self, value="A"):
print("Function simple_print! %s" % value)
class MockA(object):
def mocked_print(self, value="MockedA"):
print("Printing Mocked %s " % value)
class B(object):
def __init__(self, aobj):
self.a = aobj
def print_b(self):
current_frame = sys._getframe(0)
self.a.simple_print(value="B")
def withoutMock():
objA = A()
objA.simple_print()
objB = B(objA)
objB.print_b()
def mockPrint():
objA = A()
mockA = MockA()
objA.simple_print = mockA.mocked_print
objB = B(objA)
objB.print_b()
def main():
withoutMock()
print("---- mocked ---")
mockPrint()
if __name__ == "__main__":
main()