mirror of
https://github.com/openai/codex.git
synced 2026-11-09 20:50:33 +00:00
codex: address PR review feedback (#29497)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
FORMAT_SCRIPT_PATH = Path(__file__).resolve().parent.parent / "format.py"
|
||||
FORMAT_SCRIPT_SPEC = importlib.util.spec_from_file_location(
|
||||
"codex_format_script",
|
||||
FORMAT_SCRIPT_PATH,
|
||||
)
|
||||
if FORMAT_SCRIPT_SPEC is None or FORMAT_SCRIPT_SPEC.loader is None:
|
||||
raise RuntimeError(f"could not load {FORMAT_SCRIPT_PATH}")
|
||||
format_script = importlib.util.module_from_spec(FORMAT_SCRIPT_SPEC)
|
||||
sys.modules[FORMAT_SCRIPT_SPEC.name] = format_script
|
||||
FORMAT_SCRIPT_SPEC.loader.exec_module(format_script)
|
||||
|
||||
|
||||
class BuildifierFormatterGroupTest(unittest.TestCase):
|
||||
def test_includes_top_level_codex_rule_files(self) -> None:
|
||||
repository_files = b"\0".join(
|
||||
[
|
||||
b".codex/rules/z.rules",
|
||||
b".codex/rules/a.rules",
|
||||
b".codex/rules/nested/ignored.rules",
|
||||
b"elsewhere.rules",
|
||||
]
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
format_script.subprocess,
|
||||
"check_output",
|
||||
return_value=repository_files,
|
||||
):
|
||||
group = format_script.buildifier_formatter_group(check=True)
|
||||
|
||||
self.assertEqual(
|
||||
group.commands[0].args[4:],
|
||||
(".codex/rules/a.rules", ".codex/rules/z.rules"),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from contextlib import redirect_stdout
|
||||
import io
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
import setup_dev_execpolicy
|
||||
|
||||
|
||||
class SetupDevExecpolicyTest(unittest.TestCase):
|
||||
def test_discovers_absolute_paths_without_resolving_them(self) -> None:
|
||||
paths = {
|
||||
"cargo": "/tools/bin/cargo",
|
||||
"just": "/tools/bin/just",
|
||||
}
|
||||
|
||||
self.assertEqual(
|
||||
setup_dev_execpolicy.discover_host_executables(
|
||||
tuple(paths),
|
||||
which=paths.get,
|
||||
),
|
||||
{
|
||||
"cargo": Path("/tools/bin/cargo"),
|
||||
"just": Path("/tools/bin/just"),
|
||||
},
|
||||
)
|
||||
|
||||
def test_reports_all_missing_executables(self) -> None:
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError,
|
||||
"missing required host executables on PATH: just, pnpm",
|
||||
):
|
||||
setup_dev_execpolicy.discover_host_executables(
|
||||
("cargo", "just", "pnpm"),
|
||||
which=lambda name: "/tools/bin/cargo" if name == "cargo" else None,
|
||||
)
|
||||
|
||||
def test_renders_host_executable_rules(self) -> None:
|
||||
self.assertEqual(
|
||||
setup_dev_execpolicy.render_host_executable_rules(
|
||||
{
|
||||
"cargo": Path("/tools/bin/cargo"),
|
||||
"bazel": Path("/tools/bin/bazel"),
|
||||
}
|
||||
),
|
||||
"""# Generated by scripts/setup_dev_execpolicy.py. Do not edit.
|
||||
|
||||
host_executable(
|
||||
name = "cargo",
|
||||
paths = ["/tools/bin/cargo"],
|
||||
)
|
||||
|
||||
host_executable(
|
||||
name = "bazel",
|
||||
paths = ["/tools/bin/bazel"],
|
||||
)
|
||||
""",
|
||||
)
|
||||
|
||||
def test_main_prints_rules(self) -> None:
|
||||
executables = {"cargo": Path("/tools/bin/cargo")}
|
||||
stdout = io.StringIO()
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
setup_dev_execpolicy,
|
||||
"discover_host_executables",
|
||||
return_value=executables,
|
||||
),
|
||||
redirect_stdout(stdout),
|
||||
):
|
||||
result = setup_dev_execpolicy.main()
|
||||
|
||||
self.assertEqual(result, 0)
|
||||
self.assertEqual(
|
||||
stdout.getvalue(),
|
||||
setup_dev_execpolicy.render_host_executable_rules(executables),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user