close open filehandles. more tests

This commit is contained in:
Edwin Eefting 2020-05-17 16:59:46 +02:00
parent 2305fdf033
commit 138c913e58
4 changed files with 24 additions and 4 deletions

View File

@ -1,3 +1,5 @@
import subprocess
import random
@ -9,6 +11,8 @@ from pprint import *
from bin.zfs_autobackup import *
def shelltest(cmd):
"""execute and print result as nice copypastable string for unit tests (adds extra newlines on top/bottom)"""
ret=(subprocess.check_output(cmd , shell=True).decode('utf-8'))

View File

@ -435,12 +435,16 @@ class ExecuteNode(Logger):
if p.poll()!=None and ((not isinstance(input, subprocess.Popen)) or input.poll()!=None) and eof_count==len(selectors):
break
p.stderr.close()
p.stdout.close()
if self.debug_output:
self.debug("EXIT > {}".format(p.returncode))
#handle piped process error output and exit codes
if isinstance(input, subprocess.Popen):
input.stderr.close()
input.stdout.close()
if self.debug_output:
self.debug("EXIT |> {}".format(input.returncode))
@ -450,7 +454,6 @@ class ExecuteNode(Logger):
if valid_exitcodes and p.returncode not in valid_exitcodes:
raise(subprocess.CalledProcessError(p.returncode, encoded_cmd))
if return_stderr:
return ( output_lines, error_lines )

View File

@ -9,7 +9,7 @@ fi
source $VIRTUAL_ENV/bin/activate || true
# test needs ssh access to localhost for testing
if ! [ -t /root/.ssh/id_rsa ]; then
if ! [ -e /root/.ssh/id_rsa ]; then
ssh-keygen -t rsa -f /root/.ssh/id_rsa -P '' || exit 1
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys || exit 1
ssh -oStrictHostKeyChecking=no localhost true || exit 1
@ -22,7 +22,9 @@ echo
coverage report
#this does automatic travis CI/https://coveralls.io/ intergration:
echo "Submitting to coveralls.io:"
coveralls
if which coveralls > /dev/null; then
echo "Submitting to coveralls.io:"
coveralls
fi
exit $EXIT

11
test_zfsautobackup.py Normal file
View File

@ -0,0 +1,11 @@
from basetest import *
class TestZfsAutobackup(unittest.TestCase):
def setUp(self):
prepare_zpools()
return super().setUp()
def test_defaults(self):
self.assertFalse(ZfsAutobackup("test test_target1".split(" ")).run())