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__ import print_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
for number in count_to_two():
3030
print(number, end=' ')
3131

32-
print()
33-
34-
print('Counting to five...')
32+
print('\nCounting to five...')
3533
for number in count_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

patterns/behavioral/mediator.py.bkp

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+
import random
12+
import time
13+
14+
15+
class TC:
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+
def setup(self):
25+
print("Setting up the Test")
26+
time.sleep(0.1)
27+
self._tm.prepareReporting()
28+
29+
def execute(self):
30+
if not self._bProblem:
31+
print("Executing the test")
32+
time.sleep(0.1)
33+
else:
34+
print("Problem in setup. Test not executed.")
35+
36+
def tearDown(self):
37+
if not self._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+
def setTM(self, tm):
45+
self._tm = tm
46+
47+
def setProblem(self, value):
48+
self._bProblem = value
49+
50+
51+
class Reporter:
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+
def prepare(self):
60+
print("Reporter Class is preparing to report the results")
61+
time.sleep(0.1)
62+
63+
def report(self):
64+
print("Reporting the results of Test")
65+
time.sleep(0.1)
66+
67+
def setTM(self, tm):
68+
self._tm = tm
69+
70+
71+
class DB:
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+
def insert(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+
if random.randrange(1, 4) == 3:
86+
return -1
87+
88+
def update(self):
89+
print("Updating the test results in Database")
90+
time.sleep(0.1)
91+
92+
def setTM(self, tm):
93+
self._tm = tm
94+
95+
96+
class TestManager:
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+
def prepareReporting(self):
110+
rvalue = self._db.insert()
111+
if rvalue == -1:
112+
self._tc.setProblem(1)
113+
self._reporter.prepare()
114+
115+
def setReporter(self, reporter):
116+
self._reporter = reporter
117+
118+
def setDB(self, db):
119+
self._db = db
120+
121+
def publishReport(self):
122+
self._db.update()
123+
self._reporter.report()
124+
125+
def setTC(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+
for i in range(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-
except Exception as e:
101+
except Exception:
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-
except Exception as e:
109+
except Exception:
110110
print('-> doing stuff failed!')
111111
import sys
112112
import traceback
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
for action in actions:
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
if not callable(attr):
3737
return attr
3838

patterns/structural/flyweight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def __init__(self, *args, **kwargs):
119119
cm2 = Card2('10', 'h', a=1)
120120
cm3 = Card2('10', 'h', a=2)
121121

122-
assert (cm1 == cm2) and ( cm1 != cm3)
123-
assert (cm1 is cm2) and ( cm1 is not cm3)
122+
assert (cm1 == cm2) and (cm1 != cm3)
123+
assert (cm1 is cm2) and (cm1 is not cm3)
124124
assert len(instances_pool) == 2
125125

126126
del cm1

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
max-line-length = 120
33
ignore = E266 E731
44
exclude = .venv*
5+
6+
[tool:pytest]
7+
filterwarnings =
8+
; ignore TestRunner class from facade example
9+
ignore:.*test class 'TestRunner'.*:Warning

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"Programming Language :: Python :: 2",
88
"Programming Language :: Python :: 2.7",
99
"Programming Language :: Python :: 3",
10-
"Programming Language :: Python :: 3.4",
11-
"Programming Language :: Python :: 3.5",
1210
"Programming Language :: Python :: 3.6",
11+
"Programming Language :: Python :: 3.7",
1312
],
1413
)

0 commit comments

Comments
 (0)