Exemple #1
0
    def test_duplicate_section_names(self):
        class Mock(dict):
            name = 'name'

        matcher = BaseMatcher(None, Mock(), None)
        matcher._sectionnames['foo'] = None

        self.assertRaisesRegexp(ConfigurationError,
                                "section names must not be re-used",
                                matcher.addSection, None, 'foo', None)
Exemple #2
0
    def test_duplicate_section_names(self):
        class Mock(dict):
            name = 'name'

        matcher = BaseMatcher(None, Mock(), None)
        matcher._sectionnames['foo'] = None

        self.assertRaisesRegexp(ConfigurationError,
                                "section names must not be re-used",
                                matcher.addSection,
                                None, 'foo', None)
Exemple #3
0
    def test_construct_errors(self):

        class MockType(object):
            attribute = 'attr'

            _multi = True
            _section = True

            def ismulti(self):
                return self._multi

            def issection(self):
                return self._section

        type_ = []
        matcher = BaseMatcher(None, type_, None)
        type_.append(('key', MockType()))

        class MockSection(object):
            def getSectionDefinition(self):
                return self

            def datatype(self, _s):
                raise ValueError()

        matcher._values['attr'] = [MockSection()]

        with self.assertRaises(DataConversionError):
            matcher.constuct()

        type_[0][1]._multi = False
        matcher._values['attr'] = MockSection()
        with self.assertRaises(DataConversionError):
            matcher.constuct()
Exemple #4
0
    def test_repr(self):

        class Mock(dict):
            name = 'name'

        matcher = BaseMatcher(None, Mock(), None)
        repr(matcher)
Exemple #5
0
    def test_create_child_bad_name(self):
        class MockType(list):
            name = 'foo'
            sectiontype = None

            def getsectioninfo(self, type_name, name):
                return self

            def isabstract(self):
                return False

            def isAllowedName(self, name):
                return False

        t = MockType()
        t.sectiontype = MockType()
        matcher = BaseMatcher(None, t, None)
        self.assertRaisesRegexp(ConfigurationError, 'is not an allowed name',
                                matcher.createChildMatcher, MockType(),
                                'ignored')