@VisibleForTesting
  public void createModuleFromPackage(final @NotNull PsiDirectory pyPackage) {
    if (pyPackage.getParent() == null) {
      return;
    }

    final String packageName = pyPackage.getName();
    if (!isEmptyPackage(pyPackage)) {
      CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"),
                                             PyBundle.message("refactoring.convert.package.to.module.error.not.empty.package", packageName),
                                             ID, pyPackage.getProject());
      return;
    }
    final VirtualFile parentDirVFile = pyPackage.getParent().getVirtualFile();
    final String moduleName = packageName + PyNames.DOT_PY;
    final VirtualFile existing = parentDirVFile.findChild(moduleName);
    if (existing != null) {
      showFileExistsErrorMessage(existing, ID, pyPackage.getProject());
      return;
    }
    final PsiFile initPy = pyPackage.findFile(PyNames.INIT_DOT_PY);
    WriteCommandAction.runWriteCommandAction(pyPackage.getProject(), () -> {
      try {
        if (initPy != null) {
          final VirtualFile initPyVFile = initPy.getVirtualFile();
          initPyVFile.rename(this, moduleName);
          initPyVFile.move(this, parentDirVFile);
        }
        else {
          PyClassRefactoringUtil.getOrCreateFile(parentDirVFile.getPath() + "/" + moduleName, pyPackage.getProject());
        }
        pyPackage.getVirtualFile().delete(this);
      }
      catch (IOException e) {
        LOG.error(e);
      }
    });
  }
@VisibleForTesting
  public void createModuleFromPackage(final @NotNull PsiDirectory pyPackage)