Beispiel #1
0
    def test_optional_eye(self):
        @eye(optional=True)
        def f(x):
            return x * 3

        call_stuff = get_call_stuff(get_call_ids(lambda: f(2, trace_call=True))[0])
        self.assertEqual(call_stuff.call.result, '6')

        call = eye.enter_call
        eye.enter_call = lambda *args, **kwargs: 1 / 0
        try:
            self.assertEqual(f(3, trace_call=False), 9)
            self.assertEqual(f(4), 12)
        finally:
            eye.enter_call = call
Beispiel #2
0
    def test_nested_arguments(self):
        # Python 3 sees nested arguments as a syntax error, so I can't
        # define the function here normally
        # birdseye requires a source file so I can't just use exec
        # The file can't just live there because then the test runner imports it
        path = os.path.join(os.path.dirname(__file__), 'nested_arguments.py')
        string_to_file("""
def f((x, y), z):
    return x, y, z
""", path)

        try:
            from tests.nested_arguments import f
            f = eye(f)
            call = get_call_stuff(get_call_ids(lambda: f((1, 2), 3))[0]).call
            self.assertEqual(call.arguments,
                             '[["x", "1"], ["y", "2"], ["z", "3"]]')
            self.assertEqual(call.result, "(1, 2, 3)")
        finally:
            os.remove(path)
Beispiel #3
0
    def test_unicode(self):
        @eye
        def f():
            return u'é'

        self.assertEqual(f(), u'é')