MCPcopy
hub / github.com/pytest-dev/pytest / test_patched_compile

Function test_patched_compile

testing/code/test_source.py:656–677  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

654
655
656def test_patched_compile() -> None:
657 # ensure Source doesn't break
658 # when compile() modifies code dynamically
659 from builtins import compile
660
661 def patched_compile1(_, *args, **kwargs):
662 return compile("", *args, **kwargs)
663
664 with patch("builtins.compile", new=patched_compile1):
665 Source(patched_compile1).getstatement(1)
666
667 # fmt: off
668 def patched_compile2(_, *args, **kwargs):
669
670 # first line of this function (the one above this one) must be empty
671 # LINES must be equal or higher than number of lines of this function
672 LINES = 99
673 return compile("\ndef a():\n" + "\n" * LINES + " pass", *args, **kwargs)
674 # fmt: on
675
676 with patch("builtins.compile", new=patched_compile2):
677 Source(patched_compile2).getstatement(1)

Callers

nothing calls this directly

Calls 2

SourceClass · 0.90
getstatementMethod · 0.80

Tested by

no test coverage detected