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)
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()
def test_repr(self): class Mock(dict): name = 'name' matcher = BaseMatcher(None, Mock(), None) repr(matcher)
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')