From e18d8a84f52f8201bdfb78279729d139257906fe Mon Sep 17 00:00:00 2001 From: spark Date: Thu, 22 Oct 2026 05:34:57 +0000 Subject: [PATCH] spark: Python environment validation script with stdlib-only tests --- wizard-work/spark/python_validation.py | 90 +++++++++++++++++++++++ wizard-work/spark/validation_results.json | 62 ++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 wizard-work/spark/python_validation.py create mode 100644 wizard-work/spark/validation_results.json diff --git a/wizard-work/spark/python_validation.py b/wizard-work/spark/python_validation.py new file mode 100644 index 0000000..541f724 --- /dev/null +++ b/wizard-work/spark/python_validation.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +"""Self-contained Python environment validator using only stdlib.""" + +import sys +import json +import os +import hashlib +from datetime import datetime +from pathlib import Path + +def main(): + results = { + "timestamp": datetime.utcnow().isoformat() + "Z", + "python_version": sys.version, + "python_version_info": { + "major": sys.version_info.major, + "minor": sys.version_info.minor, + "micro": sys.version_info.micro, + "releaselevel": sys.version_info.releaselevel, + "serial": sys.version_info.serial + }, + "platform": sys.platform, + "tests": {} + } + + # Test 1: Basic arithmetic + results["tests"]["arithmetic"] = { + "passed": (2 + 2 == 4) and (10 * 5 == 50) and (100 / 4 == 25.0), + "values": {"two_plus_two": 2 + 2, "ten_times_five": 10 * 5, "hundred_div_four": 100 / 4} + } + + # Test 2: String operations + results["tests"]["string_ops"] = { + "passed": ("hello".upper() == "HELLO") and ("WORLD".lower() == "world"), + "values": {"hello_upper": "hello".upper(), "world_lower": "WORLD".lower()} + } + + # Test 3: List comprehension + results["tests"]["list_comprehension"] = { + "passed": [x * 2 for x in range(5)] == [0, 2, 4, 6, 8], + "values": {"squares": [x * 2 for x in range(5)]} + } + + # Test 4: File I/O + test_file = "/tmp/python_validation_test.txt" + test_content = "validation test content" + try: + with open(test_file, "w") as f: + f.write(test_content) + with open(test_file, "r") as f: + read_content = f.read() + results["tests"]["file_io"] = { + "passed": read_content == test_content, + "values": {"file_exists": os.path.exists(test_file), "content_match": read_content == test_content} + } + os.remove(test_file) + except Exception as e: + results["tests"]["file_io"] = {"passed": False, "error": str(e)} + + # Test 5: Hash computation + results["tests"]["hashlib"] = { + "passed": hashlib.sha256(b"test").hexdigest() == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", + "values": {"expected": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", + "computed": hashlib.sha256(b"test").hexdigest()} + } + + # Test 6: DateTime operations + results["tests"]["datetime"] = { + "passed": isinstance(datetime.utcnow(), datetime), + "values": {"current_utc": datetime.utcnow().isoformat()} + } + + # Overall pass/fail + results["all_tests_passed"] = all(t.get("passed", False) for t in results["tests"].values()) + + # Write results + output_dir = Path("/root/.hermes/wizard-outputs/spark") + output_dir.mkdir(parents=True, exist_ok=True) + output_file = output_dir / "validation_results.json" + with open(output_file, "w") as f: + json.dump(results, f, indent=2) + + print(f"Validation results written to {output_file}") + print(f"All tests passed: {results['all_tests_passed']}") + + # Return exit code + return 0 if results["all_tests_passed"] else 1 + +if __name__ == "__main__": + sys.exit(main()) \ No newline at end of file diff --git a/wizard-work/spark/validation_results.json b/wizard-work/spark/validation_results.json new file mode 100644 index 0000000..081e080 --- /dev/null +++ b/wizard-work/spark/validation_results.json @@ -0,0 +1,62 @@ +{ + "timestamp": "2026-10-22T05:34:13.722559Z", + "python_version": "3.14.7 (main, Sep 1 2026, 14:18:09) [Clang 22.1.3 ]", + "python_version_info": { + "major": 3, + "minor": 14, + "micro": 7, + "releaselevel": "final", + "serial": 0 + }, + "platform": "linux", + "tests": { + "arithmetic": { + "passed": true, + "values": { + "two_plus_two": 4, + "ten_times_five": 50, + "hundred_div_four": 25.0 + } + }, + "string_ops": { + "passed": true, + "values": { + "hello_upper": "HELLO", + "world_lower": "world" + } + }, + "list_comprehension": { + "passed": true, + "values": { + "squares": [ + 0, + 2, + 4, + 6, + 8 + ] + } + }, + "file_io": { + "passed": true, + "values": { + "file_exists": true, + "content_match": true + } + }, + "hashlib": { + "passed": true, + "values": { + "expected": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", + "computed": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" + } + }, + "datetime": { + "passed": true, + "values": { + "current_utc": "2026-10-22T05:34:13.723617" + } + } + }, + "all_tests_passed": true +} \ No newline at end of file