Example #1
0
def test_fmt_then_edit(use_pantsd: bool) -> None:
    f = "testprojects/src/python/hello/greet/greet.py"

    def run() -> None:
        run_pants(
            [
                "--backend-packages=['pants.backend.python', 'pants.backend.python.lint.black']",
                "fmt",
                f,
            ],
            use_pantsd=use_pantsd,
        ).assert_success()

    # Run once to start up, and then capture the file content.
    run()
    good_content = read_file(f)

    # Edit the file.
    with overwrite_file_content(
            f, lambda c: re.sub(b"def greet", b"def  greet", c)):
        assert good_content != read_file(f)

        # Re-run and confirm that the file was fixed.
        run()
        assert good_content == read_file(f)
Example #2
0
def test_fmt_then_edit():
    f = "examples/src/python/example/hello/greet/greet.py"
    with temporary_workdir() as workdir:

        def run() -> None:
            run_pants_with_workdir(
                [
                    "--backend-packages=['pants.backend.python', 'pants.backend.python.lint.black']",
                    "fmt",
                    f,
                ],
                workdir=workdir,
            ).assert_success()

        # Run once to start up, and then capture the file content.
        run()
        good_content = read_file(f)

        # Edit the file.
        with overwrite_file_content(
                f, lambda c: re.sub(b"def greet", b"def  greet", c)):
            assert good_content != read_file(f)

            # Re-run and confirm that the file was fixed.
            run()
            assert good_content == read_file(f)
def setup_sources_targets() -> Iterator[None]:
    build_path = Path(_SOURCES_TARGET_BASE, "BUILD")
    original_content = build_path.read_text()
    new_content = dedent(
        """\
        scala_library(
          name='missing-sources',
        )

        resources(
          name='missing-literal-files',
          sources=[
            'nonexistent_test_file.txt',
            'another_nonexistent_file.txt',
          ],
        )

        resources(
          name='missing-globs',
          sources=['*.a'],
        )

        resources(
          name='missing-rglobs',
          sources=['**/*.a'],
        )

        resources(
          name='some-missing-some-not',
          sources=['*.txt', '*.rs'],
        )

        resources(
          name='overlapping-globs',
          sources=['sources.txt', '*.txt'],
        )
        """
    )
    with overwrite_file_content(build_path, f"{original_content}\n{new_content}"):
        yield