From: Michael Tremer Date: Mon, 11 Jan 2021 17:55:42 +0000 (+0000) Subject: python: Add tests for execute() X-Git-Tag: 0.9.28~1285^2~892 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b95b06f43c1bf4599a30d094448aa8095751bc7;p=pakfire.git python: Add tests for execute() Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 5667151d0..80789223c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -603,6 +603,7 @@ TESTS_ENVIRONMENT = \ dist_check_SCRIPTS = \ tests/python/cgroups.py \ + tests/python/execute.py \ tests/python/test.py TESTS = \ diff --git a/tests/python/execute.py b/tests/python/execute.py new file mode 100755 index 000000000..b9d0e254a --- /dev/null +++ b/tests/python/execute.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 + +import pakfire +import unittest + +class Test(unittest.TestCase): + """ + This tests the execute command + """ + def setUp(self): + self.pakfire = pakfire.Pakfire("/") + + def test_execute(self): + r = self.pakfire.execute(["/usr/bin/sleep", "0"]) + + self.assertIsNone(r) + + def test_environ(self): + r = self.pakfire.execute(["/bin/sh", "-c", "echo ${VAR1}"], + environ={"VAR1" : "VAL1"}) + + self.assertIsNone(r) + + def test_invalid_inputs(self): + # Arguments + with self.assertRaises(TypeError): + self.pakfire.execute("/usr/bin/sleep") + + with self.assertRaises(TypeError): + self.pakfire.execute(["/usr/bin/sleep", 1]) + + with self.assertRaises(TypeError): + self.pakfire.execute(("/usr/bin/sleep", "--help")) + + # Environment + with self.assertRaises(TypeError): + self.pakfire.execute(["/usr/bin/sleep", "--help"], environ={"VAR1" : 1}) + + with self.assertRaises(TypeError): + self.pakfire.execute(["/usr/bin/sleep", "--help"], environ={1 : "VAL1"}) + + with self.assertRaises(TypeError): + self.pakfire.execute(["/usr/bin/sleep", "--help"], environ="VAR1=VAL1") + + def test_execute_non_existant_command(self): + """ + Executing non-existant commands should raise an error + """ + with self.assertRaises(pakfire.CommandExecutionError): + self.pakfire.execute(["/usr/bin/does-not-exist"]) + + # This is an interactive test which cannot be performed automatically + #def test_shell(self): + # self.pakfire.execute(["/bin/bash", "-i"]) + + +if __name__ == "__main__": + unittest.main()