예제 #1
0
    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())
예제 #2
0
    def wrapper(*args, **argsw):
        """
        Decorator construct, receives arguments to the decorated function
        """
        # Get the calling object (first argument supplied to this decorator)
        calling_object = args[0]

        # Add a node with the name of the current function to the active stack
        # if stack does not exist the stack will be created
        xml_current_node = enter_active_stack(
                    calling_object, target.__name__)

        # log time
        time_info1 = time.time()

        # call the actual function
        return_value = target(*args, **argsw)

        # end time
        time_info2 = time.time()
        # add the duration
        xml_current_node.setAttribute("duration", str(time_info2 - time_info1))

        # leave the stack
        exit_active_stack(calling_object)

        # return the actual value of the function
        return return_value
예제 #3
0
    def wrapper(*args, **argsw):
        """
        Decorator construct, receives arguments to the decorated function
        """
        # Get the calling object (first argument supplied to this decorator)
        calling_object = args[0]

        # Add a node with the name of the current function to the active stack
        # if stack does not exist the stack will be created
        xml_current_node = enter_active_stack(calling_object, target.__name__)

        # log time
        time_info1 = time.time()

        # call the actual function
        return_value = target(*args, **argsw)

        # end time
        time_info2 = time.time()
        # add the duration
        xml_current_node.setAttribute("duration", str(time_info2 - time_info1))

        # leave the stack
        exit_active_stack(calling_object)

        # return the actual value of the function
        return return_value
예제 #4
0
    def test_add_child_to_active_stack_head(self):
        class a_class(object):
            def __init__(self):
                pass

        local_document = xml.Document()
        created_node = local_document.createElement("Tester")

        an_object = a_class()
        return_value = xmllogging.add_child_to_active_stack_head(
            an_object, created_node)

        self.assertTrue(
            return_value == None,
            "function should return None when adding child when no active stack is there "
        )

        xmllogging.enter_active_stack(an_object, "test")
        # Add the chilf
        return_value = xmllogging.add_child_to_active_stack_head(
            an_object, created_node)
        # get the stack
        stack = xmllogging.get_active_stack(an_object)
        stack_text = stack.toxml()
        goal_text = """<active_stack Name="a_class" type="active_stack"><active_stack info="Contains functions not left with a return"><test><Tester/></test></active_stack></active_stack>"""
        # The node text should have a Tester node added
        xmllogging.exit_active_stack(an_object)

        self.assertEqual(stack_text, goal_text,
                         "THe created xml structure is not correct")
예제 #5
0
    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())
예제 #6
0
    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())
예제 #7
0
    def test_add_child_to_active_stack_head(self):
        class a_class(object):
            def __init__(self):
                pass

        local_document = xml.Document()
        created_node = local_document.createElement("Tester")

        an_object = a_class()
        return_value = xmllogging.add_child_to_active_stack_head(an_object,
                        created_node)

        self.assertTrue(return_value == None,
            "function should return None when adding child when no active stack is there ")


        xmllogging.enter_active_stack(an_object, "test")
        # Add the chilf
        return_value = xmllogging.add_child_to_active_stack_head(an_object,
                                                           created_node)
        # get the stack
        stack = xmllogging.get_active_stack(an_object)
        stack_text = stack.toxml()
        goal_text = """<active_stack Name="a_class" type="active_stack"><active_stack info="Contains functions not left with a return"><test><Tester/></test></active_stack></active_stack>"""
        # The node text should have a Tester node added
        xmllogging.exit_active_stack(an_object)

        self.assertEqual(stack_text, goal_text,
            "THe created xml structure is not correct")
예제 #8
0
    def __exit__(self, exc_type, exc_value, exc_tb):
        """
        upon leaving the context log the duration and leave the current
        Xml node
        """
        time_info_end = time.time()
        self._xml_current_node.setAttribute(
                    "duration", str(time_info_end - self._time_info_start))
        if exc_type == None:

            exit_active_stack(self._containing_object)
        else:
            # Exception thrown in the context: Return False here reraises it
            # automatically.
            False
예제 #9
0
    def __exit__(self, exc_type, exc_value, exc_tb):
        """
        upon leaving the context log the duration and leave the current
        Xml node
        """
        time_info_end = time.time()
        self._xml_current_node.setAttribute(
            "duration", str(time_info_end - self._time_info_start))
        if exc_type == None:

            exit_active_stack(self._containing_object)
        else:
            # Exception thrown in the context: Return False here reraises it
            # automatically.
            False
예제 #10
0
    def test_get_active_stack(self):
        class a_class(object):
            def __init__(self):
                pass


        an_object = a_class()
        result = xmllogging.get_active_stack(an_object)

        # If no active stack is created return None
        self.assertTrue(result == None, "When no active stack is entered"
                        " get_active_stack should return None")

        xmllogging.enter_active_stack(an_object, "test", stack_name="test_stack")

        result = xmllogging.get_active_stack(an_object)
        # Calling get stack with incorrect name (default in this case) return None
        self.assertTrue(result == None, "When incorrect active stack name is entered"
                        " get_active_stack should return None")


        xmllogging.exit_active_stack(an_object, stack_name="test_stack")
예제 #11
0
    def test_get_active_stack(self):
        class a_class(object):
            def __init__(self):
                pass

        an_object = a_class()
        result = xmllogging.get_active_stack(an_object)

        # If no active stack is created return None
        self.assertTrue(
            result == None, "When no active stack is entered"
            " get_active_stack should return None")

        xmllogging.enter_active_stack(an_object,
                                      "test",
                                      stack_name="test_stack")

        result = xmllogging.get_active_stack(an_object)
        # Calling get stack with incorrect name (default in this case) return None
        self.assertTrue(
            result == None, "When incorrect active stack name is entered"
            " get_active_stack should return None")

        xmllogging.exit_active_stack(an_object, stack_name="test_stack")
예제 #12
0
    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())