def test_enter_active_stack(self): class a_class(object): def __init__(self): pass an_object = a_class() xmllogging.enter_active_stack(an_object, "test") # The name of the create xml node should be active_stack self.assertTrue(an_object.active_stack.tagName == "active_stack") # The created node should have child active_stack with the actual active # node active_stack_node = xmllogging.get_child(an_object.active_stack, "active_stack") test_node = xmllogging.get_child(active_stack_node, "test") self.assertTrue(test_node.tagName == "test") xmllogging.exit_active_stack(an_object) # Test if after leaving the stack the test node is moved to root and # that that the active node is empty: xml_target_output = '<active_stack Name="a_class" type="active_stack"><active_stack info="Contains functions not left with a return"/><test/></active_stack>' #self.assertTrue(an_object.active_stack.toxml() == # pretty_xml_target_output) self.assertTrue(xml_target_output == an_object.active_stack.toxml(), an_object.active_stack.toxml())
def test_enter_active_stack_twice(self): class a_class(object): def __init__(self): pass an_object = a_class() xmllogging.enter_active_stack(an_object, "test") xmllogging.enter_active_stack(an_object, "test2") # The name of the create xml node should be active_stack self.assertTrue(an_object.active_stack.tagName == "active_stack") # The created node should have child active_stack with the actual active # node active_stack_node = xmllogging.get_child(an_object.active_stack, "active_stack") test_node = xmllogging.get_child(active_stack_node, "test") self.assertTrue(test_node.tagName == "test") # and a second node with the name test2 test_node2 = xmllogging.get_child(active_stack_node, "test2") self.assertTrue(test_node2.tagName == "test2") xmllogging.exit_active_stack(an_object) xmllogging.exit_active_stack(an_object) # after leaving the stack completely there should be a nested # node structure with the two test nodes xml_target_output = '<active_stack Name="a_class" type="active_stack"><active_stack info="Contains functions not left with a return"/><test><test2/></test></active_stack>' #self.assertTrue(an_object.active_stack.toxml() == # pretty_xml_target_output) self.assertTrue(xml_target_output == an_object.active_stack.toxml(), an_object.active_stack.toxml())
def test_xml_node_nested_timing_logging(self): """ Test nested logging. The duration is variable. Test existance of duration attribute and test that size of the created xml log is small. """ class Test(object): @xml_node def test(self): pass @xml_node def test2(self): self.test() an_object = Test() an_object.test2() #calling a decorated function should result in a active_stack node on the # class. After finishing it should have the duration in there target_xml = '<active_stack Name="Test" type="active_stack"><active_stack/><test duration="0.0"/></active_stack>' child2 = get_child(an_object.active_stack, "test2") child1 = get_child(child2, "test") self.assertTrue( float(child1.getAttribute("duration")) < 0.1, "The duration was to large for the size of the test function") self.assertTrue( float(child2.getAttribute("duration")) < 0.1, "The duration was to large for the size of the test function")
def test(self): if get_active_stack(tester) is not None: print( "An active stack should only exist when added explicitly" ) return False with duration(self, "a name") as context_object: active_stack = get_active_stack(self) # We should have an active stack in the context if active_stack is None: print( "In duration context the active stack should be added." ) return False if not get_child(active_stack, "active_stack").hasChildNodes(): print( "in the context the active_stack should at least contain one entry" ) return False # Now leave the context if get_child(active_stack, "active_stack").hasChildNodes(): print("After the context the active stack should be left") # There is stil an entry in the active stack return False return True
def test(self): if get_active_stack(tester) is not None: print "An active stack should only exist when added explicitly" return False with duration(self, "a name") as context_object: active_stack = get_active_stack(self) # We should have an active stack in the context if active_stack is None: print "In duration context the active stack should be added." return False if not get_child( active_stack, "active_stack").hasChildNodes(): print "in the context the active_stack should at least contain one entry" return False # Now leave the context if get_child( active_stack, "active_stack").hasChildNodes(): print "After the context the active stack should be left" # There is stil an entry in the active stack return False return True
def test_xml_node_nested_timing_logging(self): """ Test nested logging. The duration is variable. Test existance of duration attribute and test that size of the created xml log is small. """ class Test(object): @xml_node def test(self): pass @xml_node def test2(self): self.test() an_object = Test() an_object.test2() # calling a decorated function should result in a active_stack node on the # class. After finishing it should have the duration in there target_xml = ( '<active_stack Name="Test" type="active_stack"><active_stack/><test duration="0.0"/></active_stack>' ) child2 = get_child(an_object.active_stack, "test2") child1 = get_child(child2, "test") self.assertTrue( float(child1.getAttribute("duration")) < 0.1, "The duration was to large for the size of the test function" ) self.assertTrue( float(child2.getAttribute("duration")) < 0.1, "The duration was to large for the size of the test function" )
def test_enter_active_stack(self): class a_class(object): def __init__(self): pass an_object = a_class() xmllogging.enter_active_stack(an_object, "test") # The name of the create xml node should be active_stack self.assertTrue(an_object.active_stack.tagName == "active_stack") # The created node should have child active_stack with the actual active # node active_stack_node = xmllogging.get_child( an_object.active_stack, "active_stack") test_node = xmllogging.get_child( active_stack_node, "test") self.assertTrue(test_node.tagName == "test") xmllogging.exit_active_stack(an_object) # Test if after leaving the stack the test node is moved to root and # that that the active node is empty: xml_target_output = '<active_stack Name="a_class" type="active_stack"><active_stack info="Contains functions not left with a return"/><test/></active_stack>' #self.assertTrue(an_object.active_stack.toxml() == # pretty_xml_target_output) self.assertTrue(xml_target_output == an_object.active_stack.toxml(), an_object.active_stack.toxml())
def test_get_child_not_found(self): local_document = xml.Document() head = local_document.createElement("head") child = xmllogging.add_child(head, "child") # call the function returned_child = get_child(head, "does_not_exist") # test output self.assertTrue(returned_child == None, "when no children are found get_child should return None")
def test_get_child_not_found(self): local_document = xml.Document() head = local_document.createElement("head") child = xmllogging.add_child(head, "child") # call the function returned_child = get_child(head, "does_not_exist") # test output self.assertTrue( returned_child == None, "when no children are found get_child should return None")
def test_get_child(self): local_document = xml.Document() head = local_document.createElement("head") child = xmllogging.add_child(head, "child") second_child = xmllogging.add_child(head, "second_child") third_child = xmllogging.add_child(head, "child") # call the function returned_child = get_child(head, "child") # test output self.assertTrue(returned_child == child, "get_child dit not return the first child matching the name") self.assertTrue(returned_child != third_child, "get_child dit not return the first child matching the name")
def test_enter_active_stack_twice(self): class a_class(object): def __init__(self): pass an_object = a_class() xmllogging.enter_active_stack(an_object, "test") xmllogging.enter_active_stack(an_object, "test2") # The name of the create xml node should be active_stack self.assertTrue(an_object.active_stack.tagName == "active_stack") # The created node should have child active_stack with the actual active # node active_stack_node = xmllogging.get_child( an_object.active_stack, "active_stack") test_node = xmllogging.get_child( active_stack_node, "test") self.assertTrue(test_node.tagName == "test") # and a second node with the name test2 test_node2 = xmllogging.get_child( active_stack_node, "test2") self.assertTrue(test_node2.tagName == "test2") xmllogging.exit_active_stack(an_object) xmllogging.exit_active_stack(an_object) # after leaving the stack completely there should be a nested # node structure with the two test nodes xml_target_output = '<active_stack Name="a_class" type="active_stack"><active_stack info="Contains functions not left with a return"/><test><test2/></test></active_stack>' #self.assertTrue(an_object.active_stack.toxml() == # pretty_xml_target_output) self.assertTrue(xml_target_output == an_object.active_stack.toxml(), an_object.active_stack.toxml())
def test_get_child(self): local_document = xml.Document() head = local_document.createElement("head") child = xmllogging.add_child(head, "child") second_child = xmllogging.add_child(head, "second_child") third_child = xmllogging.add_child(head, "child") # call the function returned_child = get_child(head, "child") # test output self.assertTrue( returned_child == child, "get_child dit not return the first child matching the name") self.assertTrue( returned_child != third_child, "get_child dit not return the first child matching the name")
def test_xml_node_single_depth_timing_logging(self): """ Test single nested duration logging Output xml is compared as is. """ class Test(object): @xml_node def test(self): pass an_object = Test() an_object.test() #calling a decorated function should result in a active_stack node on the # class. After finishing it should have the duration in there target_xml = '<active_stack Name="Test" type="active_stack"><active_stack/><test duration="0.0"/></active_stack>' self.assertTrue(float(get_child( an_object.active_stack, "test").getAttribute("duration")) <= 0.1, "The created active stack did not add the duration information")
def strip_xml_to_master_details(pipeline_xml, logger): """ Helper function that returns a 'streamlined' subset of the data contained in the pipeline_xml. The current xml countains for instance resource level information not of interest of receivers of pipeline updates. This function removes most of the data in the xml limiting the size. """ local_document = _xml.Document() simplyfied_pipeline_xml = local_document.createElement("Simplyfied_pipeline_xml") simplyfied_pipeline_xml.appendChild(get_child(pipeline_xml, "active_stack").cloneNode(True)) for node in pipeline_xml.childNodes: # Active stack is copied in full if node.nodeName == "active_stack": continue # Create copy of the xml, make a shallow clone simplyfied_pipeline_xml.appendChild(node.cloneNode(False)) return simplyfied_pipeline_xml
def test_xml_node_single_depth_timing_logging(self): """ Test single nested duration logging Output xml is compared as is. """ class Test(object): @xml_node def test(self): pass an_object = Test() an_object.test() #calling a decorated function should result in a active_stack node on the # class. After finishing it should have the duration in there target_xml = '<active_stack Name="Test" type="active_stack"><active_stack/><test duration="0.0"/></active_stack>' self.assertTrue( float( get_child(an_object.active_stack, "test").getAttribute("duration")) <= 0.1, "The created active stack did not add the duration information")
def strip_xml_to_master_details(pipeline_xml, logger): """ Helper function that returns a 'streamlined' subset of the data contained in the pipeline_xml. The current xml countains for instance resource level information not of interest of receivers of pipeline updates. This function removes most of the data in the xml limiting the size. """ local_document = _xml.Document() simplyfied_pipeline_xml = local_document.createElement( "Simplyfied_pipeline_xml") simplyfied_pipeline_xml.appendChild( get_child(pipeline_xml, "active_stack").cloneNode(True)) for node in pipeline_xml.childNodes: # Active stack is copied in full if node.nodeName == "active_stack": continue # Create copy of the xml, make a shallow clone simplyfied_pipeline_xml.appendChild(node.cloneNode(False)) return simplyfied_pipeline_xml