Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 9pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def parse_suite(suite_path, parent_suite_path, options, settings, name=None):
test_spec_path = get_test_spec_path(case['case'], settings['test-spec'])
if os.path.exists(test_spec_path):
vcprint(pcolor.faint, f"Found test specification: {test_spec_path} for {case['case']}")
case['test-spec'] = test_spec_path
case['test-spec-sha'] = calculate_sha1sum(test_spec_path)
case['test_spec'] = test_spec_path
case['test_spec_sha'] = calculate_sha1sum(test_spec_path)
else:
vcprint(pcolor.faint, f"No test specification for {case['case']} ({test_spec_path})")

Expand Down
3 changes: 3 additions & 0 deletions self_test/cases/worker.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= Worker Test Specification

This is a test specification for the worker test case.
50 changes: 50 additions & 0 deletions self_test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,55 @@ def test_repeat_flag(self):
}
)

def test_spec_json_format(self):
"""Verify test_spec and test_spec_sha keys in JSON output"""

self.env = os.environ.copy()
self.env["NINEPM_TEST_DIR"] = self.create_unique_subdir()

result = subprocess.run(
["python3", self.ninepm, "suites/test-spec.yaml"],
cwd=self.script_dir,
text=True,
env=self.env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

if VERBOSE:
print(result.stdout)
print(result.stderr, file=sys.stderr)

assert result.returncode == 0, f"Failed with return code {result.returncode}"

json_path = os.path.join(os.path.expanduser('~/.local/share/9pm/logs/last'), 'result.json')
assert os.path.exists(json_path), f"Could not find {json_path}"

with open(json_path, 'r') as f:
data = json.load(f)

def find_test_spec(obj):
if isinstance(obj, dict):
if 'test_spec' in obj:
return obj
for value in obj.values():
result = find_test_spec(value)
if result:
return result
elif isinstance(obj, list):
for item in obj:
result = find_test_spec(item)
if result:
return result
return None

case = find_test_spec(data['suite'])
assert case is not None, "Could not find test_spec in JSON"
assert 'test_spec' in case, "Missing test_spec key"
assert 'test_spec_sha' in case, "Missing test_spec_sha key"

print_green(f"[PASS] Test spec JSON output")

def cleanup(self):
"""Cleanup temp directory after tests"""
self.temp_dir_base.cleanup()
Expand Down Expand Up @@ -357,6 +406,7 @@ def cleanup(self):
tester.test_abort_flag()
tester.test_repeat_flag()
tester.test_proj_config()
tester.test_spec_json_format()
print_green("All tests passed.")
finally:
tester.cleanup()
5 changes: 5 additions & 0 deletions self_test/suites/test-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- settings:
test-spec: <case>.adoc

- case: "../cases/worker.py"
20 changes: 20 additions & 0 deletions self_test/test_json_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
"""Verify test_spec and test_spec_sha keys in JSON output"""

import sys
import os

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from run import Test9pm

if __name__ == "__main__":
tester = Test9pm()
try:
tester.test_spec_json_format()
sys.exit(0)
except AssertionError as e:
print(f"\n✗ Test failed: {e}")
sys.exit(1)
finally:
tester.cleanup()