]> git.ipfire.org Git - pakfire.git/blobdiff - tests/python/tests.py
tests: Add functions to make opening files in the test env easier
[pakfire.git] / tests / python / tests.py
index 9fec904601c31a595381302f9a52ef497d7471f7..bc8509479644f1cbbf87fc93ec8913672f3e2e1c 100644 (file)
@@ -22,6 +22,11 @@ import pakfire
 import os
 import unittest
 
+# Fetch TEST_DATA_DIR
+TEST_DATA_DIR = os.environ.get("TEST_DATA_DIR")
+if not TEST_DATA_DIR:
+       raise RuntimeError("TEST_DATA_DIR is not set")
+
 class TestCase(unittest.TestCase):
        """
                This is a TestCase class based on unittest.TestCase which has
@@ -50,6 +55,22 @@ class TestCase(unittest.TestCase):
 
                return pakfire.Pakfire(ctx=ctx, path=path, **kwargs)
 
+       def path(self, *args, **kwargs):
+               """
+                       Creates a path absolute to the test environment
+               """
+               return os.path.join(TEST_DATA_DIR, *args, **kwargs)
+
+       def open(self, path, *args, **kwargs):
+               """
+                       Opens a file in the test environment
+               """
+               # Make the path absolute
+               path = self.path(path)
+
+               # Open the file
+               return open(path, *args, **kwargs)
+
 
 # Overlay for now
 main = unittest.main