2 * Copyright 2000-2013 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.jetbrains.python;
18 import com.intellij.codeInsight.actions.OptimizeImportsAction;
19 import com.intellij.ide.DataManager;
20 import com.jetbrains.python.fixtures.PyTestCase;
25 public class PyOptimizeImportsTest extends PyTestCase {
28 protected void setUp() throws Exception {
30 // importsFromTypingUnusedInTypeComments depends on registered TokenSetContributors
31 PythonDialectsTokenSetProvider.reset();
34 public void testSimple() {
38 public void testOneOfMultiple() {
42 public void testImportStar() {
46 public void testImportStarOneOfMultiple() {
50 public void testTryExcept() {
54 public void testFromFuture() {
58 public void testUnresolved() { // PY-2201
62 public void testSuppressed() { // PY-5228
66 public void testSplit() {
70 public void testOrderByType() {
75 public void testAlphabeticalOrder() {
79 public void testInsertBlankLines() { // PY-8355
84 public void testNoExtraBlankLineAfterImportBlock() {
85 final String testName = getTestName(true);
86 myFixture.copyDirectoryToProject(testName, "");
87 myFixture.configureByFile("main.py");
88 OptimizeImportsAction.actionPerformedImpl(DataManager.getInstance().getDataContext(myFixture.getEditor().getContentComponent()));
89 myFixture.checkResultByFile(testName + "/main.after.py");
93 public void testImportsFromTypingUnusedInTypeComments() {
94 myFixture.copyDirectoryToProject("../typing", "");
98 private void doTest() {
99 myFixture.configureByFile(getTestName(true) + ".py");
100 OptimizeImportsAction.actionPerformedImpl(DataManager.getInstance().getDataContext(myFixture.getEditor().getContentComponent()));
101 myFixture.checkResultByFile(getTestName(true) + ".after.py");
105 protected String getTestDataPath() {
106 return super.getTestDataPath() + "/optimizeImports";