FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-patterns/test_bridge.py at master · 0xd3adcafe/python-patterns · GitHub
0xd3adcafe
/
python-patterns
Public
forked from
faif/python-patterns
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-patterns
/
test_bridge.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (47 loc) · 1.88 KB
Breadcrumbs
python-patterns
/
test_bridge.py
Copy path
File metadata and controls
55 lines (47 loc) · 1.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
bridge
import
DrawingAPI1
,
DrawingAPI2
,
CircleShape
from
sys
import
version_info
if
version_info
<
(
2
,
7
):
# pragma: no cover
import
unittest2
as
unittest
else
:
import
unittest
try
:
from
unittest
.
mock
import
patch
except
ImportError
:
from
mock
import
patch
class
BridgeTest
(
unittest
.
TestCase
):
def
test_bridge_shall_draw_with_concrete_api_implementation
(
cls
):
ci1
=
DrawingAPI1
()
ci2
=
DrawingAPI2
()
with
patch
.
object
(
ci1
,
'draw_circle'
)
as
mock_ci1_draw_circle
,\
patch
.
object
(
ci2
,
'draw_circle'
)
as
mock_ci2_draw_circle
:
sh1
=
CircleShape
(
1
,
2
,
3
,
ci1
)
sh1
.
draw
()
cls
.
assertEqual
(
mock_ci1_draw_circle
.
call_count
,
1
)
sh2
=
CircleShape
(
1
,
2
,
3
,
ci2
)
sh2
.
draw
()
cls
.
assertEqual
(
mock_ci2_draw_circle
.
call_count
,
1
)
def
test_bridge_shall_scale_both_api_circles_with_own_implementation
(
cls
):
SCALE_FACTOR
=
2
CIRCLE_FACTOR
=
3
CIRCLE1_RADIUS
=
3
EXPECTED_CIRCLE1_RADIUS
=
6
CIRCLE2_RADIUS
=
CIRCLE1_RADIUS
*
CIRCLE1_RADIUS
EXPECTED_CIRCLE2_RADIUS
=
CIRCLE2_RADIUS
*
SCALE_FACTOR
ci1
=
DrawingAPI1
()
ci2
=
DrawingAPI2
()
sh1
=
CircleShape
(
1
,
2
,
CIRCLE1_RADIUS
,
ci1
)
sh2
=
CircleShape
(
1
,
2
,
CIRCLE2_RADIUS
,
ci2
)
sh1
.
scale
(
SCALE_FACTOR
)
sh2
.
scale
(
SCALE_FACTOR
)
cls
.
assertEqual
(
sh1
.
_radius
,
EXPECTED_CIRCLE1_RADIUS
)
cls
.
assertEqual
(
sh2
.
_radius
,
EXPECTED_CIRCLE2_RADIUS
)
with
patch
.
object
(
sh1
,
'scale'
)
as
mock_sh1_scale_circle
,\
patch
.
object
(
sh2
,
'scale'
)
as
mock_sh2_scale_circle
:
sh1
.
scale
(
2
)
sh2
.
scale
(
2
)
cls
.
assertEqual
(
mock_sh1_scale_circle
.
call_count
,
1
)
cls
.
assertEqual
(
mock_sh2_scale_circle
.
call_count
,
1
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL