Skip to content

Commit 9aa2a5b

Browse files
committed
Fix flake8 check and related warnings
1 parent e5b253a commit 9aa2a5b

File tree

13 files changed

+187
-20
lines changed

13 files changed

+187
-20
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ script:
2020
- pytest -s -vv --cov=. --log-level=INFO tests/
2121
# Actually run all the scripts, contributing to coverage
2222
- PYTHONPATH=. ./run_all.sh
23-
- flake8 *py
23+
- flake8 patterns/
2424

2525
after_success:
2626
- codecov

‎append_output.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ echo "$src" > $1
1616
echo -e "\n">>$1
1717
echo"$output_marker">>$1
1818
echo"$output">>$1
19-
echo'"""'>>$1
19+
echo'""" # noqa'>>$1

‎patterns/behavioral/command.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
Encapsulates all information needed to perform an action or trigger an event.
77
88
*Examples in Python ecosystem:
9-
Django HttpRequest (without `execute` method): https://docs.djangoproject.com/en/2.1/ref/request-response/#httprequest-objects
9+
Django HttpRequest (without `execute` method):
10+
https://docs.djangoproject.com/en/2.1/ref/request-response/#httprequest-objects
1011
"""
1112

1213
from __future__ importprint_function

‎patterns/behavioral/iterator.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ def main():
2929
fornumberincount_to_two():
3030
print(number, end=' ')
3131

32-
print()
33-
34-
print('Counting to five...')
32+
print('\nCounting to five...')
3533
fornumberincount_to_five():
3634
print(number, end=' ')
37-
38-
print()
3935

4036

4137
if__name__=="__main__":
@@ -47,4 +43,4 @@ def main():
4743
one two
4844
Counting to five...
4945
one two three four five
50-
"""
46+
"""# noqa
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
http://web.archive.org/web/20120309135549/http://dpip.testingperspective.com/?p=28
6+
7+
*TL;DR80
8+
Encapsulates how a set of objects interact.
9+
"""
10+
11+
importrandom
12+
importtime
13+
14+
15+
classTC:
16+
"""TestCategory
17+
responsible for running the tests with the help of setup(), execute() and tearDown() methods
18+
"""
19+
20+
def__init__(self):
21+
self._tm=None
22+
self._bProblem=0
23+
24+
defsetup(self):
25+
print("Setting up the Test")
26+
time.sleep(0.1)
27+
self._tm.prepareReporting()
28+
29+
defexecute(self):
30+
ifnotself._bProblem:
31+
print("Executing the test")
32+
time.sleep(0.1)
33+
else:
34+
print("Problem in setup. Test not executed.")
35+
36+
deftearDown(self):
37+
ifnotself._bProblem:
38+
print("Tearing down")
39+
time.sleep(0.1)
40+
self._tm.publishReport()
41+
else:
42+
print("Test not executed. No tear down required.")
43+
44+
defsetTM(self, tm):
45+
self._tm=tm
46+
47+
defsetProblem(self, value):
48+
self._bProblem=value
49+
50+
51+
classReporter:
52+
"""
53+
- calls its prepare() method while TestCategory starts getting executed
54+
- calls its report() method when TestCategory finishes its execution.
55+
"""
56+
def__init__(self):
57+
self._tm=None
58+
59+
defprepare(self):
60+
print("Reporter Class is preparing to report the results")
61+
time.sleep(0.1)
62+
63+
defreport(self):
64+
print("Reporting the results of Test")
65+
time.sleep(0.1)
66+
67+
defsetTM(self, tm):
68+
self._tm=tm
69+
70+
71+
classDB:
72+
"""
73+
stores the execution status of the test category by first
74+
calling the insert() method while the test category is in setup(),
75+
and then calls the update() method once the test category has finished execution.
76+
In this way, at any given point of time, the test execution status is available for framework user to query from the database
77+
"""
78+
def__init__(self):
79+
self._tm=None
80+
81+
definsert(self):
82+
print("Inserting the execution begin status in the Database")
83+
time.sleep(0.1)
84+
# Following code is to simulate a communication from DB to TC
85+
ifrandom.randrange(1, 4) ==3:
86+
return-1
87+
88+
defupdate(self):
89+
print("Updating the test results in Database")
90+
time.sleep(0.1)
91+
92+
defsetTM(self, tm):
93+
self._tm=tm
94+
95+
96+
classTestManager:
97+
"""
98+
Mediator between Class TC, Class Reporter and Class DB, the Colleagues in the system
99+
coordinates for
100+
test category execution (Class TC)
101+
and fetching the reports (Class Reporter)
102+
and getting the test execution status in database (Class DB) with the help of prepareReporting() and publishReport() methods
103+
"""
104+
def__init__(self):
105+
self._reporter=None
106+
self._db=None
107+
self._tc=None
108+
109+
defprepareReporting(self):
110+
rvalue=self._db.insert()
111+
ifrvalue==-1:
112+
self._tc.setProblem(1)
113+
self._reporter.prepare()
114+
115+
defsetReporter(self, reporter):
116+
self._reporter=reporter
117+
118+
defsetDB(self, db):
119+
self._db=db
120+
121+
defpublishReport(self):
122+
self._db.update()
123+
self._reporter.report()
124+
125+
defsetTC(self, tc):
126+
self._tc=tc
127+
128+
129+
if__name__=='__main__':
130+
reporter=Reporter()
131+
db=DB()
132+
tm=TestManager()
133+
tm.setReporter(reporter)
134+
tm.setDB(db)
135+
reporter.setTM(tm)
136+
db.setTM(tm)
137+
# For simplification we are looping on the same test.
138+
# Practically, it could be about various unique test classes and their
139+
# objects
140+
foriinrange(3):
141+
tc=TC()
142+
tc.setTM(tm)
143+
tm.setTC(tc)
144+
tc.setup()
145+
tc.execute()
146+
tc.tearDown()
147+
148+
### OUTPUT ###
149+
# Setting up the Test
150+
# Inserting the execution begin status in the Database
151+
# Executing the test
152+
# Tearing down
153+
# Updating the test results in Database
154+
# Reporting the results of Test
155+
# Setting up the Test
156+
# Inserting the execution begin status in the Database
157+
# Reporter Class is preparing to report the results
158+
# Problem in setup. Test not executed.
159+
# Test not executed. No tear down required.
160+
# Setting up the Test
161+
# Inserting the execution begin status in the Database
162+
# Executing the test
163+
# Tearing down
164+
# Updating the test results in Database
165+
# Reporting the results of Test

‎patterns/behavioral/memento.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,26 @@ def main():
9898
print(num_obj)
9999
num_obj.value+='x'# will fail
100100
print(num_obj)
101-
exceptExceptionase:
101+
exceptException:
102102
a_transaction.rollback()
103103
print('-- rolled back')
104104
print(num_obj)
105105

106106
print('-- now doing stuff ...')
107107
try:
108108
num_obj.do_stuff()
109-
exceptExceptionase:
109+
exceptException:
110110
print('-> doing stuff failed!')
111111
importsys
112112
importtraceback
113113

114114
traceback.print_exc(file=sys.stdout)
115115
print(num_obj)
116116

117+
117118
if__name__=='__main__':
118119
main()
119-
120+
120121

121122
OUTPUT="""
122123
<NumObj: -1>

‎patterns/behavioral/specification.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def main():
102102
print(root_specification.is_satisfied_by(ivan))
103103
print(root_specification.is_satisfied_by(vasiliy))
104104

105-
105+
106106
if__name__=='__main__':
107107
main()
108108

‎patterns/behavioral/state.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main():
7676
foractioninactions:
7777
action()
7878

79-
79+
8080
if__name__=='__main__':
8181
main()
8282

‎patterns/behavioral/template.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
An example of the Template pattern in Python
66
77
*TL;DR80
8-
Defines the skeleton of a base algorithm, deferring definition of exact
8+
Defines the skeleton of a base algorithm, deferring definition of exact
99
steps to subclasses.
1010
1111
*Examples in Python ecosystem:

‎patterns/fundamental/delegation_pattern.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, delegate):
3232

3333
def__getattr__(self, name):
3434
attr=getattr(self.delegate, name)
35-
35+
3636
ifnotcallable(attr):
3737
returnattr
3838

0 commit comments

Comments
(0)