|
44 | 44 | import org.graalvm.python.embedding.test.EmbeddingTestUtils;
|
45 | 45 | import org.graalvm.python.embedding.tools.exec.BuildToolLog;
|
46 | 46 | import org.graalvm.python.embedding.tools.vfs.VFSUtils;
|
| 47 | +import org.graalvm.python.embedding.tools.vfs.VFSUtils.PackagesChangedException; |
47 | 48 | import org.junit.Test;
|
48 | 49 |
|
49 | 50 | import java.io.IOException;
|
@@ -86,7 +87,6 @@ public class VFSUtilsTest {
|
86 | 87 |
|
87 | 88 | private static final String PACKAGE_WAS_REMOVED = "A package with transitive dependencies was removed since last install, setting up a clean venv";
|
88 | 89 | private static final String LOCK_FILE_HEADER = "generated by graalpy tests\nwith a two line header";
|
89 |
| - private static final String PACKAGES_CHANGED_ERROR = "packages changed in lock file %s, current packages %s, previous packages %s"; |
90 | 90 | private static final String MISSING_LOCK_FILE_WARNING = "missing lock file";
|
91 | 91 | private static final CharSequence STALE_VENV = "Stale GraalPy virtual environment, updating to";
|
92 | 92 |
|
@@ -184,7 +184,7 @@ private static boolean isVerbose() {
|
184 | 184 | * - packages declared only in plugin config - lock file path is provided, but does not exist
|
185 | 185 | */
|
186 | 186 | @Test
|
187 |
| - public void withPackagesOnlyFromPluginConfig() throws IOException { |
| 187 | + public void withPackagesOnlyFromPluginConfig() throws IOException, PackagesChangedException { |
188 | 188 | TestLog log = new TestLog();
|
189 | 189 | Path tmpDir = Files.createTempDirectory("withPackagesOnlyFromPluginConfig");
|
190 | 190 | Path venvDir = tmpDir.resolve("venv");
|
@@ -262,7 +262,7 @@ public void withPackagesOnlyFromPluginConfig() throws IOException {
|
262 | 262 | * - packages declared only in plugin config - and lock file path is not provided
|
263 | 263 | */
|
264 | 264 | @Test
|
265 |
| - public void withoutLockFile() throws IOException { |
| 265 | + public void withoutLockFile() throws IOException, PackagesChangedException { |
266 | 266 | TestLog log = new TestLog();
|
267 | 267 | Path tmpDir = Files.createTempDirectory("withoutLockFile");
|
268 | 268 | Path venvDir = tmpDir.resolve("venv");
|
@@ -375,7 +375,7 @@ private static List<String> createLockFileHeader(String graalPyVersion, String..
|
375 | 375 | }
|
376 | 376 |
|
377 | 377 | @Test
|
378 |
| - public void installAndLock() throws IOException { |
| 378 | + public void installAndLock() throws IOException, PackagesChangedException { |
379 | 379 | TestLog log = new TestLog();
|
380 | 380 | Path tmpDir = Files.createTempDirectory("installAndLock");
|
381 | 381 | Path venvDir = tmpDir.resolve("venv");
|
@@ -407,7 +407,7 @@ public void installAndLock() throws IOException {
|
407 | 407 | log.clearOutput();
|
408 | 408 |
|
409 | 409 | // reinstall without exact version declared - fails
|
410 |
| - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests")); |
| 410 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests")); |
411 | 411 | checkVenvCreate(log.getOutput(), false);
|
412 | 412 | assertFalse(log.getOutput().contains("pip install"));
|
413 | 413 | checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.2", "charset-normalizer", "idna", "urllib3", "certifi");
|
@@ -446,10 +446,9 @@ public void installAndLock() throws IOException {
|
446 | 446 |
|
447 | 447 | // add tiny-tiny - fails because inconsistent with lock file
|
448 | 448 | assert Files.exists(lockFile);
|
449 |
| - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.1", "tiny-tiny==0.2")); |
| 449 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.1", "tiny-tiny==0.2")); |
450 | 450 | checkVenvCreate(log.getOutput(), false);
|
451 | 451 | assertFalse(log.getOutput().contains("pip install"));
|
452 |
| - assertTrue(log.getOutput().contains(String.format(PACKAGES_CHANGED_ERROR, lockFile, "requests==2.32.1, tiny-tiny==0.2", "requests==2.32.1"))); |
453 | 452 | checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.1", "charset-normalizer", "idna", "urllib3", "certifi");
|
454 | 453 | checkVenvContentsFile(contents, "0.1", "requests==2.32.1");
|
455 | 454 | assertFalse(log.getOutput().contains(MISSING_LOCK_FILE_WARNING));
|
@@ -481,10 +480,9 @@ public void installAndLock() throws IOException {
|
481 | 480 | log.clearOutput();
|
482 | 481 |
|
483 | 482 | // update in declared packages requests version back to 2.32.2 - fails
|
484 |
| - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.2", "tiny-tiny==0.2")); |
| 483 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.2", "tiny-tiny==0.2")); |
485 | 484 | checkVenvCreate(log.getOutput(), false);
|
486 | 485 | assertFalse(log.getOutput().contains("pip install"));
|
487 |
| - assertTrue(log.getOutput().contains(String.format(PACKAGES_CHANGED_ERROR, lockFile, "requests==2.32.2, tiny-tiny==0.2", "requests==2.32.1, tiny-tiny==0.2"))); |
488 | 486 | checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.1", "tiny-tiny==0.2", "charset-normalizer", "idna", "urllib3", "certifi");
|
489 | 487 | checkVenvContentsFile(contents, "0.1", "requests==2.32.1", "tiny-tiny==0.2");
|
490 | 488 | assertFalse(log.getOutput().contains(MISSING_LOCK_FILE_WARNING));
|
@@ -520,10 +518,9 @@ public void installAndLock() throws IOException {
|
520 | 518 | log.clearOutput();
|
521 | 519 |
|
522 | 520 | // remove requests from packages list - fails because it is still in lock
|
523 |
| - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "tiny-tiny==0.2")); |
| 521 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "tiny-tiny==0.2")); |
524 | 522 | checkVenvCreate(log.getOutput(), false);
|
525 | 523 | assertFalse(log.getOutput().contains("pip install"));
|
526 |
| - assertTrue(log.getOutput().contains(String.format(PACKAGES_CHANGED_ERROR, lockFile, "tiny-tiny==0.2", "requests==2.32.2, tiny-tiny==0.2"))); |
527 | 524 | log.clearOutput();
|
528 | 525 | // lock only with tiny-tiny
|
529 | 526 | lock(venvDir, lockFile, log, "tiny-tiny==0.2");
|
@@ -656,12 +653,12 @@ private static void checkPackages(Path file, List<String> linesArg, String... pa
|
656 | 653 | }
|
657 | 654 | }
|
658 | 655 |
|
659 |
| - private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, String... packages) throws IOException { |
| 656 | + private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, String... packages) throws IOException, PackagesChangedException { |
660 | 657 | EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, packages);
|
661 | 658 | }
|
662 | 659 |
|
663 |
| - private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, Path lockFile, String... packages) throws IOException { |
664 |
| - EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, lockFile, MISSING_LOCK_FILE_WARNING, PACKAGES_CHANGED_ERROR, packages); |
| 660 | + private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, Path lockFile, String... packages) throws IOException, PackagesChangedException { |
| 661 | + EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, lockFile, MISSING_LOCK_FILE_WARNING, packages); |
665 | 662 | }
|
666 | 663 |
|
667 | 664 | private static void checkVenvContentsFile(Path contents, String graalPyVersion, String... packages) throws IOException {
|
|
0 commit comments