27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
"""Regression for deterministic package mtimes and root-created Python caches."""
|
|
import os
|
|
from pathlib import Path
|
|
import py_compile
|
|
import runpy
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
class UpgradeTests(unittest.TestCase):
|
|
def test_same_size_source_with_old_pyc_loads_new_version_after_installer_step(self):
|
|
clear = runpy.run_path(str(Path(__file__).parents[1] / "packaging/clear_runtime_cache.py"))["clear"]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); package = root / "runtime"; package.mkdir()
|
|
init = package / "__init__.py"; init.write_text('VERSION="0.1.0"\n'); os.utime(init,(0,0))
|
|
py_compile.compile(str(init),doraise=True)
|
|
init.write_text('VERSION="0.2.0"\n');os.utime(init,(0,0))
|
|
backup=root/'backup.json';backup.write_text('preserve')
|
|
code='import sys;sys.path.insert(0,sys.argv[1]);import runtime;print(runtime.VERSION)'
|
|
def version():return subprocess.check_output([sys.executable,'-I','-B','-c',code,str(root)],text=True).strip()
|
|
self.assertEqual(version(),'0.1.0')
|
|
clear(root);clear(root)
|
|
self.assertEqual(version(),'0.2.0')
|
|
self.assertEqual(backup.read_text(),'preserve')
|