mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Introduce separate test class for PyRedeclarationInspection
This commit is contained in:
committed by
Semyon Proshev
parent
aa3981954b
commit
d3f1eda306
@@ -0,0 +1,13 @@
|
||||
def test_conditional(c):
|
||||
def foo():
|
||||
pass
|
||||
|
||||
if c:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
try:
|
||||
def foo():
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
@@ -0,0 +1,10 @@
|
||||
def test_decorated_function(decorator):
|
||||
def foo():
|
||||
pass
|
||||
|
||||
@decorator
|
||||
def foo():
|
||||
pass
|
||||
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
@@ -0,0 +1,3 @@
|
||||
class TestForLoopNoRedeclaraion:
|
||||
for foo in [1, 2, 3]:
|
||||
x = 1
|
||||
@@ -0,0 +1,6 @@
|
||||
class TestForLoopTarget:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
for <warning descr="Redeclared 'foo' defined above without usage">foo</warning> in [1, 2, 3]:
|
||||
x = 1
|
||||
@@ -0,0 +1,7 @@
|
||||
class TestForLoopBody:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
for _ in [1, 2, 3]:
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
@@ -0,0 +1,3 @@
|
||||
def test_local_variable():
|
||||
x = 1
|
||||
x = 2
|
||||
@@ -0,0 +1,4 @@
|
||||
# PY-10839
|
||||
class TestNestedComprehension:
|
||||
x = [[n for _ in []] for n in []]
|
||||
n = 2
|
||||
@@ -0,0 +1,6 @@
|
||||
def test_class():
|
||||
class X:
|
||||
pass
|
||||
|
||||
class <warning descr="Redeclared 'X' defined above without usage">X</warning>:
|
||||
pass
|
||||
@@ -0,0 +1,6 @@
|
||||
def test_function():
|
||||
def foo():
|
||||
pass
|
||||
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
@@ -0,0 +1,10 @@
|
||||
def TopLevelBoo():
|
||||
pass
|
||||
|
||||
|
||||
<warning descr="Redeclared 'TopLevelBoo' defined above without usage">TopLevelBoo</warning> = 1
|
||||
<warning descr="Redeclared 'TopLevelBoo' defined above without usage">TopLevelBoo</warning> = 2
|
||||
|
||||
|
||||
class <warning descr="Redeclared 'TopLevelBoo' defined above without usage">TopLevelBoo</warning>:
|
||||
pass
|
||||
@@ -1,95 +0,0 @@
|
||||
def test_class():
|
||||
class X:
|
||||
pass
|
||||
|
||||
class <warning descr="Redeclared 'X' defined above without usage">X</warning>:
|
||||
pass
|
||||
|
||||
def test_function():
|
||||
def foo():
|
||||
pass
|
||||
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
|
||||
|
||||
# Top-level variable test
|
||||
def TopLevelBoo():
|
||||
pass
|
||||
|
||||
|
||||
<warning descr="Redeclared 'TopLevelBoo' defined above without usage">TopLevelBoo</warning> = 1
|
||||
<warning descr="Redeclared 'TopLevelBoo' defined above without usage">TopLevelBoo</warning> = 2
|
||||
|
||||
|
||||
class <warning descr="Redeclared 'TopLevelBoo' defined above without usage">TopLevelBoo</warning>:
|
||||
pass
|
||||
|
||||
|
||||
def test_decorated_function(decorator):
|
||||
def foo():
|
||||
pass
|
||||
|
||||
@decorator
|
||||
def foo():
|
||||
pass
|
||||
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
|
||||
|
||||
def test_local_variable():
|
||||
x = 1
|
||||
x = 2
|
||||
|
||||
|
||||
def test_conditional(c):
|
||||
def foo():
|
||||
pass
|
||||
|
||||
if c:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
try:
|
||||
def foo():
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def test_while_loop(c):
|
||||
def foo():
|
||||
pass
|
||||
|
||||
while c:
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
|
||||
|
||||
class TestForLoopNoRedeclaraion:
|
||||
for foo in [1, 2, 3]:
|
||||
x = 1
|
||||
|
||||
|
||||
class TestForLoopTarget:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
for <warning descr="Redeclared 'foo' defined above without usage">foo</warning> in [1, 2, 3]:
|
||||
x = 1
|
||||
|
||||
|
||||
class TestForLoopBody:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
for _ in [1, 2, 3]:
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
|
||||
|
||||
# PY-10839
|
||||
class TestNestedComprehension:
|
||||
x = [[n for _ in []] for n in []]
|
||||
n = 2
|
||||
@@ -0,0 +1,7 @@
|
||||
def test_while_loop(c):
|
||||
def foo():
|
||||
pass
|
||||
|
||||
while c:
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
pass
|
||||
@@ -79,10 +79,6 @@ public class PythonInspectionsTest extends PyTestCase {
|
||||
doTest(getTestName(false), inspection);
|
||||
}
|
||||
|
||||
public void testPyRedeclarationInspection() {
|
||||
doHighlightingTest(PyRedeclarationInspection.class);
|
||||
}
|
||||
|
||||
public void testPyTrailingSemicolonInspection() {
|
||||
LocalInspectionTool inspection = new PyTrailingSemicolonInspection();
|
||||
doTest(getTestName(false), inspection);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.inspections;
|
||||
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
|
||||
public class PyRedeclarationInspectionTest extends PyTestCase {
|
||||
|
||||
public void testRedeclaredClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRedeclaredFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRedeclaredTopLevel() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDecoratedFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLocalVariable() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConditional() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWhile() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFor() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testForAndFunctionBefore() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testForBody() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNestedComprehension() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "inspections/PyRedeclarationInspection/" + getTestName(true) + ".py";
|
||||
|
||||
myFixture.configureByFile(path);
|
||||
myFixture.enableInspections(PyRedeclarationInspection.class);
|
||||
myFixture.checkHighlighting(true, false, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user