40 lines
2.1 KiB
Python
40 lines
2.1 KiB
Python
import fcntl
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
spec=importlib.util.spec_from_file_location('acceptance_run',Path(__file__).with_name('run.py'))
|
|
module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
|
|
|
|
class LauncherTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.temp=tempfile.TemporaryDirectory();self.home=Path(self.temp.name)
|
|
self.patch=patch.object(Path,'home',return_value=self.home);self.patch.start()
|
|
self.root=self.home/'.local/state/cyj/browser/application';self.root.mkdir(parents=True,mode=0o700)
|
|
def tearDown(self):self.patch.stop();self.temp.cleanup()
|
|
def test_concurrent_session_is_rejected_without_launch(self):
|
|
with (self.root/'session.lock').open('w') as lock:
|
|
(self.root/'session.lock').chmod(0o600);fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
|
with patch.object(module.subprocess,'run') as launch:
|
|
with self.assertRaises(ValueError):module.run('/fixture.cjs',[])
|
|
launch.assert_not_called()
|
|
def test_pending_fixtures_require_explicit_resume_and_valid_run(self):
|
|
run='a'*32;(self.root/(run+'.json')).write_text(json.dumps({'runId':run,'projects':[{'id':1}]}))
|
|
with patch.object(module.subprocess,'run',return_value=subprocess.CompletedProcess([],0)) as launch:
|
|
with self.assertRaises(ValueError):module.run('/fixture.cjs',[])
|
|
with self.assertRaises(ValueError):module.run('/fixture.cjs',[],'../escape')
|
|
with patch.dict(module.os.environ,{'DEBUG':'pw:api','PWDEBUG':'1'}):
|
|
self.assertEqual(module.run('/fixture.cjs',[],run),0)
|
|
kwargs=launch.call_args.kwargs
|
|
self.assertEqual(kwargs['env']['PD_DEV_BROWSER_RUN_ID'],run)
|
|
self.assertIn(int(kwargs['env']['PD_DEV_BROWSER_LOCK_FD']),kwargs['pass_fds'])
|
|
self.assertNotIn('Password',kwargs['env'])
|
|
self.assertNotIn('DEBUG',kwargs['env'])
|
|
self.assertNotIn('PWDEBUG',kwargs['env'])
|
|
|
|
if __name__=='__main__':unittest.main()
|