]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Build a common basis for Python tests
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 25 Jan 2024 16:01:09 +0000 (16:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 25 Jan 2024 16:01:09 +0000 (16:01 +0000)
This new class has some methods that make it easy for us to set up some
simple Pakfire environments.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/python/keys.py
tests/python/tests.py [new file with mode: 0644]

index 92000e27c728f2457e11dcaa26a96562de6aaa01..2310118c70e64a2001eda9237def3ba0d5972045 100644 (file)
@@ -1129,6 +1129,7 @@ TESTSUITE_LDADD = \
        libpakfire-internal.la
 
 TESTS_ENVIRONMENT = \
+       TEST_CONFIG_FILE="$(abs_top_srcdir)/tests/pakfire/pakfire.conf" \
        TEST_DATA_DIR="$(abs_top_srcdir)/tests/data" \
        TEST_STUB_ROOT="$(TEST_STUB_ROOT)" \
        PAKFIRE_LOG=debug \
@@ -1139,6 +1140,9 @@ dist_check_SCRIPTS = \
        tests/python/jail.py \
        tests/python/package.py
 
+EXTRA_DIST += \
+       tests/python/tests.py
+
 TESTS = \
        $(check_PROGRAMS) \
        $(dist_check_SCRIPTS)
index 14473ca90ab4e5185ebff2f0e0b6b4cfccfcca6a..0c84ac0edcfcb956fbbce5ffeca402ff0f687823 100755 (executable)
 
 import os
 import pakfire
-import unittest
 
-class KeysTests(unittest.TestCase):
+import tests
+
+class KeysTests(tests.TestCase):
        """
                This tests the keys
        """
        def setUp(self):
-               path = os.environ.get("TEST_STUB_ROOT")
-               if not path:
-                       raise RuntimeError("TEST_STUB_ROOT is not defined")
-
-               self.pakfire = pakfire.Pakfire(path)
+               self.pakfire = self.setup_pakfire()
 
        def test_generate(self):
                """
@@ -91,4 +88,4 @@ class KeysTests(unittest.TestCase):
 
 
 if __name__ == "__main__":
-       unittest.main()
+       tests.main()
diff --git a/tests/python/tests.py b/tests/python/tests.py
new file mode 100644 (file)
index 0000000..9fec904
--- /dev/null
@@ -0,0 +1,55 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2024 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import pakfire
+import os
+import unittest
+
+class TestCase(unittest.TestCase):
+       """
+               This is a TestCase class based on unittest.TestCase which has
+               a couple of handy methods that we frequently need.
+       """
+       def setup_ctx(self, path=None, **kwargs):
+               """
+                       Sets up a new Pakfire context
+               """
+               if path is None:
+                       path = os.environ.get("TEST_CONFIG_FILE")
+
+               # Return a new context
+               return pakfire.Ctx(path=path, **kwargs)
+
+       def setup_pakfire(self, ctx=None, path=None, **kwargs):
+               """
+                       Sets up a new Pakfire environment
+               """
+               # Create a context if none given
+               if ctx is None:
+                       ctx = self.setup_ctx()
+
+               if path is None:
+                       path = os.environ.get("TEST_STUB_ROOT")
+
+               return pakfire.Pakfire(ctx=ctx, path=path, **kwargs)
+
+
+# Overlay for now
+main = unittest.main