File: errors.py

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (125 lines) | stat: -rw-r--r-- 4,395 bytes parent folder | download | duplicates (3)
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
'''
Define all error types used in yaml_tools.
All errors must inherit from YAMLTestError.
'''
from __future__ import print_function, division, unicode_literals


class YAMLTestError(Exception):
    """Base class for all other errors."""


class ConfigContextError(YAMLTestError):
    def __init__(self, path):
        spath = '.'.join(path)
        msg = ('Tried to enter a None context in the config tree at {}'
               .format(spath))
        super(ConfigContextError, self).__init__(msg)


class NoYAMLSupportError(YAMLTestError):
    """Raised when Yaml library is not installed."""


###############################################################################
class ConfigParserError(YAMLTestError):
    pass


class UnknownParamError(ConfigParserError):
    def __init__(self, cons, param):
        msg = ('Encounterd an unknown parameter name "{}"'
               ' when registering constraint "{}".')
        super(UnknownParamError, self).__init__(msg.format(param, cons))


class AlreadyRegisteredTagError(ConfigParserError):
    def __init__(self, tag):
        msg = 'Attempt to register {} twice.'
        super(ConfigParserError, self).__init__(msg.format(tag))


###############################################################################
class ConfigError(YAMLTestError):
    pass


class ValueTypeError(TypeError, ConfigError):
    def __init__(self, name, exp, found):
        msg = ('The value found in config does not match the type expected for'
               ' {}. Expected {} and found {} of type {}.')
        super(TypeError, self).__init__(msg.format(name, exp, found, type(found)))


class InvalidNodeError(ConfigError):
    def __init__(self, name, value):
        msg = ('The node labeled {} is not a known parameter or constraint and'
               ' have not the form of a specialisation. Value: {}')
        super(InvalidNodeError, self).__init__(msg.format(name, value))


class EmptySetError(ConfigError):
    def __init__(self, obj):
        msg = 'User tried to create an empty set with {}.'
        super(EmptySetError, self).__init__(msg.format(obj))


class NotOrderedOverlappingSetError(ConfigError):
    def __init__(self, set1, set2):
        msg = '{} and {} are overlapping but cannot be ordered.'
        super(NotOrderedOverlappingSetError, self).__init__(msg.format(set1,
                                                                       set2))


class IllegalFilterNameError(ConfigError):
    def __init__(self, name):
        msg = '{} is a reserved name, you cannot use it as a filter name.'
        super(IllegalFilterNameError, self).__init__(msg.format(name))


class MissingCallbackError(ConfigError):
    def __init__(self, obj, method):
        msg = '{} does not expose a {} method.'.format(obj, method)
        super(MissingCallbackError, self).__init__(msg)


###############################################################################
class InputFileError(YAMLTestError):
    def __init__(self, line, msg):
        msg = 'In input file at line {}:\n{}'.format(line, msg)
        super(InputFileError, self).__init__(self, msg)


class NoIteratorDefinedError(InputFileError):
    def __init__(self, doc):
        msg = ('No iterator have been found before the first document {}.'
               .format(doc.obj))
        super(NoIteratorDefinedError, self).__init__(doc.start + 1, msg)


class NotAvailableTagError(InputFileError):
    def __init__(self, tag, msg):
        msg = ('Tag {} is not available in this installation : {}'
               .format(tag, msg))
        YAMLTestError.__init__(msg)


class UntaggedDocumentError(InputFileError):
    def __init__(self, line):
        msg = ('This document does not have a tag. It cannot be identified.')
        super(UntaggedDocumentError, self).__init__(line, msg)


class TagMismatchError(InputFileError):
    def __init__(self, line, expected, found):
        msg = ('This was supposed to be tagged {} but it was {}.'
               .format(expected, found))
        super(TagMismatchError, self).__init__(line, msg)


class DuplicateDocumentError(InputFileError):
    def __init__(self, line, id):
        msg = ('There are two document with the same tag and iteration'
               ' state ({}). Please change the tag of one of them to make it'
               ' unique.').format(id)
        super(DuplicateDocumentError, self).__init__(line, msg)