Skip to content

Commit 3b35609

Browse files
authored
Merge pull request #104 from zalando/requirements
Remove pytest from requirements.txt
2 parents de5325a + 9e98394 commit 3b35609

File tree

11 files changed

+46
-40
lines changed

11 files changed

+46
-40
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
language: python
22
python:
3-
- "3.4"
43
- "2.7"
4+
- "3.5"
5+
- "3.6"
6+
- "3.7"
7+
- "3.8"
58
install:
69
- pip install -r requirements.txt
7-
- pip install coveralls
10+
- pip install coveralls pytest pytest-cov flake8
811
script:
912
- python setup.py test
1013
- python setup.py flake8

pg_view/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def main():
283283
print(traceback.format_exc())
284284
if 'SSH_CLIENT' in os.environ and 'SSH_TTY' not in os.environ:
285285
print('Unable to initialize curses. Make sure you supply -t option (force psedo-tty allocation) to ssh')
286-
except:
286+
except Exception:
287287
print(traceback.format_exc())
288288
finally:
289289
sys.exit(0)

pg_view/collectors/base_collector.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def __init__(self, ticks_per_refresh=1, produce_diffs=True):
5959
self.ncurses_custom_fields = dict.fromkeys(StatCollector.NCURSES_CUSTOM_OUTPUT_FIELDS, None)
6060

