File: test_exceptions.py

package info (click to toggle)
dnf5 5.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,960 kB
  • sloc: cpp: 94,312; python: 3,370; xml: 1,073; ruby: 600; sql: 250; ansic: 232; sh: 104; perl: 62; makefile: 30
file content (140 lines) | stat: -rw-r--r-- 6,050 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright Contributors to the DNF5 project.
# Copyright Contributors to the libdnf project.
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
#
# Libdnf 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 2 of the License, or
# (at your option) any later version.
#
# Libdnf 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 libdnf.  If not, see <https://www.gnu.org/licenses/>.

import unittest

import libdnf5


class TestExceptions(unittest.TestCase):
    # List of all exceptions
    EXCEPTIONS = (
        libdnf5.exception.BaseTransactionError,
        libdnf5.exception.BaseTransactionErrorNested,

        libdnf5.exception.CompsInvalidPackageType,
        libdnf5.exception.CompsInvalidPackageTypeNested,

        #        libdnf5.module.NoModuleError,
        #        libdnf5.module.NoStreamError,
        #        libdnf5.module.EnabledStreamError,
        #        libdnf5.module.EnableMultipleStreamsError,
        #        libdnf5.module.ModuleConflictError,
        #        libdnf5.module.ModuleResolveError,
        #        libdnf5.module.ModuleError,

        #        libdnf5.module.InvalidModuleStatus,

        libdnf5.exception.RepoFileDownloadError,
        libdnf5.exception.RepoFileDownloadErrorNested,
        libdnf5.exception.RepoPackageDownloadError,
        libdnf5.exception.RepoPackageDownloadErrorNested,
        libdnf5.exception.RepoCacheError,
        libdnf5.exception.RepoCacheErrorNested,

        libdnf5.exception.RepoCacheonlyError,
        libdnf5.exception.RepoCacheonlyErrorNested,
        libdnf5.exception.RepoDownloadError,
        libdnf5.exception.RepoDownloadErrorNested,
        libdnf5.exception.RepoPgpError,
        libdnf5.exception.RepoPgpErrorNested,
        libdnf5.exception.RepoRpmError,
        libdnf5.exception.RepoRpmErrorNested,
        libdnf5.exception.RepoCompsError,
        libdnf5.exception.RepoCompsErrorNested,
        libdnf5.exception.RepoIdAlreadyExistsError,
        libdnf5.exception.RepoIdAlreadyExistsErrorNested,
        libdnf5.exception.RepoError,
        libdnf5.exception.RepoErrorNested,

        libdnf5.exception.RpmNevraIncorrectInputError,
        libdnf5.exception.RpmNevraIncorrectInputErrorNested,
        libdnf5.exception.RpmSignatureCheckError,
        libdnf5.exception.RpmSignatureCheckErrorNested,
        libdnf5.exception.RpmKeyImportError,
        libdnf5.exception.RpmKeyImportErrorNested,

        libdnf5.exception.TransactionInvalidTransactionItemAction,
        libdnf5.exception.TransactionInvalidTransactionItemActionNested,
        libdnf5.exception.TransactionInvalidTransactionItemReason,
        libdnf5.exception.TransactionInvalidTransactionItemReasonNested,
        libdnf5.exception.TransactionInvalidTransactionItemState,
        libdnf5.exception.TransactionInvalidTransactionItemStateNested,
        libdnf5.exception.TransactionInvalidTransactionItemType,
        libdnf5.exception.TransactionInvalidTransactionItemTypeNested,
        libdnf5.exception.TransactionInvalidTransactionState,
        libdnf5.exception.TransactionInvalidTransactionStateNested,

        libdnf5.exception.InaccessibleConfigError,
        libdnf5.exception.InaccessibleConfigErrorNested,
        libdnf5.exception.MissingConfigError,
        libdnf5.exception.MissingConfigErrorNested,
        libdnf5.exception.InvalidConfigError,
        libdnf5.exception.InvalidConfigErrorNested,

        libdnf5.exception.ConfigParserSectionNotFoundError,
        libdnf5.exception.ConfigParserSectionNotFoundErrorNested,
        libdnf5.exception.ConfigParserOptionNotFoundError,
        libdnf5.exception.ConfigParserOptionNotFoundErrorNested,
        libdnf5.exception.ConfigParserError,
        libdnf5.exception.ConfigParserErrorNested,

        libdnf5.exception.OptionValueNotSetError,
        libdnf5.exception.OptionValueNotSetErrorNested,
        libdnf5.exception.OptionValueNotAllowedError,
        libdnf5.exception.OptionValueNotAllowedErrorNested,
        libdnf5.exception.OptionInvalidValueError,
        libdnf5.exception.OptionInvalidValueErrorNested,
        libdnf5.exception.OptionError,
        libdnf5.exception.OptionErrorNested,

        libdnf5.exception.OptionBindsOptionNotFoundError,
        libdnf5.exception.OptionBindsOptionNotFoundErrorNested,
        libdnf5.exception.OptionBindsOptionAlreadyExistsError,
        libdnf5.exception.OptionBindsOptionAlreadyExistsErrorNested,
        libdnf5.exception.OptionBindsError,
        libdnf5.exception.OptionBindsErrorNested,

        libdnf5.exception.ReadOnlyVariableError,
        libdnf5.exception.ReadOnlyVariableErrorNested,

        libdnf5.exception.FileSystemError,
        libdnf5.exception.FileSystemErrorNested,
        libdnf5.exception.SystemError,
        libdnf5.exception.SystemErrorNested,
        libdnf5.exception.RuntimeError,
        libdnf5.exception.RuntimeErrorNested,
        libdnf5.exception.Error,
        libdnf5.exception.ErrorNested,
        libdnf5.exception.UserAssertionError,
        libdnf5.exception.UserAssertionErrorNested,
        libdnf5.exception.AssertionError,
        libdnf5.exception.AssertionErrorNested,

        libdnf5.exception.NonLibdnf5Exception,
        libdnf5.exception.NonLibdnf5ExceptionNested
    )

    def test_all_exceptions_without_ctor(self):
        # Check that exceptions do not have a defined constructor.
        for ex in self.EXCEPTIONS:
            with self.assertRaises(AttributeError, msg=str(ex)) as e:
                raise ex()
            self.assertEqual(str(e.exception),
                             'No constructor defined', str(ex))