]>
git.ipfire.org Git - pakfire.git/blob - tests/python/tests.py
1 ###############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2024 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 ###############################################################################
27 TEST_DATA_DIR
= os
.environ
.get("TEST_DATA_DIR")
29 raise RuntimeError("TEST_DATA_DIR is not set")
31 class TestCase(unittest
.TestCase
):
33 This is a TestCase class based on unittest.TestCase which has
34 a couple of handy methods that we frequently need.
36 def setup_ctx(self
, path
=None, **kwargs
):
38 Sets up a new Pakfire context
41 path
= os
.environ
.get("TEST_CONFIG_FILE")
43 # Return a new context
44 return pakfire
.Ctx(path
=path
, **kwargs
)
46 def setup_pakfire(self
, ctx
=None, path
=None, **kwargs
):
48 Sets up a new Pakfire environment
50 # Create a context if none given
52 ctx
= self
.setup_ctx()
55 path
= os
.environ
.get("TEST_STUB_ROOT")
57 return pakfire
.Pakfire(ctx
=ctx
, path
=path
, **kwargs
)
59 def path(self
, *args
, **kwargs
):
61 Creates a path absolute to the test environment
63 return os
.path
.join(TEST_DATA_DIR
, *args
, **kwargs
)
65 def open(self
, path
, *args
, **kwargs
):
67 Opens a file in the test environment
69 # Make the path absolute
70 path
= self
.path(path
)
73 return open(path
, *args
, **kwargs
)
77 Creates a temporary directory
79 return tempfile
.TemporaryDirectory(prefix
="pakfire-test-")