def test_handles_bound_methods(self):
     class Class:
         def method(self, x):
             return x + 1
     meth = Class().method
     rewrite_function(meth)
     assert_equal(meth(1), 2)
Exemplo n.º 2
0
    def test_handles_bound_methods(self):
        class Class:
            def method(self, x):
                return x + 1

        meth = Class().method
        rewrite_function(meth)
        assert_equal(meth(1), 2)
Exemplo n.º 3
0
    def test_handles_functions_with_free_variables(self):
        x = 1

        def fun():
            return x + 1

        rewrite_function(fun)
        assert_equal(fun(), 2)
Exemplo n.º 4
0
 def trace_function(self, fun):
     dis.dis(fun.func_code)
     rewrite_function(fun)
     self.btracer.setup()
     sys.settrace(self._trace)
     try:
         fun()
     finally:
         sys.settrace(None)
         self.btracer.teardown()
 def test_rewrites_each_function_only_once(self):
     def other():
         pass
     def fun():
         other()
         other()
     rewrite_function(other)
     rewritten_code = other.func_code
     self.trace_function(fun)
     assert other.func_code is rewritten_code
 def trace_function(self, fun):
     dis.dis(fun.func_code)
     rewrite_function(fun)
     self.btracer.setup()
     sys.settrace(self._trace)
     try:
         fun()
     finally:
         sys.settrace(None)
         self.btracer.teardown()
Exemplo n.º 7
0
    def test_rewrites_each_function_only_once(self):
        def other():
            pass

        def fun():
            other()
            other()

        rewrite_function(other)
        rewritten_code = other.func_code
        self.trace_function(fun)
        assert other.func_code is rewritten_code
Exemplo n.º 8
0
    def trace(self, code):
        """Trace execution of given code. Code may be either a function
        or a string with Python code.

        This method may be invoked many times for a single tracer instance.
        """
        self.setup(code)
        self.btracer.setup()
        rewrite_function(self.top_level_function)
        sys.settrace(self.tracer)
        try:
            self.top_level_function()
        finally:
            sys.settrace(None)
            self.teardown()
            self.btracer.teardown()
Exemplo n.º 9
0
    def trace(self, code):
        """Trace execution of given code. Code may be either a function
        or a string with Python code.

        This method may be invoked many times for a single tracer instance.
        """
        self.setup(code)
        self.btracer.setup()
        rewrite_function(self.top_level_function)
        sys.settrace(self.tracer)
        try:
            self.top_level_function()
        finally:
            sys.settrace(None)
            self.teardown()
            self.btracer.teardown()
Exemplo n.º 10
0
 def test_handles_functions_with_free_variables(self):
     x = 1
     def fun():
         return x + 1
     rewrite_function(fun)
     assert_equal(fun(), 2)
Exemplo n.º 11
0
def doimport():
    import foo
    foo.bleh()

def doyield():
    def y():
        yield 1
        yield 2
        yield 3
    for x in y():
        chr(x)

def doprint():
    print 1, 2, 3
    print>>sys.stderr, 4

######################################################################

if __name__ == '__main__':
    f = doprint
    btracer.setup()

    dis.dis(f)
    rewrite_function(f)

    sys.settrace(trace)
    try:
        f()
    finally:
        sys.settrace(None)
Exemplo n.º 12
0
def doyield():
    def y():
        yield 1
        yield 2
        yield 3

    for x in y():
        chr(x)


def doprint():
    print 1, 2, 3
    print >> sys.stderr, 4


######################################################################

if __name__ == '__main__':
    f = doprint
    btracer.setup()

    dis.dis(f)
    rewrite_function(f)

    sys.settrace(trace)
    try:
        f()
    finally:
        sys.settrace(None)