Host PictureProperties in the same scrolling layout used by the inspector, scope scrub labels and transform field assertions to the controls under test, and compare resolved temporary paths in tool tests on macOS. Validation: full application analysis, 1261 Flutter tests passed (9 skipped), generated-code verification, and 171 tool tests.
59 lines
2.7 KiB
Python
59 lines
2.7 KiB
Python
"""Shared process/CLI contracts used by application and platform entrypoints."""
|
|
import contextlib
|
|
import hashlib
|
|
import io
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from common.files import file_sha256
|
|
from common.process import cli, run
|
|
|
|
|
|
class CommonToolsTests(unittest.TestCase):
|
|
def test_process_arguments_directory_and_child_environment_are_preserved(self):
|
|
with tempfile.TemporaryDirectory(prefix='cutdex common process ') as directory:
|
|
code = "import os,sys; print(os.getcwd()); print(os.environ['CUTDEX_TEST']); print(repr(sys.argv[1:]))"
|
|
arguments = ['A&B with spaces', 'with "quotes"', '', '%literal%']
|
|
result = run([sys.executable, '-c', code, *arguments], cwd=directory,
|
|
env={'CUTDEX_TEST': 'child'}, capture_output=True, text=True)
|
|
lines = result.stdout.splitlines()
|
|
self.assertEqual(Path(lines[0]).resolve(), Path(directory).resolve())
|
|
self.assertEqual(lines[1], 'child')
|
|
self.assertEqual(lines[2], repr(arguments))
|
|
|
|
def test_cli_preserves_child_failure_without_exposing_arguments(self):
|
|
def fail():
|
|
run([sys.executable, '-c', 'import sys; sys.exit(17)', 'secret-token'], capture_output=True)
|
|
with contextlib.redirect_stderr(io.StringIO()) as diagnostics:
|
|
self.assertEqual(cli(fail), 17)
|
|
self.assertIn('exit 17', diagnostics.getvalue())
|
|
self.assertNotIn('secret-token', diagnostics.getvalue())
|
|
|
|
def test_child_stdout_and_stderr_remain_separate(self):
|
|
result = run([sys.executable, '-c', "import sys; print('result'); print('diagnostic', file=sys.stderr)"],
|
|
capture_output=True, text=True)
|
|
self.assertEqual(result.stdout.strip(), 'result')
|
|
self.assertEqual(result.stderr.strip(), 'diagnostic')
|
|
|
|
def test_cli_reports_validation_failure_without_a_traceback(self):
|
|
def fail():
|
|
raise ValueError('Release files differ from the audited manifest')
|
|
with contextlib.redirect_stderr(io.StringIO()) as diagnostics:
|
|
self.assertEqual(cli(fail), 1)
|
|
self.assertEqual(diagnostics.getvalue(), 'Release files differ from the audited manifest\n')
|
|
|
|
def test_streamed_file_hash_matches_binary_contents(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / 'artifact'
|
|
payload = bytes(range(256)) * 32768
|
|
path.write_bytes(payload)
|
|
self.assertEqual(file_sha256(path), hashlib.sha256(payload).hexdigest())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|