]>
Commit | Line | Data |
---|---|---|
ecfab818 MT |
1 | #!/usr/bin/python3 |
2 | ############################################################################### | |
3 | # # | |
4 | # Pakfire - The IPFire package management system # | |
5 | # Copyright (C) 2024 Pakfire development team # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | import logging | |
23 | import pakfire | |
24 | ||
25 | import tests | |
26 | ||
27 | class CtxTests(tests.TestCase): | |
28 | """ | |
29 | This tests the pakfire context | |
30 | """ | |
31 | def test_create(self): | |
32 | """ | |
33 | Create a context without any further ado | |
34 | """ | |
35 | ctx = self.setup_ctx() | |
36 | ||
37 | self.assertIsInstance(ctx, pakfire.Ctx) | |
38 | ||
39 | # Logging | |
40 | ||
41 | def test_log_default(self): | |
42 | """ | |
43 | Tests if there is any log output if the default logger is being used | |
44 | """ | |
45 | logger = logging.getLogger("pakfire") | |
46 | ||
47 | with self.assertLogs(logger, logging.DEBUG): | |
48 | self.setup_pakfire() | |
49 | ||
50 | def test_log_custom(self): | |
51 | """ | |
52 | Tests if log messages can be received using a custom logger | |
53 | """ | |
54 | # A simple logger that stores everything it receives in a buffer | |
55 | class Logger(object): | |
56 | def __init__(self): | |
57 | self.buffer = [] | |
58 | ||
59 | def log(self, *args): | |
60 | self.buffer.append(args) | |
61 | ||
62 | logger = Logger() | |
63 | ||
64 | # Setup a new context | |
65 | ctx = self.setup_ctx() | |
66 | ||
67 | # Configure the logger | |
68 | ctx.set_logger(logger) | |
69 | ||
70 | # Create a new Pakfire instance to create some log messages | |
71 | self.setup_pakfire(ctx=ctx) | |
72 | ||
73 | # Check if we have received anything | |
74 | self.assertTrue(logger.buffer) | |
75 | ||
76 | ||
77 | if __name__ == "__main__": | |
78 | tests.main() |