Skip to content

Commit 7656d3f

Browse files
committed
clean up test for pylint
1 parent 8687632 commit 7656d3f

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

tests/unittests/test_pulsar.py

+53-51
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
2-
import hubblestack.extmods.modules.pulsar as pulsar
3-
from salt.exceptions import CommandExecutionError
4-
52
import shutil
3+
import logging
64
import six
7-
import pyinotify
5+
6+
from salt.exceptions import CommandExecutionError
7+
import hubblestack.extmods.modules.pulsar as pulsar
8+
9+
log = logging.getLogger(__name__)
810

911
if os.environ.get('DEBUG_SHOW_PULSAR_LOGS'):
1012
import logging
@@ -145,26 +147,26 @@ class TestPulsar2():
145147
atdir = os.path.abspath(tdir)
146148
atfile = os.path.abspath(tfile)
147149

148-
def reset(self, **kw):
150+
def reset(self, **kwargs):
149151
def config_get(value, default):
150152
return default
151153

152-
if 'paths' not in kw:
153-
kw['paths'] = []
154+
if 'paths' not in kwargs:
155+
kwargs['paths'] = []
154156

155157
__salt__ = {}
156158
__salt__['config.get'] = config_get
157159
pulsar.__salt__ = __salt__
158-
pulsar.__opts__ = {'pulsar': kw}
160+
pulsar.__opts__ = {'pulsar': kwargs}
159161
pulsar.__context__ = c = {}
160162
self.nuke_tdir()
161163

162164
pulsar._get_notifier() # sets up the dequeue
163165

164166
self.events = []
165167
self.N = c['pulsar.notifier']
166-
self.wm = self.N._watch_manager
167-
self.wm.update_config()
168+
self.watch_manager = self.N._watch_manager
169+
self.watch_manager.update_config()
168170

169171
def process(self):
170172
self.events.extend([ "{change}(path)".format(**x) for x in pulsar.process() ])
@@ -181,28 +183,28 @@ def mk_tdir_and_write_tfile(self, fname=None, to_write='supz\n'):
181183
with open(self.tfile, 'w') as fh:
182184
fh.write(to_write)
183185

184-
def mk_subdir_files(self, *f, **kw):
185-
if len(f) == 1 and isinstance(f[0], (list,tuple)):
186-
f = f[0]
187-
for _f in f:
188-
_f = _f if _f.startswith(self.tdir + '/') else os.path.join(self.tdir, _f)
189-
s = _f.split('/')
190-
if s:
191-
fn = s.pop()
192-
b = ''
193-
for i in s:
194-
b = os.path.join(b,i)
186+
def mk_subdir_files(self, *files, **kwargs):
187+
if len(files) == 1 and isinstance(files[0], (list,tuple)):
188+
files = files[0]
189+
for file in files:
190+
file = file if file.startswith(self.tdir + '/') else os.path.join(self.tdir, file)
191+
split_file = file.split('/')
192+
if split_file:
193+
output_fname = split_file.pop()
194+
dir_to_make = ''
195+
for i in split_file:
196+
dir_to_make = os.path.join(dir_to_make,i)
195197
if not os.path.isdir(i):
196-
os.mkdir(b)
197-
k = ('{}_out', 'out_{}', '{}_to_write', 'to_write')
198-
for _k in k:
199-
to_write = kw.get(_k.format(fn))
198+
os.mkdir(dir_to_make)
199+
forms = ('{}_out', 'out_{}', '{}_to_write', 'to_write')
200+
for form in forms:
201+
to_write = kwargs.get(form.format(output_fname))
200202
if to_write is not None:
201203
break
202204
if to_write is None:
203205
to_write = 'supz\n'
204-
fn = os.path.join(b, fn)
205-
with open(fn, 'a') as fh:
206+
output_fname = os.path.join(dir_to_make, output_fname)
207+
with open(output_fname, 'a') as fh:
206208
fh.write(to_write if to_write is not None else 'supz\n')
207209

208210
def more_fname(self, number, base=None):
@@ -234,33 +236,33 @@ def sla(x,e):
234236

235237
def test_add_watch(self, modality='add-watch'):
236238
o = {}
237-
kw = { self.atdir: o }
239+
kwargs = { self.atdir: o }
238240

239241
if modality in ('watch_new_files', 'watch_files'):
240242
o[modality] = True
241243

242-
self.reset(**kw)
244+
self.reset(**kwargs)
243245

