]> git.ipfire.org Git - pakfire.git/commitdiff
python: Add tests for execute()
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 Jan 2021 17:55:42 +0000 (17:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 Jan 2021 17:55:42 +0000 (17:55 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/python/execute.py [new file with mode: 0755]

index 5667151d0a6e4e8b300116257df6afd1ff0a54e7..80789223cecfe5ea41db8cce3eab317451a94488 100644 (file)
@@ -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 (executable)
index 0000000..b9d0e25
--- /dev/null
@@ -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()