6161
def postinit(self):
62-
for l in [self.transform_list_data, self.transform_dict_data, self.diff_generator_data,
62+
for n in [self.transform_list_data, self.transform_dict_data, self.diff_generator_data,
6363
self.output_transform_data]:
64-
self.validate_list_out(l)
64+
self.validate_list_out(n)
6565
self.output_column_positions = self._calculate_output_column_positions()
6666

6767
def set_ignore_autohide(self, new_status):
@@ -91,12 +91,12 @@ def exec_command_with_output(cmdline):
9191
return ret, proc.stdout.read().strip()
9292

9393
@staticmethod
94-
def validate_list_out(l):
94+
def validate_list_out(n):
9595
""" If the list element doesn't supply an out column - remove it """
9696

97-
for col in l:
97+
for col in n:
9898
if 'out' not in col:
99-
el = l.pop(l.index(col))
99+
el = n.pop(n.index(col))
100100
logger.error('Removed {0} column because it did not specify out value'.format(el))
101101

102102
@staticmethod
@@ -135,10 +135,10 @@ def kb_pretty_print_long(b):
135135
""" Show kb values in a human readable form. """
136136

137137
r = []
138-
for l, n in StatCollector.BYTE_MAP:
138+
for unit, n in StatCollector.BYTE_MAP:
139139
d = b / n
140140
if d:
141-
r.append(str(d) + l)
141+
r.append(str(d) + unit)
142142
b %= n
143143
return ' '.join(r)
144144

@@ -147,10 +147,10 @@ def kb_pretty_print(b):
147147
""" Show memory size as a float value in the biggest measurement units """
148148

149149
r = []
150-
for l, n in StatCollector.BYTE_MAP:
150+
for unit, n in StatCollector.BYTE_MAP:
151151
if b > n:
152152
v = round(float(b) / n, 1)
153-
r.append(str(v) + l)
153+
r.append(str(v) + unit)
154154
break
155155
if len(r) == 0:
156156
return '{0}KB'.format(str(b))
@@ -486,21 +486,21 @@ def _transform_input(self, x, custom_transformation_data=None):
486486
# behavior in case 'in' is not specified: the _dict version assumes the in
487487
# column is the same as the out one, the list emits the warning and skips
488488
# the column.
489-
def _transform_list(self, l, custom_transformation_data=None):
489+
def _transform_list(self, x, custom_transformation_data=None):
490490
result = {}
491491
# choose between the 'embedded' and external transformations
492492
if custom_transformation_data is not None:
493493
transformation_data = custom_transformation_data
494494
else:
495495
transformation_data = self.transform_list_data
496496
if transformation_data is not None:
497-
total = len(l)
497+
total = len(x)
498498
for col in transformation_data:
499499
# set the output column name
500500
attname = col['out']
501501
if 'infn' in col:
502-
if len(l) > 0:
503-
result[attname] = col['infn'](attname, l, 'optional' in col and col['optional'])
502+
if len(x) > 0:
503+
result[attname] = col['infn'](attname, x, 'optional' in col and col['optional'])
504504
else:
505505
result[attname] = None
506506
else:
@@ -513,18 +513,18 @@ def _transform_list(self, l, custom_transformation_data=None):
513513
# the result in the format we ask them to, but, on the other hand, if there is
514514
# nothing at all from them - then the problem is elsewhere and there is no need
515515
# to bleat here for each missing column.
516-
if not col.get('optional', False) and len(l) > 0:
516+
if not col.get('optional', False) and len(x) > 0:
517517
self.warn_non_optional_column(incol)
518518
else:
519-
result[attname] = l[incol]
519+
result[attname] = x[incol]
520520
# if transformation function is supplied - apply it to the input data.
521521
if 'fn' in col and result[attname] is not None:
522522
result[attname] = col['fn'](result[attname])
523523
return result
524524
raise Exception('No data for the list transformation supplied')
525525

526526
# Most of the functionality is the same as in the dict transforming function above.
527-
def _transform_dict(self, l, custom_transformation_data=None):
527+
def _transform_dict(self, x, custom_transformation_data=None):
528528
result = {}
529529
if custom_transformation_data is not None:
530530
transformation_data = custom_transformation_data
@@ -538,19 +538,19 @@ def _transform_dict(self, l, custom_transformation_data=None):
538538
# if infn is supplied - it calculates the column value possbily using other values
539539
# in the row - we don't use incoming column in this case.
540540
if 'infn' in col:
541-
if len(l) > 0:
542-
result[attname] = col['infn'](attname, l, 'optional' in col and col['optional'])
541+
if len(x) > 0:
542+
result[attname] = col['infn'](attname, x, 'optional' in col and col['optional'])
543543
else:
544544
result[attname] = None
545-
elif incol not in l:
545+
elif incol not in x:
546546
# if the column is marked as optional and it's not present in the output data
547547
# set None instead
548548
result[attname] = None
549549
# see the comment at _transform_list on why we do complain here.
550-
if not col.get('optional', False) and len(l) > 0:
550+
if not col.get('optional', False) and len(x) > 0:
551551
self.warn_non_optional_column(incol)
552552
else:
553-
result[attname] = l[incol]
553+
result[attname] = x[incol]
554554
if 'fn' in col and result[attname] is not None:
555555
result[attname] = col['fn'](result[attname])
556556
return result

pg_view/collectors/host_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _read_cpus():
118118
cpus = 0
119119
try:
120120
cpus = cpu_count()
121-
except:
121+
except Exception:
122122
logger.error('multiprocessing does not support cpu_count')
123123
return {'cores': cpus}
124124

@@ -134,7 +134,7 @@ def _read_uptime(self):
134134
try:
135135
fp = open(HostStatCollector.UPTIME_FILE, 'rU')
136136
raw_result = fp.read().split()
137-
except:
137+
except Exception:
138138
logger.error('Unable to read uptime from {0}'.format(HostStatCollector.UPTIME_FILE))
139139
finally:
140140
fp and fp.close()

pg_view/collectors/memory_collector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def _read_memory_data():
125125
result = {}
126126
try:
127127
fp = open(MemoryStatCollector.MEMORY_STAT_FILE, 'rU')
128-
for l in fp:
129-
vals = l.strip().split()
128+
for line in fp:
129+
vals = line.strip().split()
130130
if len(vals) >= 2:
131131
name, val = vals[:2]
132132
# if we have units of measurement different from kB - transform the result
@@ -141,7 +141,7 @@ def _read_memory_data():
141141
logger.error('name is too short: {0}'.format(str(name)))
142142
else:
143143
logger.error('/proc/meminfo string is not name value: {0}'.format(vals))
144-
except:
144+
except Exception:
145145
logger.error('Unable to read /proc/meminfo memory statistics. Check your permissions')
146146
return result
147147
finally:

pg_view/collectors/partition_collector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def get_io_data(pnames):
181181
try:
182182
fp = None
183183
fp = open(PartitionStatCollector.DISK_STAT_FILE, 'rU')
184-
for l in fp:
185-
elements = l.split()
184+
for line in fp:
185+
elements = line.split()
186186
for pname in pnames:
187187
if pname in elements:
188188
result[pname] = elements
@@ -191,7 +191,7 @@ def get_io_data(pnames):
191191
break
192192
if found == total:
193193
break
194-
except:
194+
except Exception:
195195
logger.error('Unable to read {0}'.format(PartitionStatCollector.DISK_STAT_FILE))
196196
result = {}
197197
finally:

pg_view/collectors/pg_collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def _read_pg_stat_activity(self):
548548
if r['pid'] != self.connection_pid:
549549
self.active_connections += 1
550550
lines = r['query'].splitlines()
551-
newlines = [re.sub('\s+', ' ', l.strip()) for l in lines]
551+
newlines = [re.sub(r'\s+', ' ', line.strip()) for line in lines]
552552
r['query'] = ' '.join(newlines)
553553
ret[r['pid']] = r
554554
self.pgcon.commit()

pg_view/models/db_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def read_postmaster_pid(work_directory, dbname):
1616
try:
1717
fp = open('{0}/postmaster.pid'.format(work_directory))
1818
pid = fp.readline().strip()
19-
except:
19+
except Exception:
2020
# XXX: do not bail out in case we are collecting data for multiple PostgreSQL clusters
2121
logger.error('Unable to read postmaster.pid for {name} at {wd}\n HINT: \
2222
make sure Postgres is running'.format(name=dbname, wd=work_directory))
@@ -170,7 +170,7 @@ def get_postmasters_directories():
170170
try:
171171
with open(f, 'rU') as fp:
172172
stat_fields = fp.read().strip().split()
173-
except:
173+
except Exception:
174174
logger.error('failed to read {0}'.format(f))
175175
continue
176176
# read PostgreSQL processes. Avoid zombies
@@ -233,7 +233,7 @@ def get_postmasters_directories():
233233
val = fp.read().strip()
234234
if val is not None and len(val) >= 2:
235235
version = float(val)
236-
except os.error as e:
236+
except os.error:
237237
logger.error(
238238
'unable to read version number from PG_VERSION directory {0}, have to skip it'.format(pg_dir))
239239
continue
@@ -259,7 +259,7 @@ def fetch_socket_inodes_for_process(pid):
259259
continue
260260
try:
261261
target = os.readlink(link)
262-
except:
262+
except Exception:
263263
logger.error('coulnd\'t read link {0}'.format(link))
264264
else:
265265
# socket:[8430]

pg_view/models/outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _init_display(self):
6565
if hasattr(curses, 'curs_set'):
6666
try:
6767
curses.curs_set(0) # make the cursor invisible
68-
except:
68+
except Exception:
6969
pass
7070
self.screen.nodelay(1) # disable delay when waiting for keyboard input
7171

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pytest
21
psycopg2

0 commit comments

Comments
 (0)