All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jetbrains.python.testing.nosetest.PythonNoseTestUrlProvider Maven / Gradle / Ivy

Go to download

A packaging of the IntelliJ Community Edition python-community library. This is release number 1 of trunk branch 142.

The newest version!
/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jetbrains.python.testing.nosetest;

import com.intellij.execution.Location;
import com.intellij.execution.testframework.sm.runner.SMTestLocator;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.jetbrains.python.testing.PythonUnitTestUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;

public class PythonNoseTestUrlProvider implements SMTestLocator, DumbAware {
  public static final String PROTOCOL_ID = "python_nosetestid";

  public static final PythonNoseTestUrlProvider INSTANCE = new PythonNoseTestUrlProvider();

  @NotNull
  @Override
  public List getLocation(@NotNull String protocol, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
    if (!PROTOCOL_ID.equals(protocol)) {
      return Collections.emptyList();
    }

    final List list = StringUtil.split(path, ".");
    if (list.isEmpty()) {
      return Collections.emptyList();
    }
    final int listSize = list.size();

    // parse path as [ns.]*fileName[.className][.methodName]
    if (listSize == 2) {
    final List classes = PythonUnitTestUtil.findLocations(project, list.get(0), list.get(1), null);
    if (classes.size() > 0)
      return classes;
    final List functions = PythonUnitTestUtil.findLocations(project, list.get(0), null, list.get(1));
    if (functions.size() > 0)
      return functions;
    }
    
    if (listSize > 2) {
      final String className = list.get(listSize - 2);
      final String methodName = list.get(listSize - 1);

      String fileName = list.get(listSize - 3);
      List locations = PythonUnitTestUtil.findLocations(project, fileName, className, methodName);
      if (locations.size() > 0) {
        return locations;
      }
      locations = PythonUnitTestUtil.findLocations(project, list.get(listSize - 2), list.get(listSize - 1), null);
      if (locations.size() > 0) {
        return locations;
      }
      final List functions = PythonUnitTestUtil.findLocations(project, list.get(listSize - 2), null, list.get(listSize - 1));
      if (functions.size() > 0)
        return functions;
    }
    return PythonUnitTestUtil.findLocations(project, project.getBasePath() + "/" + StringUtil.join(list, "/") + ".py", null, null);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy