How to use the executing.Source.executing function in executing

To help you get started, we’ve selected a few executing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexmojaki / executing / tests / samples / tests.py View on Github external
def get_node(self, typ):
        frame = inspect.currentframe().f_back.f_back
        Source.lazycache(frame)
        node = Source.executing(frame).node
        assert isinstance(node, typ), (node, typ)
        return node
github alexmojaki / executing / tests / test_main.py View on Github external
def test_executing_methods(self):
        frame = inspect.currentframe()
        executing = Source.executing(frame)
        self.assertEqual(executing.code_qualname(), 'TestStuff.test_executing_methods')
        text = 'Source.executing(frame)'
        self.assertEqual(executing.text(), text)
        start, end = executing.text_range()
        self.assertEqual(executing.source.text[start:end], text)
github alexmojaki / executing / tests / samples / tests.py View on Github external
def test_many_calls(self):
        node = None
        start = time.time()
        for i in range(10000):
            new_node = Source.executing(inspect.currentframe()).node
            if node is None:
                node = new_node
            else:
                self.assertIs(node, new_node)
        self.assertLess(time.time() - start, 1)
github alexmojaki / heartrate / heartrate / core.py View on Github external
def highlight_ranges(source, frames):
    text = source.text
    ranges = set()
    for frame in frames:
        executing = Source.executing(frame)
        if executing.node:
            text_range = executing.text_range()
            ranges.add(text_range)
    
    positions = []

    for start, end in ranges:
        positions.append((start, open_sentinel))
        positions.append((end, close_sentinel))
        while True:
            start = text.find('\n', start + 1, end)
            if start == -1:
                break
            positions.append((start, close_sentinel))
            positions.append((start + 1, open_sentinel))