244246
# NOTE: without new_files and/or without watch_files parent_db should
245247
# remain empty, and we shouldn't get a watch on tfile
246248

247249
os.mkdir(self.tdir)
248250

249251
if modality == 'add-watch':
250-
self.wm.add_watch(self.tdir, pulsar.DEFAULT_MASK)
252+
self.watch_manager.add_watch(self.tdir, pulsar.DEFAULT_MASK)
251253

252254
elif modality in ('watch', 'watch_new_files', 'watch_files'):
253-
self.wm.watch(self.tdir)
255+
self.watch_manager.watch(self.tdir)
254256

255257
else:
256258
raise Exception("unknown modality")
257259

258260
self.process()
259261
assert len(self.events) == 0
260-
assert self.wm.watch_db.get(self.tdir) is None
261-
assert self.wm.watch_db.get(self.atdir) > 0
262-
assert len(self.wm.watch_db) == 1
263-
assert not isinstance(self.wm.parent_db.get(self.atdir), set)
262+
assert self.watch_manager.watch_db.get(self.tdir) is None
263+
assert self.watch_manager.watch_db.get(self.atdir) > 0
264+
assert len(self.watch_manager.watch_db) == 1
265+
assert not isinstance(self.watch_manager.parent_db.get(self.atdir), set)
264266

265267
self.mk_tdir_and_write_tfile() # write supz to tfile
266268

@@ -270,11 +272,11 @@ def test_add_watch(self, modality='add-watch'):
270272
assert self.events[1].startswith('IN_MODIFY')
271273

272274
if modality in ('watch_files', 'watch_new_files'):
273-
assert len(self.wm.watch_db) == 2
274-
assert isinstance(self.wm.parent_db.get(self.atdir), set)
275+
assert len(self.watch_manager.watch_db) == 2
276+
assert isinstance(self.watch_manager.parent_db.get(self.atdir), set)
275277
else:
276-
assert len(self.wm.watch_db) == 1
277-
assert not isinstance(self.wm.parent_db.get(self.atdir), set)
278+
assert len(self.watch_manager.watch_db) == 1
279+
assert not isinstance(self.watch_manager.parent_db.get(self.atdir), set)
278280

279281
self.nuke_tdir()
280282

@@ -290,15 +292,15 @@ def test_recurse_without_watch_files(self):
290292

291293
self.reset(**c1)
292294
self.mk_subdir_files('blah1','a/b/c/blah2')
293-
self.wm.watch(self.tdir)
294-
self.wm.prune()
295-
s1 = set(self.wm.watch_db)
295+
self.watch_manager.watch(self.tdir)
296+
self.watch_manager.prune()
297+
s1 = set(self.watch_manager.watch_db)
296298

297299
self.reset(**c2)
298300
self.mk_subdir_files('blah1','a/b/c/blah2')
299-
self.wm.watch(self.tdir)
300-
self.wm.prune()
301-
s2 = set(self.wm.watch_db)
301+
self.watch_manager.watch(self.tdir)
302+
self.watch_manager.prune()
303+
s2 = set(self.watch_manager.watch_db)
302304

303305
s0a = set([self.atdir])
304306
s0b = [self.atdir]
@@ -325,18 +327,18 @@ def config_make_files_watch_process_reconfig(self, config, reconfig=None, mk_fil
325327
"""
326328
self.reset(**config)
327329
self.mk_tdir_and_write_tfile()
328-
self.wm.watch(self.tdir)
329-
s0 = set(self.wm.watch_db)
330+
self.watch_manager.watch(self.tdir)
331+
s0 = set(self.watch_manager.watch_db)
330332
if mk_files > 0:
331333
self.mk_more_files(count=mk_files)
332334
self.process()
333-
s1 = set(self.wm.watch_db)
335+
s1 = set(self.watch_manager.watch_db)
334336
if reconfig is None:
335-
del self.wm.cm.nc_config[ self.atdir ]
337+
del self.watch_manager.cm.nc_config[ self.atdir ]
336338
else:
337-
self.wm.cm.nc_config[ self.atdir ] = reconfig
339+
self.watch_manager.cm.nc_config[ self.atdir ] = reconfig
338340
self.process()
339-
s2 = set(self.wm.watch_db)
341+
s2 = set(self.watch_manager.watch_db)
340342
return s0,s1,s2
341343

342344
def test_pruning_watch_files_false(self):

0 commit comments

Comments
 (0)