mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Initial tests for types defined by mypy's typing module
This commit is contained in:
0
python/testData/typing/typing.py
Normal file
0
python/testData/typing/typing.py
Normal file
80
python/testSrc/com/jetbrains/python/PyTypingTest.java
Normal file
80
python/testSrc/com/jetbrains/python/PyTypingTest.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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;
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.jetbrains.python.documentation.PythonDocumentationProvider;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class PyTypingTest extends PyTestCase {
|
||||
@Nullable
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return ourPy3Descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setLanguageLevel(LanguageLevel.PYTHON32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
setLanguageLevel(null);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testClassType() {
|
||||
doTest("Foo",
|
||||
"class Foo:" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"def f(expr: Foo):\n" +
|
||||
" pass\n");
|
||||
}
|
||||
|
||||
public void testClassReturnType() {
|
||||
doTest("Foo",
|
||||
"class Foo:" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"def f() -> Foo:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"expr = f()\n");
|
||||
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String expectedType, @NotNull String text) {
|
||||
myFixture.copyDirectoryToProject("typing", "");
|
||||
myFixture.configureByText(PythonFileType.INSTANCE, text);
|
||||
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
|
||||
final TypeEvalContext context = TypeEvalContext.userInitiated(expr.getContainingFile()).withTracing();
|
||||
PyType actual = context.getType(expr);
|
||||
final String actualType = PythonDocumentationProvider.getTypeName(actual, context);
|
||||
assertEquals(expectedType, actualType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user