|
@@ -15,10 +15,11 @@ BASH = shutil.which('bash') or ('C:/Program Files/Git/bin/bash.exe' if Path('C:/
|
|
|
|
|
|
|
|
@unittest.skipUnless(BASH, 'bash is unavailable')
|
|
@unittest.skipUnless(BASH, 'bash is unavailable')
|
|
|
class BootstrapTests(unittest.TestCase):
|
|
class BootstrapTests(unittest.TestCase):
|
|
|
- def run_script(self, action, fail='', env_exists=True, args=()):
|
|
|
|
|
|
|
+ def run_script(self, action, fail='', env_exists=True, args=(), deploy_python=None):
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
|
root=Path(tmp)
|
|
root=Path(tmp)
|
|
|
shutil.copy2(ROOT/'deploy.sh',root/'deploy.sh')
|
|
shutil.copy2(ROOT/'deploy.sh',root/'deploy.sh')
|
|
|
|
|
+ shutil.copy2(ROOT/'.python-version',root/'.python-version')
|
|
|
(root/'.env.example').write_text('EXAMPLE=1\n')
|
|
(root/'.env.example').write_text('EXAMPLE=1\n')
|
|
|
if env_exists: (root/'.env').write_text('KEEP=unchanged\n')
|
|
if env_exists: (root/'.env').write_text('KEEP=unchanged\n')
|
|
|
bin_dir=root/'bin'; bin_dir.mkdir()
|
|
bin_dir=root/'bin'; bin_dir.mkdir()
|
|
@@ -26,6 +27,8 @@ class BootstrapTests(unittest.TestCase):
|
|
|
fake.write_text('#!/bin/sh\nprintf "%s\\n" "$*" >> "$CALL_LOG"\ncase "$*" in *"$FAIL_MATCH"*) if [ -n "$FAIL_MATCH" ]; then exit 9; fi ;; esac\n')
|
|
fake.write_text('#!/bin/sh\nprintf "%s\\n" "$*" >> "$CALL_LOG"\ncase "$*" in *"$FAIL_MATCH"*) if [ -n "$FAIL_MATCH" ]; then exit 9; fi ;; esac\n')
|
|
|
fake.chmod(0o755)
|
|
fake.chmod(0o755)
|
|
|
env={**os.environ,'PATH':str(bin_dir)+os.pathsep+os.environ['PATH'],'CALL_LOG':str(root/'calls.log'),'FAIL_MATCH':fail}
|
|
env={**os.environ,'PATH':str(bin_dir)+os.pathsep+os.environ['PATH'],'CALL_LOG':str(root/'calls.log'),'FAIL_MATCH':fail}
|
|
|
|
|
+ env.pop('DEPLOY_PYTHON', None)
|
|
|
|
|
+ if deploy_python is not None: env['DEPLOY_PYTHON'] = deploy_python
|
|
|
result=subprocess.run([BASH,str(root/'deploy.sh'),action,*args],env=env,capture_output=True,text=True)
|
|
result=subprocess.run([BASH,str(root/'deploy.sh'),action,*args],env=env,capture_output=True,text=True)
|
|
|
calls=(root/'calls.log').read_text() if (root/'calls.log').exists() else ''
|
|
calls=(root/'calls.log').read_text() if (root/'calls.log').exists() else ''
|
|
|
return result.returncode,calls,(root/'.env').read_text()
|
|
return result.returncode,calls,(root/'.env').read_text()
|
|
@@ -45,6 +48,17 @@ class BootstrapTests(unittest.TestCase):
|
|
|
self.assertLess(calls.index('download_model.py'),calls.index('update_data.py'))
|
|
self.assertLess(calls.index('download_model.py'),calls.index('update_data.py'))
|
|
|
self.assertEqual(env,'KEEP=unchanged\n')
|
|
self.assertEqual(env,'KEEP=unchanged\n')
|
|
|
|
|
|
|
|
|
|
+ def test_python_selection_is_consistent_throughout_pipeline(self):
|
|
|
|
|
+ for override, expected in ((None, '3.14.5'), ('3.11', '3.11')):
|
|
|
|
|
+ with self.subTest(override=override):
|
|
|
|
|
+ code, calls, _ = self.run_script('templates', deploy_python=override)
|
|
|
|
|
+ self.assertEqual(code, 0, calls)
|
|
|
|
|
+ lines = calls.splitlines()
|
|
|
|
|
+ self.assertEqual(lines[0], f'python install {expected}')
|
|
|
|
|
+ self.assertEqual(lines[1], f'sync --frozen --python {expected}')
|
|
|
|
|
+ for line in lines[2:]:
|
|
|
|
|
+ self.assertTrue(line.startswith(f'run --frozen --no-sync --python {expected} python '), line)
|
|
|
|
|
+
|
|
|
def test_restart_starts_with_restart_flag_without_data_update(self):
|
|
def test_restart_starts_with_restart_flag_without_data_update(self):
|
|
|
code,calls,_=self.run_script('restart')
|
|
code,calls,_=self.run_script('restart')
|
|
|
self.assertEqual(code,0)
|
|
self.assertEqual(code,0)
|