Skip to content

Commit ee5fa7a

Browse files
author
fkromer
committed
add: test for calls of concrete implementations
1 parent 529c76f commit ee5fa7a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test_bridge.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from bridge import DrawingAPI1, DrawingAPI2, CircleShape
5+
from sys import version_info
6+
7+
if version_info < (2, 7):
8+
import unittest2 as unittest
9+
else:
10+
import unittest
11+
12+
from unittest.mock import patch
13+
14+
class BridgeTest(unittest.TestCase):
15+
16+
def test_bridge_shall_draw_with_concrete_implementation(cls):
17+
ci1 = DrawingAPI1()
18+
ci2 = DrawingAPI2()
19+
with patch.object(ci1, 'draw_circle') as mock_ci1_draw_circle,\
20+
patch.object(ci2, 'draw_circle') as mock_ci2_draw_circle:
21+
sh1 = CircleShape(1, 2, 3, ci1)
22+
sh1.draw()
23+
cls.assertEqual(mock_ci1_draw_circle.call_count, 1)
24+
sh2 = CircleShape(1, 2, 3, ci2)
25+
sh2.draw()
26+
cls.assertEqual(mock_ci2_draw_circle.call_count, 1)
27+
28+
if __name__ == "__main__":
29+
unittest.main()
30+

0 commit comments

Comments
 (0)