Skip to content

Commit f9a9244

Browse files
committed
Merge pull request #1666 from mboersma/1509-make-test-style
feat(*): add `make test-style` targets
2 parents 07a7f50 + a573c08 commit f9a9244

17 files changed

Lines changed: 134 additions & 80 deletions

File tree

client/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ clean:
1313

1414
client:
1515
pyinstaller deis.spec
16+
17+
setup-venv:
18+
@if [ ! -d venv ]; then virtualenv venv; fi
19+
venv/bin/pip install -q flake8==2.2.2
20+
21+
test-style: setup-venv
22+
venv/bin/flake8

client/deis.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def readable_datetime(datetime_str):
318318
else:
319319
return "{}{}ago".format(hour_str, min_str)
320320
# if it happened yesterday, say "yesterday at 3:23 pm"
321-
yesterday = now + relativedelta.relativedelta(days= -1)
321+
yesterday = now + relativedelta.relativedelta(days=-1)
322322
if delta.days <= 2 and dt.day == yesterday.day:
323323
return dt.strftime("Yesterday at %X")
324324
# otherwise return locale-specific date/time format
@@ -1033,12 +1033,13 @@ def clusters_update(self, args):
10331033
if k == 'auth' and args.get('--auth') is not None:
10341034
auth_path = os.path.expanduser(args['--auth'])
10351035
if not os.path.exists(auth_path):
1036-
print('Path to authentication credentials does not exist: {}'.format(auth_path))
1036+
print(
1037+
"Path to authentication credentials does not exist: {}".format(auth_path))
10371038
sys.exit(1)
10381039
with open(auth_path) as f:
10391040
data = f.read()
10401041
body.update({'auth': base64.b64encode(data)})
1041-
else :
1042+
else:
10421043
v = args.get(arg)
10431044
if v:
10441045
body.update({k: v})
@@ -1176,7 +1177,8 @@ def config_unset(self, args):
11761177
try:
11771178
progress = TextProgress()
11781179
progress.start()
1179-
response = self._dispatch('post', "/api/apps/{}/config".format(app), json.dumps(body))
1180+
response = self._dispatch(
1181+
'post', "/api/apps/{}/config".format(app), json.dumps(body))
11801182
finally:
11811183
progress.cancel()
11821184
progress.join()
@@ -1230,10 +1232,8 @@ def config_pull(self, args):
12301232
if response.status_code == requests.codes.ok: # @UndefinedVariable
12311233
config = json.loads(response.json()['values'])
12321234
for k, v in config.items():
1233-
if interactive:
1234-
confirm = raw_input('overwrite {} with {}? (y/N) '.format(k, v))
1235-
if confirm == 'y':
1236-
env_dict[k] = v
1235+
if interactive and raw_input("overwrite {} with {}? (y/N) ".format(k, v)) == 'y':
1236+
env_dict[k] = v
12371237
if k in env_dict and not overwrite:
12381238
continue
12391239
env_dict[k] = v
@@ -1284,7 +1284,8 @@ def domains_add(self, args):
12841284
try:
12851285
progress = TextProgress()
12861286
progress.start()
1287-
response = self._dispatch('post', "/api/apps/{app}/domains".format(app=app), json.dumps(body))
1287+
response = self._dispatch(
1288+
'post', "/api/apps/{app}/domains".format(app=app), json.dumps(body))
12881289
finally:
12891290
progress.cancel()
12901291
progress.join()
@@ -1316,7 +1317,8 @@ def domains_remove(self, args):
13161317
try:
13171318
progress = TextProgress()
13181319
progress.start()
1319-
response = self._dispatch('delete', "/api/apps/{app}/domains/{domain}".format(**locals()))
1320+
response = self._dispatch(
1321+
'delete', "/api/apps/{app}/domains/{domain}".format(**locals()))
13201322
finally:
13211323
progress.cancel()
13221324
progress.join()

client/setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[sdist]
22
formats = zip,gztar
3+
4+
[flake8]
5+
max-line-length = 99
6+
exclude = build,dist,venv
7+
max-complexity = 12

controller/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ coverage:
4141
coverage run manage.py test --noinput api
4242
coverage html
4343

44-
flake8:
45-
flake8
46-
4744
test: test-unit test-functional
4845

49-
test-unit:
46+
setup-venv:
5047
@if [ ! -d venv ]; then virtualenv venv; fi
5148
venv/bin/pip install -q -r requirements.txt -r dev_requirements.txt
49+
50+
test-style: setup-venv
51+
venv/bin/flake8
52+
53+
test-unit: setup-venv test-style
5254
venv/bin/python manage.py test --noinput api
5355

5456
test-functional:

