示例#1
0
    def test_absolute_filepath_is_collected(self):
        with callspectpy.trace(self.collector):
            single_call()

        exp = os.path.abspath(__file__)
        self.assertEqual(self.collector.collected[0]['abs_filepath'], exp)
        self.assertEqual(self.collector.collected[1]['abs_filepath'], exp)
示例#2
0
    def test_line_number_is_collected(self):
        with callspectpy.trace(self.collector):
            single_call()

        # TODO: mv single_call to exclusive file
        # storing single_call in editable file (like this)
        # breaks this test on each edition
        self.assertEqual(self.collector.collected[0]['line_number'], 8)
        self.assertEqual(self.collector.collected[1]['line_number'], 8)
示例#3
0
    def test_single_call_works(self):
        with callspectpy.trace(self.collector):
            a()

        found = self.collector.collected
        expected = (
            {'event': 'call', 'fn': 'a', 'module': 'tests',},
            {'event': 'call', 'fn': 'a_b', 'module': 'tests',},
            {'event': 'return', 'fn': 'a_b', 'module': 'tests',},
            {'event': 'return', 'fn': 'a', 'module': 'tests',},
        )
        for idx, data_dict in enumerate(expected):
            self.assertEqual(found[idx]['event'], data_dict['event'])
            self.assertEqual(found[idx]['fn'], data_dict['fn'])
示例#4
0
    def test_data_is_collected_when_fn_creates_two_obj_of_same_class(self):
        with callspectpy.trace(self.collector):
            fn_creates_two_objs_of_same_class()

        found = self.collector.collected
        expected = (
            {'event': 'call', 'fn': 'fn_creates_two_objs_of_same_class',},
            {'event': 'call', 'fn': 'A',},
            {'event': 'return', 'fn': 'A',},
            {'event': 'call', 'fn': 'A',},
            {'event': 'return', 'fn': 'A',},
            {'event': 'return', 'fn': 'fn_creates_two_objs_of_same_class',},
        )
        for idx, data_dict in enumerate(expected):
            self.assertEqual(found[idx]['event'], data_dict['event'])
            self.assertEqual(found[idx]['fn'], data_dict['fn'])
示例#5
0
    def test_data_is_collected_when_fn_calls_method_of_obj(self):
        with callspectpy.trace(self.collector):
            fn_calls_method_of_obj_of_class_A()

        found = self.collector.collected
        expected = (
            {'event': 'call', 'fn': 'fn_calls_method_of_obj_of_class_A',},
            {'event': 'call', 'fn': 'A',},
            {'event': 'return', 'fn': 'A',},
            {'event': 'call', 'fn': 'print',},
            {'event': 'return', 'fn': 'print',},
            {'event': 'return', 'fn': 'fn_calls_method_of_obj_of_class_A',},
        )
        for idx, data_dict in enumerate(expected):
            self.assertEqual(found[idx]['event'], data_dict['event'])
            self.assertEqual(found[idx]['fn'], data_dict['fn'])
示例#6
0
    def test_data_is_collected_when_obj_method_calss_module_fn(self):
        with callspectpy.trace(self.collector):
            fn_calls_method_which_calls_module_fn()

        found = self.collector.collected
        expected = (
            {'event': 'call', 'fn': 'fn_calls_method_which_calls_module_fn',},
            {'event': 'call', 'fn': 'A',},
            {'event': 'return', 'fn': 'A',},
            {'event': 'call', 'fn': 'call_module_fn',},
            {'event': 'call', 'fn': 'single_call',},
            {'event': 'return', 'fn': 'single_call',},
            {'event': 'return', 'fn': 'call_module_fn',},
            {'event': 'return', 'fn': 'fn_calls_method_which_calls_module_fn',},
        )
        for idx, data_dict in enumerate(expected):
            self.assertEqual(found[idx]['event'], data_dict['event'])
            self.assertEqual(found[idx]['fn'], data_dict['fn'])
示例#7
0
    def test_a_start_chained_calls_works(self):
        with callspectpy.trace(self.collector):
            a_start_chained_call()

        found = self.collector.collected
        expected = (
            {'event': 'call', 'fn': 'a_start_chained_call',},
            {'event': 'call', 'fn': 'b',},
            {'event': 'call', 'fn': 'c',},
            {'event': 'call', 'fn': 'd',},
            {'event': 'call', 'fn': 'e',},
            {'event': 'return', 'fn': 'e',},
            {'event': 'return', 'fn': 'd',},
            {'event': 'return', 'fn': 'c',},
            {'event': 'return', 'fn': 'b',},
            {'event': 'return', 'fn': 'a_start_chained_call',},
        )
        for idx, data_dict in enumerate(expected):
            self.assertEqual(found[idx]['event'], data_dict['event'])
            self.assertEqual(found[idx]['fn'], data_dict['fn'])
示例#8
0
    def test_a_calls_a_few_other_fn_works(self):
        with callspectpy.trace(self.collector):
            a_calls_a_few_other_fn()

        found = self.collector.collected
        expected = (
            {'event': 'call', 'fn': 'a_calls_a_few_other_fn', 'module': 'tests'},
            {'event': 'call', 'fn': 'b', 'module': 'tests'},
            {'event': 'return', 'fn': 'b', 'module': 'tests'},
            {'event': 'call', 'fn': 'c', 'module': 'tests'},
            {'event': 'return', 'fn': 'c', 'module': 'tests'},
            {'event': 'call', 'fn': 'd', 'module': 'tests'},
            {'event': 'return', 'fn': 'd', 'module': 'tests'},
            {'event': 'call', 'fn': 'e', 'module': 'tests'},
            {'event': 'return', 'fn': 'e', 'module': 'tests'},
            {'event': 'return', 'fn': 'a_calls_a_few_other_fn', 'module': 'tests'},
        )
        for idx, data_dict in enumerate(expected):
            self.assertEqual(found[idx]['event'], data_dict['event'])
            self.assertEqual(found[idx]['fn'], data_dict['fn'])
示例#9
0
    def test_event_is_collected(self):
        with callspectpy.trace(self.collector):
            single_call()

        self.assertEqual(self.collector.collected[0]['event'], 'call')
        self.assertEqual(self.collector.collected[1]['event'], 'return')
示例#10
0
    def test_no_call_works(self):
        with callspectpy.trace(self.collector):
            pass

        self.assertEqual(self.collector.collected, [])
示例#11
0
    def test_callspect_calls_are_skipped(self):
        with callspectpy.trace(self.collector):
            pass

        self.assertEqual(self.collector.collected, [])
示例#12
0
    def test_module_is_collected(self):
        with callspectpy.trace(self.collector):
            single_call()

        self.assertEqual(self.collector.collected[0]['module'], 'tests')
        self.assertEqual(self.collector.collected[1]['module'], 'tests')