mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-12 18:35:16 -10:00
Allow parity runner defaults in dolphin and spell harnesses
This commit is contained in:
1 parent
41f822b659
commit
a98ba02730
4 files changed
+53
-10
No files matched your search
@@ -0,0 +1,39 @@
|
||||
"""Command harnesses accept the arguments parity.py actually supplies."""
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
class ReachedDriver(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class CommandHarnessInvocationTest(unittest.TestCase):
|
||||
def test_default_and_explicit_scratch_paths_reach_the_shared_driver(self):
|
||||
for name, default in [('test_noai_dolphin_air_parity', 'noai-dolphin-air-parity'),
|
||||
('test_spell_ticks_parity', 'spell-ticks-parity')]:
|
||||
harness = importlib.import_module('tools.' + name)
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
local = Path(temporary)
|
||||
requested = local / 'requested'
|
||||
for arguments, expected in [([], local / default),
|
||||
(['--reference-only'], local / default),
|
||||
(['--work-dir', str(requested)], requested),
|
||||
([f'--work-dir={requested}', '--binary=game'], requested)]:
|
||||
with self.subTest(harness=name, arguments=arguments):
|
||||
argv = [name + '.py', *arguments]
|
||||
with patch.object(sys, 'argv', argv), \
|
||||
patch.object(harness.driver.lab, 'LOCAL', local), \
|
||||
patch.object(harness.driver.corpus_module, 'groups'), \
|
||||
patch.object(harness.driver, 'main', side_effect=ReachedDriver) as run:
|
||||
with self.assertRaises(ReachedDriver):
|
||||
harness.main()
|
||||
run.assert_called_once_with()
|
||||
self.assertEqual(harness.harness_args.ensure_work_dir(local / 'unused'), expected)
|
||||
self.assertIn('--allow-gaps', argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -33,13 +33,13 @@ class EnsureWorkDirTest(unittest.TestCase):
|
||||
self.assertEqual(harness_args.ensure_work_dir(DEFAULT, argv), DEFAULT)
|
||||
self.assertEqual(
|
||||
argv,
|
||||
['harness.py', '--reference', '/tmp/vanilla.jsonl', '--work-dir', '/scratch/default'],
|
||||
['harness.py', '--reference', '/tmp/vanilla.jsonl', '--work-dir', str(DEFAULT)],
|
||||
)
|
||||
|
||||
def test_script_path_is_not_an_argument(self):
|
||||
argv = ['--work-dir/not-an-argument.py']
|
||||
harness_args.ensure_work_dir(DEFAULT, argv)
|
||||
self.assertEqual(argv, ['--work-dir/not-an-argument.py', '--work-dir', '/scratch/default'])
|
||||
self.assertEqual(argv, ['--work-dir/not-an-argument.py', '--work-dir', str(DEFAULT)])
|
||||
|
||||
def test_the_last_one_wins_as_in_argparse(self):
|
||||
argv = ['harness.py', '--work-dir', '/tmp/first', '--work-dir=/tmp/second']
|
||||
|
||||
@@ -8,7 +8,11 @@ import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import test_command_exec_parity as driver
|
||||
try:
|
||||
from . import harness_args, test_command_exec_parity as driver
|
||||
except ImportError:
|
||||
import harness_args
|
||||
import test_command_exec_parity as driver
|
||||
|
||||
|
||||
def subjects():
|
||||
@@ -95,9 +99,7 @@ def main():
|
||||
i = sys.argv.index('--reference')
|
||||
reference = Path(sys.argv[i + 1]).resolve().read_bytes()
|
||||
del sys.argv[i:i + 2]
|
||||
if '--binary' not in sys.argv:
|
||||
raise SystemExit('--binary is required (also for a reference-only run)')
|
||||
build = Path(sys.argv[sys.argv.index('--work-dir') + 1]).resolve()
|
||||
build = harness_args.ensure_work_dir(driver.lab.LOCAL / 'noai-dolphin-air-parity').resolve()
|
||||
ops = program(full)
|
||||
driver.corpus_module.groups = lambda: [('NoAI dolphin air', ops)]
|
||||
sys.argv.append('--allow-gaps')
|
||||
|
||||
@@ -8,7 +8,11 @@ import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import test_command_exec_parity as driver
|
||||
try:
|
||||
from . import harness_args, test_command_exec_parity as driver
|
||||
except ImportError:
|
||||
import harness_args
|
||||
import test_command_exec_parity as driver
|
||||
|
||||
|
||||
def subjects():
|
||||
@@ -88,9 +92,7 @@ def main():
|
||||
i = sys.argv.index('--reference')
|
||||
reference = Path(sys.argv[i + 1]).resolve().read_bytes()
|
||||
del sys.argv[i:i + 2]
|
||||
if '--binary' not in sys.argv:
|
||||
raise SystemExit('--binary is required (also for a reference-only run)')
|
||||
build = Path(sys.argv[sys.argv.index('--work-dir') + 1]).resolve()
|
||||
build = harness_args.ensure_work_dir(driver.lab.LOCAL / 'spell-ticks-parity').resolve()
|
||||
ops = program(full)
|
||||
driver.corpus_module.groups = lambda: [('spell ticks', ops)]
|
||||
sys.argv.append('--allow-gaps')
|
||||
|
||||
Reference in new issue
Block a user