Esempio n. 1
0
 def test_creation(self):
     definition = DefinitionTree()
     self.assertTrue(isinstance(definition, Definition))
     definition = DefinitionTree('name')
     self.assertTrue(isinstance(definition, Definition))
     definition = DefinitionTree('name', [self.element_0])
     self.assertTrue(isinstance(definition, Definition))
     definition = DefinitionTree('name', [self.element_1], {'key': 'value'})
     self.assertTrue(isinstance(definition, Definition))
Esempio n. 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)
Esempio n. 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'})
         ]))
Esempio n. 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'))
Esempio n. 5
0
 def test_equality(self):
     definition_0 = DefinitionTree('test', [self.element_0], {'a': 'b'})
     definition_1 = DefinitionTree('test', [self.element_0], {'a': 'b'})
     self.assertEqual(definition_0, definition_1)
     self.assertNotEqual(definition_0, DefinitionTree('', [self.element_0], {'a': 'b'}))
     self.assertNotEqual(definition_0, DefinitionTree('name', [], {'a': 'b'}))
     self.assertNotEqual(definition_0, DefinitionTree('name', [self.element_0], {'b': 'b'}))
     self.assertNotEqual(DefinitionTree(), 'different type')
Esempio n. 6
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'))
Esempio n. 7
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)
Esempio n. 8
0
 def test_to_string_name(self):
     definition = DefinitionTree(name = "test")
     copy = DefinitionTree.from_string(str(definition))
     self.assertEqual(definition, copy)
Esempio n. 9
0
 def test_to_lxml_full(self):
     definition = DefinitionTree('test', [self.element_0, self.element_1], {'a': 'b'})
     copy = DefinitionTree.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
Esempio n. 10
0
 def test_top_lxml_attributes(self):
     definition = DefinitionTree(attributes = {'a': 'b', 'b': 'c'})
     copy = DefinitionTree.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
Esempio n. 11
0
 def test_top_lxml_definitions(self):
     definition = DefinitionTree(definitions = [self.element_0, self.element_1])
     copy = DefinitionTree.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
Esempio n. 12
0
 def test_to_lxml_name(self):
     definition = DefinitionTree(name = "test")
     copy = DefinitionTree.from_lxml_element(definition.to_lxml_element())
     self.assertEqual(definition, copy)
Esempio n. 13
0
 def test_to_string_full(self):
     definition = DefinitionTree('test', [self.element_0, self.element_1], {'a': 'b'})
     copy = DefinitionTree.from_string(str(definition))
     self.assertEqual(definition, copy)
Esempio n. 14
0
 def test_top_string_attributes(self):
     definition = DefinitionTree(attributes = {'a': 'b', 'b': 'c'})
     copy = DefinitionTree.from_string(str(definition))
     self.assertEqual(definition, copy)
Esempio n. 15
0
 def test_from_string(self):
     text = '<DEFINE />'
     definition = DefinitionTree.from_string(text)
     right = DefinitionTree()
     self.assertEqual(definition, right)
Esempio n. 16
0
 def test_from_lxml_full(self):
     text = '<DEFINE name="test" a="b">{0}{1}</DEFINE>'.format(
         self.element_0, self.element_1)
     definition = DefinitionTree.from_lxml_element(etree.XML(text))
     right = DefinitionTree('test', [self.element_0, self.element_1], {'a': 'b'})
     self.assertEqual(definition, right)
Esempio n. 17
0
 def test_from_lxml_attributes(self):
     text = '<DEFINE a="b" b="c" />'
     definition = DefinitionTree.from_lxml_element(etree.XML(text))
     right = DefinitionTree(attributes = {'a': 'b', 'b': 'c'})
     self.assertEqual(definition, right)
Esempio n. 18
0
 def test_from_lxml_definitions(self):
     text = '<DEFINE>{0}{1}</DEFINE>'.format(self.element_0, self.element_1)
     definition = DefinitionTree.from_lxml_element(etree.XML(text))
     right = DefinitionTree(definitions = [self.element_0, self.element_1])
     self.assertEqual(definition, right)
Esempio n. 19
0
 def test_from_lxml_name(self):
     text = '<DEFINE name="test" />'
     definition = DefinitionTree.from_lxml_element(etree.XML(text))
     right = DefinitionTree(name = "test")
     self.assertEqual(definition, right)
Esempio n. 20
0
 def test_from_string_attributes(self):
     text = '<DEFINE a="b" b="c" />'
     definition = DefinitionTree.from_string(text)
     right = DefinitionTree(attributes = {'a': 'b', 'b': 'c'})
     self.assertEqual(definition, right)
Esempio n. 21
0
 def test_from_string_name(self):
     text = '<DEFINE name="test" />'
     definition = DefinitionTree.from_string(text)
     right = DefinitionTree(name = "test")
     self.assertEqual(definition, right)
Esempio n. 22
0
 def test_top_string_definitions(self):
     definition = DefinitionTree(definitions = [self.element_0, self.element_1])
     copy = DefinitionTree.from_string(str(definition))
     self.assertEqual(definition, copy)
Esempio n. 23
0
 def test_definitions(self):
     definition = DefinitionTree()
     self.assertEqual(0, len(definition.get_definitions()))
     definition.add_definition(self.element_0)
     self.assertEqual(1, len(definition.get_definitions()))
     self.assertEqual(self.element_0, definition.get_definition(0))
     definition.add_definition(self.element_1)
     self.assertEqual(2, len(definition.get_definitions()))
     self.assertEqual(self.element_0, definition.get_definition(0))
     self.assertEqual(self.element_1, definition.get_definition(1))
     definition.remove_definition(0)
     self.assertEqual(1, len(definition.get_definitions()))
     self.assertEqual(self.element_1, definition.get_definition(0))
     definition.add_definition(self.element_0, 0)
     self.assertEqual(2, len(definition.get_definitions()))
     self.assertEqual(self.element_0, definition.get_definition(0))
     self.assertEqual(self.element_1, definition.get_definition(1))
     self.assertRaises(IndexError, definition.get_definition, 2)
     definition = DefinitionTree(definitions = [self.element_0, self.element_1])
     self.assertEqual(2, len(definition.get_definitions()))
     self.assertEqual(self.element_0, definition.get_definition(0))
     self.assertEqual(self.element_1, definition.get_definition(1))