summaryrefslogtreecommitdiff
path: root/scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py
diff options
context:
space:
mode:
authorManel Caro <mcaro@iseebcn.com>2019-03-09 21:25:56 +0100
committerManel Caro <mcaro@iseebcn.com>2019-03-09 21:25:56 +0100
commit9332c933fc05f42882640c9a4e35fab09854af84 (patch)
tree2b9b00b5a411b27f9705603c0d93b8925afd4677 /scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py
downloadboard-9332c933fc05f42882640c9a4e35fab09854af84.zip
board-9332c933fc05f42882640c9a4e35fab09854af84.tar.gz
board-9332c933fc05f42882640c9a4e35fab09854af84.tar.bz2
Board: Client Test Suite Initial Commit
Diffstat (limited to 'scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py')
-rw-r--r--scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py108
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py b/scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py
new file mode 100644
index 0000000..b579e39
--- /dev/null
+++ b/scripts/PYTHON_SOFTWARE/test/helpers/syscmd.py
@@ -0,0 +1,108 @@
+import unittest
+import subprocess
+from test.helpers.globalVariables import globalVar
+
+
+class TestSysCommand(unittest.TestCase):
+ __str_cmd = None
+ __testname = None
+ __outfilename = None
+ __outdata = None
+ __outtofile = False
+
+ def __init__(self, testname, testfunc, str_cmd, outtofile = False):
+ """ init """
+ super(TestSysCommand, self).__init__(testfunc)
+ self.__str_cmd = str_cmd
+ self.__testname = testname
+ self.__outtofile = outtofile
+ self._testMethodDoc = testname
+ if self.__outtofile is True:
+ self.__outfilename = '/tmp/{}.txt'.format(testname)
+
+ def getName(self):
+ return self.__testname
+
+ def execute(self):
+ res = -1
+ try:
+ completed = subprocess.run(
+ self.__str_cmd,
+ check=True,
+ shell=True,
+ stdout=subprocess.PIPE,
+ )
+ self.assertTrue(completed.returncode is 0)
+ if completed.returncode is 0:
+ if self.__outtofile is True:
+ f = open(self.__outfilename, 'wb')
+ f.write(completed.stdout)
+ f.close()
+ res = 0
+ else:
+ res = -3
+ outdata = completed.stdout
+ self.longMessage=str(outdata).replace("'","")
+ self.assertTrue(True)
+ except subprocess.CalledProcessError as err:
+ self.assertTrue(False)
+ res = -1
+ except Exception as t:
+ res = -2
+ return res
+
+ def remove_file(self):
+ pass
+
+class SysCommand(object):
+ __str_cmd = None
+ __cmdname = None
+ __outdata = None
+ __errdata = None
+
+ def __init__(self, cmdname, str_cmd):
+ """ init """
+ self.__str_cmd = str_cmd
+ self.__cmdname = cmdname
+
+ def getName(self):
+ return self.__testname
+
+ def execute(self):
+ res = -1
+ try:
+ self.__outdata = None
+ self.__errdata = None
+ completed = subprocess.run(
+ self.__str_cmd,
+ check=True,
+ shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE
+ )
+ self.__outdata = completed.stdout
+ if completed.returncode is 0:
+ res = 0
+ if completed.stderr.decode('ascii') != "":
+ res = -1
+ self.__errdata = completed.stderr
+ except subprocess.CalledProcessError as err:
+ res = -2
+ except Exception as t:
+ res = -3
+ return res
+
+ def getOutput(self):
+ return self.__outdata
+
+ def getOutErr(self):
+ return self.__errdata
+
+ def getOutputlines(self):
+ return self.__outdata.splitlines()
+
+ def save_file(self, fname):
+ f = open(fname, 'wb')
+ f.write(self.__outdata)
+ f.close()
+