Exemplo n.º 1
0
def test_is_entry_point_false() -> None:
    assert not is_entry_point(
        textwrap.dedent(
            """
            # Note commented out.
            # if __name__ == "__main__":
            #    main()
            """
        ).encode()
    )

    assert not is_entry_point(
        textwrap.dedent(
            """
            # Note weird indent.
             if __name__ == "__main__":
                 main()
            """
        ).encode()
    )

    assert not is_entry_point(
        textwrap.dedent(
            """
            # Note some nonsense, as a soundness check.
            print(__name__)
            """
        ).encode()
    )
Exemplo n.º 2
0
def test_is_entry_point_true() -> None:
    assert is_entry_point(
        textwrap.dedent(
            """
            # Note single quotes.
            if __name__ == '__main__':
                main()
            """
        ).encode()
    )

    assert is_entry_point(
        textwrap.dedent(
            """
            # Note double quotes.
            if __name__ == "__main__":
                main()
            """
        ).encode()
    )

    assert is_entry_point(
        textwrap.dedent(
            """
            # Note weird extra spaces.
            if __name__  ==    "__main__":
                main()
            """
        ).encode()
    )

    assert is_entry_point(
        textwrap.dedent(
            """
            # Note trailing comment.
            if __name__ == "__main__": # Trailing comment.
                main()
            """
        ).encode()
    )

    assert is_entry_point(
        textwrap.dedent(
            """
            # Note trailing comment.
            if __name__ == "__main__":# Trailing comment.
                main()
            """
        ).encode()
    )

    assert is_entry_point(
        textwrap.dedent(
            """
            # Note trailing comment.
            if __name__ == "__main__":        # Trailing comment.
                main()
            """
        ).encode()
    )