mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
tests/fprintd-utils: Add utility function to stop the utility process
This avoids addCleanup ordering errors and also errors when we may try to
print an invalid stdout pipe (like when we have processed it all), as python
might fail with something like:
======================================================================
ERROR: test_fprintd_multiple_verify_fails (__main__.TestFprintdUtilsVerify)
----------------------------------------------------------------------
Traceback (most recent call last):
File "~/GNOME/fprintd/tests/test_fprintd_utils.py", line 102, in <lambda>
self.addCleanup(lambda: print(process.stdout.read()))
File "/usr/lib/python3.8/codecs.py", line 321, in decode
data = self.buffer + input
TypeError: can't concat NoneType to bytes
This commit is contained in:
@ -93,15 +93,24 @@ class TestFprintdUtilsBase(dbusmock.DBusTestCase):
|
||||
flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL)
|
||||
fcntl.fcntl(process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
|
||||
|
||||
self.addCleanup(process.wait)
|
||||
self.addCleanup(process.terminate)
|
||||
self.addCleanup(lambda: print(process.stdout.read()))
|
||||
self.addCleanup(self.try_stop_utility_process, process)
|
||||
|
||||
if sleep:
|
||||
time.sleep(self.sleep_time)
|
||||
|
||||
return process
|
||||
|
||||
def stop_utility_process(self, process):
|
||||
print(process.stdout.read())
|
||||
process.terminate()
|
||||
process.wait()
|
||||
|
||||
def try_stop_utility_process(self, process):
|
||||
try:
|
||||
self.stop_utility_process(process)
|
||||
except:
|
||||
pass
|
||||
|
||||
def get_process_output(self, process):
|
||||
out = process.stdout.read()
|
||||
self.addCleanup(print, out)
|
||||
|
||||
Reference in New Issue
Block a user