示例#1
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)
示例#2
0
 def test_concurrent_overrides_pantsd(self):
     """Tests that the --concurrent flag overrides the --pantsd flag, because we don't allow
     concurrent runs under pantsd."""
     config = {"GLOBAL": {"concurrent": True, "pantsd": True}}
     with temporary_workdir() as workdir:
         pants_run = self.run_pants_with_workdir(
             ["-ldebug", "help", "goals"], workdir=workdir, config=config)
         pants_run.assert_success()
         self.assertNotIn("Connecting to pantsd", pants_run.stderr)
示例#3
0
 def test_concurrent_overrides_pantsd(self):
     """Tests that the --concurrent flag overrides the --pantsd flag, because we don't allow
     concurrent runs under pantsd."""
     config = {"GLOBAL": {"concurrent": True, "pantsd": True}}
     with temporary_workdir() as workdir:
         pants_run = self.run_pants_with_workdir(
             ["help", "goals"], workdir=workdir, config=config
         )
         pants_run.assert_success()
         pantsd_log_location = os.path.join(workdir, "pantsd", "pantsd.log")
         self.assertFalse(os.path.exists(pantsd_log_location))
def test_ctrl_c() -> None:
    with temporary_workdir() as workdir:
        dest = os.path.join(workdir, "dest.log")

        # Start a pantsd run that will wait forever, then kill the pantsd client.
        client_handle, _, _ = launch_waiter(
            workdir=workdir, config=workunit_logger_config(dest))
        client_pid = client_handle.process.pid
        os.kill(client_pid, signal.SIGINT)

        # Confirm that finish is still called (even though it may be backgrounded in the server).
        confirm_eventual_success(dest)
def test_ctrl_c() -> None:
    with temporary_workdir() as workdir:
        dest = os.path.join(workdir, "dest.log")

        # Start a pantsd run that will wait forever, then kill the pantsd client.
        client_handle, _, _ = launch_waiter(workdir=workdir, config=workunit_logger_config(dest))
        client_pid = client_handle.process.pid
        os.kill(client_pid, signal.SIGINT)

        # Confirm that finish is still called (even though it may be backgrounded in the server).
        for _ in attempts("The log should eventually show that the SWH shut down."):
            content = maybe_read_file(dest)
            if content and FINISHED_SUCCESSFULLY in content:
                break
示例#6
0
def test_run_then_edit(use_pantsd: bool) -> None:
    slow = "slow.py"
    files = {
        slow:
        dedent("""\
        import time
        time.sleep(30)
        raise Exception("Should have been restarted by now!")
        """),
        "BUILD":
        dedent(f"""\
        python_sources(name='lib')
        pex_binary(name='bin', entry_point='{slow}', restartable=True)
        """),
    }
    for name, content in files.items():
        Path(name).write_text(content)

    with temporary_workdir() as workdir:

        client_handle = run_pants_with_workdir_without_waiting(
            [
                "--backend-packages=['pants.backend.python']",
                "run",
                slow,
            ],
            workdir=workdir,
            use_pantsd=use_pantsd,
        )

        # The process shouldn't exit on its own.
        time.sleep(5)
        assert client_handle.process.poll() is None

        # Edit the file to restart the run, and check that it re-ran
        Path(slow).write_text('print("No longer slow!")')
        result = client_handle.join()
        result.assert_success()
        assert result.stdout == "No longer slow!\n"
示例#7
0
def test_explorer_graphql_query(query: dict, expected_result: dict) -> None:
    with temporary_workdir() as workdir:
        handle = run_pants_with_workdir_without_waiting(
            [
                "--backend-packages=['pants.backend.explorer']",
                "--no-watch-filesystem",
                "--no-dynamic-ui",
                "experimental-explorer",
                "--address=127.0.0.1",
                "--port=7908",
            ],
            workdir=workdir,
            use_pantsd=False,
        )
        assert handle.process.stderr is not None
        os.set_blocking(handle.process.stderr.fileno(), False)
        count = 30

        while count > 0:
            data = handle.process.stderr.readline()
            if not data:
                count -= 1
                time.sleep(1)
            elif "Application startup complete." in data.decode():
                break

        if count > 0:
            rsp = requests.post("http://127.0.0.1:7908/graphql", json=query)
            rsp.raise_for_status()
            assert rsp.json() == expected_result
            print("GRAPHQL query passed!")
        else:
            # This is unexpected and wrong, but seems to be the case when run during CI.
            # TODO: figure out why, and fix, but allow for now to unblock.
            print("GRAPHQL query skipped, backend api did not startup properly.")

        handle.process.terminate()
        handle.join()