"""Regression for an execution-path error, unrelated to brain dynamics.""" from pathlib import Path from unittest import TestCase,main,mock,skipIf import os import sys import tempfile from oracle_apl import _python_entry class PythonEntryTests(TestCase): @skipIf(os.name=='nt','Real POSIX interpreter symlink is validated on the task server') def test_real_symlink_remains_invocation_path(self): with tempfile.TemporaryDirectory(prefix='phase4ag-entry-') as folder: path=Path(folder)/'python' path.symlink_to(sys.executable) self.assertEqual(_python_entry(path),path) self.assertNotEqual(_python_entry(path),path.resolve()) @skipIf(os.name=='nt','POSIX dangling symlink test is validated on the task server') def test_real_dangling_link_and_directory_rejected(self): with tempfile.TemporaryDirectory(prefix='phase4ag-entry-') as folder: path=Path(folder)/'python' path.symlink_to(Path(folder)/'absent') with self.assertRaises(ValueError):_python_entry(path) with self.assertRaises(ValueError):_python_entry(Path(folder)) def test_preserves_declared_venv_path_without_resolving_symlink(self): entry=Path.cwd()/'.fixture-venv/bin/python' with mock.patch.object(Path,'resolve',side_effect=AssertionError('Must not resolve interpreter symlink')): with mock.patch.object(Path,'is_file',return_value=True): self.assertEqual(_python_entry(entry),entry) def test_missing_python_entry_is_rejected(self): with mock.patch.object(Path,'is_file',return_value=False): with self.assertRaises(ValueError):_python_entry('/missing/python') if __name__=='__main__':main()