MCPcopy Index your code
hub / github.com/python/mypy / test_allowlist

Method test_allowlist

mypy/test/teststubtest.py:3043–3094  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3041 assert output == "Success: no issues found in 1 module\n"
3042
3043 def test_allowlist(self) -> None:
3044 # Can't use this as a context because Windows
3045 allowlist = tempfile.NamedTemporaryFile(mode="w+", delete=False)
3046 try:
3047 with allowlist:
3048 allowlist.write(f"{TEST_MODULE_NAME}.bad # comment\n# comment")
3049
3050 output = run_stubtest(
3051 stub="def bad(number: int, text: str) -> None: ...",
3052 runtime="def bad(asdf, text): pass",
3053 options=["--allowlist", allowlist.name],
3054 )
3055 assert output == "Success: no issues found in 1 module\n"
3056
3057 # test unused entry detection
3058 output = run_stubtest(stub="", runtime="", options=["--allowlist", allowlist.name])
3059 assert output == (
3060 f"note: unused allowlist entry {TEST_MODULE_NAME}.bad\n"
3061 "Found 1 error (checked 1 module)\n"
3062 )
3063
3064 output = run_stubtest(
3065 stub="",
3066 runtime="",
3067 options=["--allowlist", allowlist.name, "--ignore-unused-allowlist"],
3068 )
3069 assert output == "Success: no issues found in 1 module\n"
3070
3071 # test regex matching
3072 with open(allowlist.name, mode="w+") as f:
3073 f.write(f"{TEST_MODULE_NAME}.b.*\n")
3074 f.write("(unused_missing)?\n")
3075 f.write("unused.*\n")
3076
3077 output = run_stubtest(
3078 stub=textwrap.dedent("""
3079 def good() -> None: ...
3080 def bad(number: int) -> None: ...
3081 def also_bad(number: int) -> None: ...
3082 """.lstrip("\n")),
3083 runtime=textwrap.dedent("""
3084 def good(): pass
3085 def bad(asdf): pass
3086 def also_bad(asdf): pass
3087 """.lstrip("\n")),
3088 options=["--allowlist", allowlist.name, "--generate-allowlist"],
3089 )
3090 assert output == (
3091 f"note: unused allowlist entry unused.*\n{TEST_MODULE_NAME}.also_bad\n"
3092 )
3093 finally:
3094 os.unlink(allowlist.name)
3095
3096 def test_mypy_build(self) -> None:
3097 output = run_stubtest(stub="+", runtime="", options=[])

Callers

nothing calls this directly

Calls 4

run_stubtestFunction · 0.85
lstripMethod · 0.80
writeMethod · 0.45
dedentMethod · 0.45

Tested by

no test coverage detected