コード例 #1
0
  public static void show() {
    if (shownInSession) {
      return;
    }
    shownInSession = true;
    if (SharedCorePlugin.inTestMode()) {
      return;
    }
    String hide = System.getProperty("pydev.funding.hide");
    if (hide != null && (hide.equals("1") || hide.equals("true"))) {
      return;
    }
    IPreferenceStore preferenceStore = PydevPrefs.getPreferenceStore();
    boolean shownOnce = preferenceStore.getBoolean(PYDEV_FUNDING_SHOWN);
    if (!shownOnce) {
      boolean runNowIfInUiThread = false;
      RunInUiThread.async(
          new Runnable() {

            @Override
            public void run() {
              Display disp = Display.getCurrent();
              Shell shell = new Shell(disp);
              DialogNotifier notifier = new DialogNotifier(shell);
              notifier.open();
            }
          },
          runNowIfInUiThread);
    }
  }
コード例 #2
0
  /**
   * Adds a set of arguments used to wrap executed file with unittest runner.
   *
   * @param actualRun in an actual run we'll start the xml-rpc server.
   * @param coverageRun whether we should add the flags to do a coverage run.
   */
  private void addUnittestArgs(List<String> cmdArgs, boolean actualRun, boolean coverageRun)
      throws CoreException {
    if (isUnittest()) {

      // The tests are either written to a configuration file or passed as a parameter.
      String configurationFile =
          this.configuration.getAttribute(Constants.ATTR_UNITTEST_CONFIGURATION_FILE, "");
      if (configurationFile.length() > 0) {
        cmdArgs.add("--config_file");
        if (actualRun) {
          // We should write the contents to a temporary file (because it may be too long, so,
          // always write
          // to a file and read from it later on).
          File tempFile = PydevPlugin.getDefault().getTempFile("custom_pydev_unittest_launch_");
          try {
            OutputStream fileOutputStream = new FileOutputStream(tempFile);
            try {
              try {
                fileOutputStream.write(configurationFile.getBytes());
              } catch (IOException e) {
                throw new CoreException(
                    PydevPlugin.makeStatus(IStatus.ERROR, "Error writing to: " + tempFile, e));
              }
            } finally {
              fileOutputStream.close();
            }
          } catch (Exception e) {
            if (e instanceof CoreException) {
              throw (CoreException) e;
            }
            throw new CoreException(
                PydevPlugin.makeStatus(IStatus.ERROR, "Error writing to: " + tempFile, e));
          }
          cmdArgs.add(tempFile.toString());
        } else {
          cmdArgs.add(configurationFile);
        }
      } else {
        String tests = this.configuration.getAttribute(Constants.ATTR_UNITTEST_TESTS, "");
        if (tests.length() > 0) {
          cmdArgs.add("--tests");
          cmdArgs.add(tests);
        }
      }

      if (PyUnitPrefsPage2.getUsePyUnitView()) {
        // If we want to use the PyUnitView, we need to get the port used so that the python side
        // can connect.
        cmdArgs.add("--port");
        if (actualRun) {
          cmdArgs.add(String.valueOf(getPyUnitServer().getPort()));
        } else {
          cmdArgs.add("0");
        }
      }

      if (coverageRun) {
        cmdArgs.add("--coverage_output_dir");
        cmdArgs.add(PyCoverage.getCoverageDirLocation().getAbsolutePath());

        cmdArgs.add("--coverage_include");
        cmdArgs.add(PyCodeCoverageView.getChosenDir().getLocation().toOSString());

        if (actualRun) {
          IPreferenceStore prefs = PydevPrefs.getPreferenceStore();
          int testRunner = prefs.getInt(PyUnitPrefsPage2.TEST_RUNNER);

          switch (testRunner) {
            case PyUnitPrefsPage2.TEST_RUNNER_NOSE:
              RunInUiThread.async(
                  new Runnable() {

                    public void run() {
                      PyDialogHelpers.openWarningWithIgnoreToggle(
                          "Notes for coverage with the nose test runner.",
                          "Note1: When using the coverage with the nose test runner, "
                              + "please don't pass any specific parameter related to "
                              + "the run in the arguments, as that's already handled by PyDev "
                              + "(i.e.: don't use the builtin cover plugin from nose).\n"
                              + "\n"
                              + "Note2: It's currently not possible to use coverage with the multi-process "
                              + "plugin in nose.",
                          "KEY_COVERAGE_WITH_NOSE_TEST_RUNNER");
                    }
                  });

              break;
            case PyUnitPrefsPage2.TEST_RUNNER_PY_TEST:
              RunInUiThread.async(
                  new Runnable() {

                    public void run() {
                      PyDialogHelpers.openCritical(
                          "PyUnit coverage not compatible with the Py.test test runner.",
                          "Currently the PyDev PyUnit integration is not able to provide coverage "
                              + "info using the py.test test runner (please enter a "
                              + "feature request if you'd like that added)\n"
                              + "\n"
                              + "Note: the run will be continued anyways (without gathering coverage info).");
                    }
                  });
              break;
          }
        }
      }

      // Last thing: nose parameters or parameters the user configured.
      for (String s :
          parseStringIntoList(
              PyUnitPrefsPage2.getTestRunnerParameters(this.configuration, this.project))) {
        cmdArgs.add(s);
      }
    }
  }