mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Test configuration deserialization
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<configuration default="false" name="MyConfig" type="tests" factoryName="py.test">
|
||||
<module name="tst"/>
|
||||
<option name="INTERPRETER_OPTIONS" value=""/>
|
||||
<option name="PARENT_ENVS" value="true"/>
|
||||
<option name="SDK_HOME" value="C:\temp\tst\venv\Scripts\python.exe"/>
|
||||
<option name="WORKING_DIRECTORY" value=""/>
|
||||
<option name="IS_MODULE_SDK" value="false"/>
|
||||
<option name="ADD_CONTENT_ROOTS" value="true"/>
|
||||
<option name="ADD_SOURCE_ROOTS" value="true"/>
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py"/>
|
||||
<option name="_new_keywords" value=""keywords""/>
|
||||
<option name="_new_additionalArguments" value=""--additional-args""/>
|
||||
<option name="_new_target" value=""foo.py""/>
|
||||
<option name="_new_targetType" value=""PATH""/>
|
||||
<method/>
|
||||
</configuration>
|
||||
@@ -0,0 +1,16 @@
|
||||
<configuration default="false" name="MyConfigWithCustom" type="tests" factoryName="py.test">
|
||||
<module name="tst"/>
|
||||
<option name="INTERPRETER_OPTIONS" value=""/>
|
||||
<option name="PARENT_ENVS" value="true"/>
|
||||
<option name="SDK_HOME" value="C:\temp\tst\venv\Scripts\python.exe"/>
|
||||
<option name="WORKING_DIRECTORY" value=""/>
|
||||
<option name="IS_MODULE_SDK" value="false"/>
|
||||
<option name="ADD_CONTENT_ROOTS" value="true"/>
|
||||
<option name="ADD_SOURCE_ROOTS" value="true"/>
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py"/>
|
||||
<option name="_new_keywords" value=""keywords""/>
|
||||
<option name="_new_additionalArguments" value=""--additional-args""/>
|
||||
<option name="_new_target" value=""spam""/>
|
||||
<option name="_new_targetType" value=""CUSTOM""/>
|
||||
<method/>
|
||||
</configuration>
|
||||
@@ -11,22 +11,31 @@ import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.jetbrains.env.EnvTestTagsRequired;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.python.testing.CreateConfigurationTestTask.PyConfigurationValidationTask;
|
||||
import com.jetbrains.env.ut.PyTestTestProcessRunner;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.run.targetBasedConfiguration.PyRunTargetVariant;
|
||||
import com.jetbrains.python.testing.ConfigurationTarget;
|
||||
import com.jetbrains.python.testing.PyTestConfiguration;
|
||||
import com.jetbrains.python.testing.PyTestFactory;
|
||||
import com.jetbrains.python.testing.PyTestFrameworkService;
|
||||
import com.jetbrains.python.tools.sdkTools.SdkCreationType;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jdom.input.SAXBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -54,6 +63,42 @@ public final class PythonPyTestingTest extends PyEnvTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides existing .xml and checks that configuration is able to parse it
|
||||
*/
|
||||
@Test
|
||||
public void testDeserialization() {
|
||||
runPythonTest(new PyExecutionFixtureTestTask("testRunner/env/pytest/config/") {
|
||||
@Override
|
||||
public void runTestOn(String sdkHome) throws Exception {
|
||||
final PyTestConfiguration configuration = configureByFile("MyConfig.xml");
|
||||
assertEquals("Wrong target type", new ConfigurationTarget("foo.py", PyRunTargetVariant.PATH), configuration.getTarget());
|
||||
assertEquals("Wrong keywords", "keywords", configuration.getKeywords());
|
||||
assertEquals("Wrong arguments", "--additional-args", configuration.getAdditionalArguments());
|
||||
|
||||
|
||||
final PyTestConfiguration configurationWithCustom = configureByFile("MyConfigWithCustom.xml");
|
||||
assertEquals("Wrong target type", new ConfigurationTarget("spam", PyRunTargetVariant.CUSTOM), configurationWithCustom.getTarget());
|
||||
assertEquals("Wrong keywords", "keywords", configurationWithCustom.getKeywords());
|
||||
assertEquals("Wrong arguments", "--additional-args", configurationWithCustom.getAdditionalArguments());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PyTestConfiguration configureByFile(@NotNull final String path) throws IOException, JDOMException {
|
||||
final VirtualFile file = myFixture.getTempDirFixture().getFile(path);
|
||||
assert file != null : "No config found";
|
||||
|
||||
final SAXBuilder builder = new SAXBuilder();
|
||||
final CharBuffer data = Charset.defaultCharset().decode(ByteBuffer.wrap(file.contentsToByteArray()));
|
||||
final Element element = builder.build(new StringReader(data.toString())).getRootElement();
|
||||
|
||||
final PyTestConfiguration configuration = new PyTestConfiguration(myFixture.getProject(), PyTestFactory.INSTANCE);
|
||||
configuration.readExternal(element);
|
||||
return configuration;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that python target pointing to module works correctly
|
||||
*/
|
||||
@@ -116,7 +161,8 @@ public final class PythonPyTestingTest extends PyEnvTestCase {
|
||||
@Test
|
||||
public void testTestNameBeforeTestStarted() {
|
||||
runPythonTest(
|
||||
new PyProcessWithConsoleTestTask<PyTestTestProcessRunner>("/testRunner/env/pytest/testNameBeforeTestStarted", SdkCreationType.EMPTY_SDK) {
|
||||
new PyProcessWithConsoleTestTask<PyTestTestProcessRunner>("/testRunner/env/pytest/testNameBeforeTestStarted",
|
||||
SdkCreationType.EMPTY_SDK) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user