Skip to content

Commit a76da3e

Browse files
authored
Enhance test for Activate.ps1 file integrity
Added a temporal check to ensure the source file is not modified during the test. Enhanced assertions to protect against future changes in the Activate.ps1 file's structure.
1 parent 75bd937 commit a76da3e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/test_venv.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ def test_install_scripts_mtime(self):
386386
venv_dir = os.path.dirname(venv.__file__)
387387
src_path = os.path.join(venv_dir, 'scripts', 'common', 'Activate.ps1')
388388
src_mtime = os.path.getmtime(src_path)
389+
390+
# Ensure a temporal difference between src and dst creation
389391
if abs(time.time() - src_mtime) < 1.0:
390392
time.sleep(1.1)
391393

@@ -404,14 +406,17 @@ def test_install_scripts_mtime(self):
404406
src_stat = os.stat(src_path)
405407
dst_stat = os.stat(dst_path)
406408
self.assertEqual(src_stat.st_mode, dst_stat.st_mode, "File modes do not match")
407-
self.assertNotIn(b'__VENV_PYTHON__', src_data,
408-
"Test assumes Activate.ps1 is a static file, not a template")
409+
409410
with open(src_path, 'rb') as f:
410411
src_data = f.read()
412+
413+
# Protection against the file becoming a template in the future
411414
self.assertNotIn(b'__VENV_PYTHON__', src_data,
412415
"Test assumes Activate.ps1 is a static file, not a template")
416+
413417
with open(dst_path, 'rb') as f:
414418
dst_data = f.read()
419+
415420
self.assertEqual(src_data, dst_data, "File contents do not match")
416421

417422

0 commit comments

Comments
 (0)