PythonInstallationDirectoryFinder { public static List<PythonInstallationDirectory> findPossibleInstallationsFor(final String path) { final File location = new File(path); if (!location.exists() || !location.isDirectory()) { return new ArrayList<>(); } return Stream.of(location.listFiles()) .filter(File::isFile) .flatMap(file -> EnumSet.allOf(SuiteExecutor.class) .stream() .filter(executor -> file.getName().equals(executor.executableName()))) .map(interpreter -> new PythonInstallationDirectory(location.toURI(), interpreter)) .collect(toList()); }  static List<PythonInstallationDirectory> whereArePythonInterpreters(); static Optional<PythonInstallationDirectory> whereIsPythonInterpreter(final SuiteExecutor interpreter); static List<PythonInstallationDirectory> findPossibleInstallationsFor(final String path);  }
@Test public void emptyPossibleInstallationDirectoriesAreReturned_whenLocationDoesNotExist() throws Exception { assertThat(PythonInstallationDirectoryFinder.findPossibleInstallationsFor("not_existing_location")).isEmpty(); }
@Test public void emptyPossibleInstallationDirectoriesAreReturned_whenLocationDoesNotContainExecutable() throws Exception { final File location = new File(tempDir, "no_executable"); location.mkdir(); new File(location, "notExecutor").createNewFile(); new File(location, "nested_dir").mkdir(); assertThat(PythonInstallationDirectoryFinder.findPossibleInstallationsFor(location.getPath())).isEmpty(); }
@Test public void possibleInstallationDirectoriesAreReturned_forEveryExecutor() throws Exception { for (final SuiteExecutor executor : EnumSet.allOf(SuiteExecutor.class)) { final File location = new File(tempDir, executor.name() + "_executable"); location.mkdir(); new File(location, executor.executableName()).createNewFile(); new File(location, "notExecutor").createNewFile(); new File(location, "nested_dir").mkdir(); assertThat(PythonInstallationDirectoryFinder.findPossibleInstallationsFor(location.getPath())) .containsOnly(new PythonInstallationDirectory(location.toURI(), executor)); } }
@Test public void allPossibleInstallationDirectoriesAreReturned_whenSeveralExecutablesExist() throws Exception { final File location = new File(tempDir, "several_executables"); location.mkdir(); new File(location, SuiteExecutor.Python.executableName()).createNewFile(); new File(location, SuiteExecutor.Python2.executableName()).createNewFile(); new File(location, SuiteExecutor.Python3.executableName()).createNewFile(); new File(location, "notExecutor").createNewFile(); new File(location, "nested_dir").mkdir(); assertThat(PythonInstallationDirectoryFinder.findPossibleInstallationsFor(location.getPath())).containsOnly( new PythonInstallationDirectory(location.toURI(), SuiteExecutor.Python), new PythonInstallationDirectory(location.toURI(), SuiteExecutor.Python2), new PythonInstallationDirectory(location.toURI(), SuiteExecutor.Python3)); }