@Test
 public void testComparability1() {
   PythonVersion v12 = new PythonVersion(1, 2, "");
   PythonVersion v21 = new PythonVersion(2, 1, "");
   int z = v12.compareTo(v21);
   assertTrue(z < 0);
 }
 @Test
 public void testComparability2() {
   PythonVersion v26 = new PythonVersion(2, 6, "");
   PythonVersion v27 = new PythonVersion(2, 7, "");
   int z = v26.compareTo(v27);
   assertTrue(z < 0);
 }
 @Test
 public void testComparability3() {
   PythonVersion v331 = new PythonVersion(3, 3, "3.3.1");
   PythonVersion v333 = new PythonVersion(3, 3, "3.3.3");
   int z = v331.compareTo(v333);
   assertTrue(z < 0);
   assertFalse(v331.equals(v333));
 }
示例#4
0
 @VisibleForTesting
 static PythonVersion extractPythonVersion(Path pythonPath, ProcessExecutor.Result versionResult) {
   if (versionResult.getExitCode() == 0) {
     String versionString =
         CharMatcher.WHITESPACE.trimFrom(
             CharMatcher.WHITESPACE.trimFrom(versionResult.getStderr().get())
                 + CharMatcher.WHITESPACE
                     .trimFrom(versionResult.getStdout().get())
                     .replaceAll("\u001B\\[[;\\d]*m", ""));
     Matcher matcher = PYTHON_VERSION_REGEX.matcher(versionString.split("\\r?\\n")[0]);
     if (!matcher.matches()) {
       throw new HumanReadableException(
           "`%s -V` returned an invalid version string %s", pythonPath, versionString);
     }
     return PythonVersion.of(matcher.group(1));
   } else {
     throw new HumanReadableException(versionResult.getStderr().get());
   }
 }