nix-eval-jobs/tests/test_eval.py
adisbladis 434376f8e1
Remove outputs from JSON output
The output of the evaluator should only include either the full
derivation (not yet implemented) or fields not directly accessible
from the drv such as meta.

Right now the output is a fairly arbitrary selection of fields.
2021-08-26 18:48:56 -05:00

44 lines
1.1 KiB
Python

#!/usr/bin/env python3
import subprocess
import json
from tempfile import TemporaryDirectory
from pathlib import Path
from typing import List
TEST_ROOT = Path(__file__).parent.resolve()
PROJECT_ROOT = TEST_ROOT.parent
BIN = PROJECT_ROOT.joinpath("build", "src", "nix-eval-jobs")
def common_test(extra_args: List[str]) -> None:
with TemporaryDirectory() as tempdir:
cmd = [str(BIN), "--gc-roots-dir", tempdir] + extra_args
res = subprocess.run(
cmd,
cwd=TEST_ROOT.joinpath("assets"),
text=True,
check=True,
stdout=subprocess.PIPE,
)
results = [json.loads(r) for r in res.stdout.split("\n") if r]
assert len(results) == 2
built_job = results[0]
assert built_job["attr"] == "builtJob"
assert built_job["name"] == "job1"
substituted_job = results[1]
assert substituted_job["attr"] == "substitutedJob"
assert substituted_job["name"].startswith("hello-")
def test_flake() -> None:
common_test(["--flake", ".#"])
def test_expression() -> None:
common_test(["ci.nix"])