fix: stream data update script output
1 files added
1 files modified
| | |
| | | result = subprocess.run( |
| | | [sys.executable, str(script_path)], |
| | | cwd=project_root, |
| | | capture_output=True, |
| | | capture_output=False, |
| | | text=True |
| | | ) |
| | | if result.stdout: |
| | | print(result.stdout) |
| | | if result.stderr: |
| | | print_error(result.stderr) |
| | | |
| | | |
| | | if return_result: |
| | | result_file = project_root / 'logs' / 'script_result.json' |
| | | if result_file.exists(): |
| New file |
| | |
| | | import importlib |
| | | import subprocess |
| | | import sys |
| | | import unittest |
| | | from pathlib import Path |
| | | from unittest.mock import patch |
| | | |
| | | |
| | | PROJECT_ROOT = Path(__file__).resolve().parents[1] |
| | | sys.path.insert(0, str(PROJECT_ROOT)) |
| | | |
| | | a_stock_manager = importlib.import_module("a_stock_manager") |
| | | |
| | | |
| | | class AStockManagerRunScriptTests(unittest.TestCase): |
| | | def test_run_script_streams_child_output(self): |
| | | completed = subprocess.CompletedProcess( |
| | | args=[sys.executable, "fake.py"], |
| | | returncode=0, |
| | | ) |
| | | |
| | | with patch.object(a_stock_manager.subprocess, "run", return_value=completed) as run: |
| | | result = a_stock_manager.run_script("fake.py", "fake task") |
| | | |
| | | self.assertTrue(result) |
| | | kwargs = run.call_args.kwargs |
| | | self.assertIs(kwargs["cwd"], a_stock_manager.project_root) |
| | | self.assertFalse(kwargs["capture_output"]) |
| | | self.assertNotIn("stdout", kwargs) |
| | | self.assertNotIn("stderr", kwargs) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | unittest.main() |