Commit 97a57742 authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Pylint fixes.

Some pylint fixes, including some that appear to have been actual bugs -
the inspect module was never imported, so it's not clear why the test
code worked.
parent 135660ea
...@@ -49,7 +49,6 @@ try: ...@@ -49,7 +49,6 @@ try:
except ImportError: except ImportError:
# No fcntl module; might be running on non-POSIX system # No fcntl module; might be running on non-POSIX system
fcntl = None fcntl = None
pass
try: try:
# Python 2 has Queue with a capital # Python 2 has Queue with a capital
...@@ -166,7 +165,7 @@ class StreamedInput(object): ...@@ -166,7 +165,7 @@ class StreamedInput(object):
fd = self.stdoutfd fd = self.stdoutfd
if fcntl: if fcntl:
flags = fcntl.fcntl(fd, fcntl.F_GETFL) flags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) # pylint: disable=no-member
else: else:
print("Warning: Cannot mark subprocess output as non-blocking") print("Warning: Cannot mark subprocess output as non-blocking")
...@@ -361,7 +360,7 @@ class StreamedInput(object): ...@@ -361,7 +360,7 @@ class StreamedInput(object):
try: try:
return self.data_buffer.get_nowait() return self.data_buffer.get_nowait()
except Queue.Empty: except queue.Empty:
return None return None
def is_running(self): def is_running(self):
......
...@@ -8,6 +8,9 @@ Class: Functional ...@@ -8,6 +8,9 @@ Class: Functional
Type: Unit test Type: Unit test
""" """
# Some tests just check that we don't crash.
# pylint: disable=no-self-use
import inspect import inspect
import os import os
import psutil import psutil
...@@ -238,7 +241,7 @@ class Test41DataFunctionObjectAPIs(BaseDataFunction): ...@@ -238,7 +241,7 @@ class Test41DataFunctionObjectAPIs(BaseDataFunction):
with self.assertRaises(streamedinput.StreamedInputNotSimpleError): with self.assertRaises(streamedinput.StreamedInputNotSimpleError):
for _ in si: for _ in si:
self.assertTrue(False, "This should never happen") self.assertTrue(False, "There should not be items here") # pylint: disable=redundant-unittest-assert
def test_002_read_fails(self): def test_002_read_fails(self):
self.data_expects = ['foo\n'] self.data_expects = ['foo\n']
...@@ -320,6 +323,7 @@ class Test50CompleteFunction(BaseCompleteFunction): ...@@ -320,6 +323,7 @@ class Test50CompleteFunction(BaseCompleteFunction):
class Test80Repr(BaseStreamedInput): class Test80Repr(BaseStreamedInput):
called = None
def test_001_before_start(self): def test_001_before_start(self):
si = streamedinput.StreamedInput(['true']) si = streamedinput.StreamedInput(['true'])
...@@ -339,7 +343,7 @@ class Test80Repr(BaseStreamedInput): ...@@ -339,7 +343,7 @@ class Test80Repr(BaseStreamedInput):
self.assertIn("data_chunks=0", repr(si)) self.assertIn("data_chunks=0", repr(si))
def test_003_with_datafunc(self): def test_003_with_datafunc(self):
def dummy(data): def dummy(_):
pass pass
si = streamedinput.StreamedInput(['true'], data_function=dummy) si = streamedinput.StreamedInput(['true'], data_function=dummy)
...@@ -362,7 +366,7 @@ class Test80Repr(BaseStreamedInput): ...@@ -362,7 +366,7 @@ class Test80Repr(BaseStreamedInput):
def test_005_running_state(self): def test_005_running_state(self):
self.called = False self.called = False
def test_func(data): def test_func(_):
self.assertIn('started=True', repr(si)) self.assertIn('started=True', repr(si))
self.assertIn("stopped=running", repr(si)) self.assertIn("stopped=running", repr(si))
self.called = True self.called = True
...@@ -404,7 +408,7 @@ class Test80Repr(BaseStreamedInput): ...@@ -404,7 +408,7 @@ class Test80Repr(BaseStreamedInput):
time.sleep(0.2) time.sleep(0.2)
self.assertTrue(si.eof(), "We should be at the end of the stream") self.assertTrue(si.eof(), "We should be at the end of the stream")
else: else:
self.assertTrue(False, "WE SHOULD NOT GET HERE") self.assertTrue(False, "Invalid data received") # pylint: disable=redundant-unittest-assert
self.called = True self.called = True
si = streamedinput.StreamedInput('echo foo && sleep 1 && echo bar', shell=True, data_function=test_func) si = streamedinput.StreamedInput('echo foo && sleep 1 && echo bar', shell=True, data_function=test_func)
...@@ -428,8 +432,10 @@ class BaseThreadedInput(BaseStreamedInput): ...@@ -428,8 +432,10 @@ class BaseThreadedInput(BaseStreamedInput):
frames = inspect.stack() frames = inspect.stack()
try: try:
caller = frames[1] caller = frames[1]
# We'll check whether the name of the module we're in matches the
# caller. If so, we're really inside this test code.
if caller[0].f_globals['__name__'] == \ if caller[0].f_globals['__name__'] == \
really_call_ThreadedStreamedInput.func_globals['__name__']: really_call_ThreadedStreamedInput.__globals__['__name__']:
# We're in this test code, so divert to the threaded call # We're in this test code, so divert to the threaded call
return streamedinput.ThreadedStreamedInput(*args, **kwargs) return streamedinput.ThreadedStreamedInput(*args, **kwargs)
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment