示例#1
0
 def test_creation(self):
     definition = DefinitionElement()
     self.assertTrue(isinstance(definition, Definition))
     definition = DefinitionElement('name')
     self.assertTrue(isinstance(definition, Definition))
     definition = DefinitionElement('name', {'value': 'value'})
     self.assertTrue(isinstance(definition, Definition))
示例#2
0
 def test_to_string_definitions(self):
     config = MyServerConfig([
         DefinitionElement('a'),
         DefinitionTree(
             definitions=[DefinitionElement('b'),
                          DefinitionElement('c')])
     ])
     copy = MyServerConfig.from_lxml_element(config.to_lxml_element())
     self.assertEqual(config, copy)
示例#3
0
 def setUp(self):
     self.definitions = []
     self.definitions.append(
         DefinitionElement('http.use_error_file', {'value': 'YES'}))
     self.definitions.append(
         DefinitionElement('http.error.file.404', {'value': '404.html'}))
     self.definitions.append(
         DefinitionTree('http.default_file', [
             DefinitionElement(attributes={'value': 'index.html'}),
             DefinitionElement(attributes={'value': 'index.htm'})
         ]))
示例#4
0
 def test_search_by_name(self):
     element_0 = DefinitionElement('a')
     element_1 = DefinitionElement('b')
     element_2 = DefinitionElement('a')
     tree = DefinitionTree('x', definitions = [element_0, element_1, element_2])
     self.assertEqual(element_1, tree.search_by_name('b'))
     self.assertEqual(element_2, tree.search_by_name('a'))
     self.assertEqual(None, tree.search_by_name('c'))
     self.assertEqual(tree, tree.search_by_name('x'))
     tree = DefinitionTree('b', definitions = [element_0, element_1, element_2])
     self.assertEqual(element_1, tree.search_by_name('b'))
示例#5
0
 def test_search_by_name(self):
     def_list = DefinitionList()
     self.assertEqual(None, def_list.search_by_name('x'))
     element_0 = DefinitionElement('x')
     def_list.add_definition(element_0)
     self.assertEqual(element_0, def_list.search_by_name('x'))
     element_1 = DefinitionElement('x')
     def_list.add_definition(element_1)
     self.assertEqual(element_1, def_list.search_by_name('x'))
     element_2 = DefinitionElement('x')
     tree_1 = DefinitionTree('t', definitions = [element_2])
     self.assertEqual(element_2, def_list.search_by_name('x'))
     def_list.add_definition(element_1)
     self.assertEqual(element_1, def_list.search_by_name('x'))
示例#6
0
    def test_from_lxml_definitions(self):
        text = '''<MYSERVER>
  <DEFINE name="a" />
  <DEFINE>
    <DEFINE name="b" />
    <DEFINE name="c" />
  </DEFINE>
</MYSERVER>'''
        config = MyServerConfig.from_lxml_element(etree.XML(text))
        right = MyServerConfig([
            DefinitionElement('a'),
            DefinitionTree(
                definitions=[DefinitionElement('b'),
                             DefinitionElement('c')])
        ])
        self.assertEqual(config, right)
示例#7
0
 def test_equality(self):
     self.assertEqual(DefinitionElement('name', {'some': 'attributes'}),
                      DefinitionElement('name', {'some': 'attributes'}))
     self.assertNotEqual(DefinitionElement('name1'),
                         DefinitionElement('name2'))
     self.assertNotEqual(DefinitionElement('name', {'attribute': '1'}),
                         DefinitionElement('name', {'attribute': '2'}))
     self.assertNotEqual(DefinitionElement(), 'different type')
示例#8
0
 def test_definitions(self):
     def_list = DefinitionList()
     self.assertEqual([], def_list.get_definitions())
     counter = 0
     for definition in self.definitions:
         def_list.add_definition(definition)
         counter += 1
         self.assertEqual(self.definitions[:counter],
                          def_list.get_definitions())
     for counter in xrange(len(self.definitions)):
         self.assertEqual(self.definitions[counter],
                          def_list.get_definition(counter))
     def_list.add_definition(DefinitionElement('test'), 1)
     self.assertEqual(DefinitionElement('test'), def_list.get_definition(1))
     def_list.remove_definition(1)
     self.assertEqual(self.definitions, def_list.get_definitions())
     for counter in xrange(len(self.definitions)):
         def_list.remove_definition(0)
         self.assertEqual(self.definitions[counter + 1:],
                          def_list.get_definitions())
示例#9
0
 def test_definitions(self):
     config = MyServerConfig()
     self.assertEqual([], config.get_definitions())
     counter = 0
     for definition in self.definitions:
         config.add_definition(definition)
         counter += 1
         self.assertEqual(self.definitions[:counter],
                          config.get_definitions())
     for counter in xrange(len(self.definitions)):
         self.assertEqual(self.definitions[counter],
                          config.get_definition(counter))
     config.add_definition(DefinitionElement('test'), 1)
     self.assertEqual(DefinitionElement('test'), config.get_definition(1))
     config.remove_definition(1)
     self.assertEqual(self.definitions, config.get_definitions())
     for counter in xrange(len(self.definitions)):
         config.remove_definition(0)
         self.assertEqual(self.definitions[counter + 1:],
                          config.get_definitions())
示例#10
0
 def setUp(self):
     self.definitions = []
     self.definitions.append(DefinitionElement('a'))
     self.definitions.append(DefinitionElement('b'))
     self.definitions.append(DefinitionElement('c'))
示例#11
0
 def setUp(self):
     self.element_0 = DefinitionElement('test', {'value': 'x'})
     self.element_1 = DefinitionElement(attributes = {'a': 'b', 'b': 'c'})
示例#12
0
 def test_from_lxml(self):
     text = '<DEFINE />'
     definition = DefinitionElement.from_lxml_element(etree.XML(text))
     right = DefinitionElement()
     self.assertEqual(definition, right)
示例#13
0
 def test_to_lxml_full(self):
     definition = DefinitionElement('test', {'value': 'x', 'a': 'b'})
     copy = DefinitionElement.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
示例#14
0
 def test_search_by_name(self):
     definition = DefinitionElement('a')
     self.assertEqual(None, definition.search_by_name('b'))
     self.assertEqual(definition, definition.search_by_name('a'))
示例#15
0
 def test_value(self):
     definition = DefinitionElement('name', {'value': 'x'})
     self.assertEqual('x', definition.get_attribute('value'))
     definition.set_attribute('value', 'y')
     self.assertEqual('y', definition.get_attribute('value'))
     definition.set_attribute('value', None)
     self.assertEqual(None, definition.get_attribute('value'))
     definition.remove_attribute('value')
     self.assertRaises(KeyError, definition.get_attribute, 'value')
     definition = DefinitionElement()
     self.assertRaises(KeyError, definition.get_attribute, 'value')
示例#16
0
 def test_from_string_name(self):
     text = '<DEFINE name="test" />'
     definition = DefinitionElement.from_string(text)
     right = DefinitionElement(name = "test")
     self.assertEqual(definition, right)
示例#17
0
 def test_from_xml_name(self):
     text = '<DEFINE name="test" />'
     definition = DefinitionElement.from_lxml_element(etree.XML(text))
     right = DefinitionElement(name = "test")
     self.assertEqual(definition, right)
示例#18
0
 def test_to_string_attributes(self):
     definition = DefinitionElement(attributes = {'a': 'b', 'b': 'c', 'value': 'x'})
     copy = DefinitionElement.from_string(str(definition))
     self.assertEqual(definition, copy)
示例#19
0
 def test_to_string_name(self):
     definition = DefinitionElement(name = 'test')
     copy = DefinitionElement.from_string(str(definition))
     self.assertEqual(definition, copy)
示例#20
0
 def test_from_lxml_attributes(self):
     text = '<DEFINE a="b" b="c" value="x" />'
     definition = DefinitionElement.from_lxml_element(etree.XML(text))
     right = DefinitionElement(attributes = {'a': 'b', 'b': 'c', 'value': 'x'})
     self.assertEqual(definition, right)
示例#21
0
 def test_from_lxml_full(self):
     text = '<DEFINE name="test" value="x" a="b" />'
     definition = DefinitionElement.from_lxml_element(etree.XML(text))
     right = DefinitionElement('test', {'value': 'x', 'a': 'b'})
     self.assertEqual(definition, right)
示例#22
0
 def test_to_lxml_name(self):
     definition = DefinitionElement(name = 'test')
     copy = DefinitionElement.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
示例#23
0
 def test_to_lxml_attributes(self):
     definition = DefinitionElement(attributes = {'a': 'b', 'b': 'c', 'value': 'x'})
     copy = DefinitionElement.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
示例#24
0
 def test_to_string_full(self):
     definition = DefinitionElement('test', {'value': 'x', 'a': 'b'})
     copy = DefinitionElement.from_string(str(definition))
     self.assertEqual(definition, copy)
示例#25
0
 def test_from_string(self):
     text = '<DEFINE />'
     definition = DefinitionElement.from_string(text)
     right = DefinitionElement()
     self.assertEqual(definition, right)