controller/api/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def deploy(self, release, initial=False):
186186
elif release.build.dockerfile and not release.build.procfile:
187187
self.structure = {'cmd': 1}
188188
# if a procfile exists without a web entry, assume docker workflow
189-
elif release.build.procfile and not 'web' in release.build.procfile:
189+
elif release.build.procfile and 'web' not in release.build.procfile:
190190
self.structure = {'cmd': 1}
191191
# default to heroku workflow
192192
else:
@@ -206,7 +206,7 @@ def scale(self, **kwargs): # noqa
206206
for container_type in requested_containers.keys():
207207
if container_type == 'cmd':
208208
continue # allow docker cmd types in case we don't have the image source
209-
if not container_type in available_process_types:
209+
if container_type not in available_process_types:
210210
raise EnvironmentError(
211211
'Container type {} does not exist in application'.format(container_type))
212212
msg = 'Containers scaled ' + ' '.join(

controller/dev_requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ coverage>=3.7.1
1919
docutils>=0.12
2020

2121
# Run "make flake8" to check python syntax and style
22-
flake8==2.1.0
23-
pep8==1.4.6
24-
pyflakes==0.7.3
22+
flake8==2.2.2
2523

2624
# Used for mocking endpoints
2725
mock==1.0.1

controller/scheduler/coreos.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
if not os.path.exists(ROOT_DIR):
1212
os.mkdir(ROOT_DIR)
1313

14-
MATCH = re.compile('(?P<app>[a-z0-9-]+)_?(?P<version>v[0-9]+)?\.?(?P<c_type>[a-z]+)?.(?P<c_num>[0-9]+)')
14+
MATCH = re.compile(
15+
'(?P<app>[a-z0-9-]+)_?(?P<version>v[0-9]+)?\.?(?P<c_type>[a-z]+)?.(?P<c_num>[0-9]+)')
16+
1517

1618
class FleetClient(object):
1719

@@ -76,15 +78,15 @@ def _create_container(self, name, image, command, template, env, **kwargs):
7678
# prepare memory limit for the container type
7779
mem = kwargs.get('memory', {}).get(l['c_type'], None)
7880
if mem:
79-
l.update({'memory': '-m {}'.format(mem.lower())})
81+
l.update({'memory': '-m {}'.format(mem.lower())})
8082
else:
81-
l.update({'memory': ''})
83+
l.update({'memory': ''})
8284
# prepare memory limit for the container type
8385
cpu = kwargs.get('cpu', {}).get(l['c_type'], None)
8486
if cpu:
85-
l.update({'cpu': '-c {}'.format(cpu)})
87+
l.update({'cpu': '-c {}'.format(cpu)})
8688
else:
87-
l.update({'cpu': ''})
89+
l.update({'cpu': ''})
8890
env.update({'FLEETW_UNIT': name + '.service'})
8991
# construct unit from template
9092
unit = template.format(**l)
@@ -148,7 +150,7 @@ def _wait_for_announcer(self, name, env):
148150
# we bump to 20 minutes here to match the timeout on the router and in the app unit files
149151
for _ in range(1200):
150152
status = subprocess.check_output(
151-
"fleetctl.sh list-units --no-legend --fields unit,sub | grep {name}-announce.service | awk '{{print $2}}'".format(**locals()),
153+
"fleetctl.sh list-units --no-legend --fields unit,sub | grep {name}-announce.service | awk '{{print $2}}'".format(**locals()), # noqa
152154
shell=True, env=env).strip('\n')
153155
if status == 'running':
154156
break
@@ -246,7 +248,7 @@ def attach(self, name):
246248
ExecStart=/bin/sh -c "IMAGE=$(etcdctl get /deis/registry/host 2>&1):$(etcdctl get /deis/registry/port 2>&1)/{image}; port=$(docker inspect -f '{{{{range $k, $v := .ContainerConfig.ExposedPorts }}}}{{{{$k}}}}{{{{end}}}}' $IMAGE | cut -d/ -f1) ; docker run --name {name} {memory} {cpu} -P -e PORT=$port $IMAGE {command}"
247249
ExecStop=/usr/bin/docker rm -f {name}
248250
TimeoutStartSec=20m
249-
"""
251+
""" # noqa
250252

251253
# TODO revisit the "not getting a port" issue after we upgrade to Docker 1.1.0
252254
ANNOUNCE_TEMPLATE = """
@@ -263,7 +265,7 @@ def attach(self, name):
263265
264266
[X-Fleet]
265267
X-ConditionMachineOf={name}.service
266-
"""
268+
""" # noqa
267269

268270
LOG_TEMPLATE = """
269271
[Unit]
@@ -277,4 +279,4 @@ def attach(self, name):
277279
278280
[X-Fleet]
279281
X-ConditionMachineOf={name}.service
280-
"""
282+
""" # noqa

controller/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
max-line-length = 99
3-
exclude = */api/migrations/*,*/api/south_migrations/*,*/build/*,*/venv/*,*/virtualenv/*,*/scheduler/*,*/templates/*
3+
exclude = api/migrations,api/south_migrations,templates,venv
44
max-complexity = 12

logger/Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ full-clean: clean
2929

3030
test: test-unit test-functional
3131

32-
test-unit:
32+
setup-root-gotools:
33+
sudo GOPATH=/tmp/tmpGOPATH go get -u -v code.google.com/p/go.tools/cmd/cover
34+
sudo GOPATH=/tmp/tmpGOPATH go get -u -v code.google.com/p/go.tools/cmd/vet
35+
sudo rm -rf /tmp/tmpGOPATH
36+
37+
setup-gotools:
38+
go get -v github.com/golang/lint/golint
39+
40+
test-style:
41+
go vet -x ./...
42+
-golint .
43+
44+
test-unit: test-style
3345
go test -v -cover ./syslog
3446

3547
test-functional:

logger/syslog/filehandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (h *FileHandler) checkErr(err error) bool {
8989
return true
9090
}
9191

92-
// See BaseHandler.Handle
92+
// Handle queues and dispatches a message. See BaseHandler.Handle
9393
func (h *FileHandler) Handle(m *Message) *Message {
9494
return h.bh.Handle(m)
9595
}

0 commit comments

Comments
 (0)