Search in sources :

Example 11 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testDictAssign.

public void testDictAssign() {
    PyBlockEvaluator eval = doEvaluate("a={}\na['b']='c'");
    Map map = (Map) eval.getValue("a");
    assertEquals(1, map.size());
    assertEquals("c", map.get("b"));
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) Map(java.util.Map)

Example 12 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testImport.

/**
   * Ensures module has any vars imported from external modules
   */
public void testImport() {
    myFixture.copyDirectoryToProject("blockEvaluator", "");
    final PyFile file = PyUtil.as(myFixture.configureByFile("my_module.py"), PyFile.class);
    assert file != null : "Failed to read file";
    final PyBlockEvaluator sut = new PyBlockEvaluator();
    sut.evaluate(file);
    Assert.assertEquals("Failed to read var from package module", "foo", sut.getValueAsString("VARIABLE_IN_PACKAGE_MODULE"));
    Assert.assertEquals("Failed to read var from package", "foo", sut.getValueAsString("VARIABLE_IN_PACKAGE"));
    Assert.assertEquals("Failed to read list from another module", Arrays.asList("a", "b", "c", "d"), sut.getValueAsList("SOME_LIST"));
    Assert.assertEquals("Failed to read var from another module", "42", sut.getValueAsString("SOME_VARIABLE"));
    Assert.assertEquals("Failed to read var from another module with alias", "foo", sut.getValueAsString("MY_RENAMED_VAR"));
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) PyFile(com.jetbrains.python.psi.PyFile)

Example 13 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testDict.

public void testDict() {
    PyBlockEvaluator eval = doEvaluate("a={'b': 'c'}");
    Map map = (Map) eval.getValue("a");
    assertEquals(1, map.size());
    assertEquals("c", map.get("b"));
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) Map(java.util.Map)

Aggregations

PyBlockEvaluator (com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator)13 Map (java.util.Map)5 PyFile (com.jetbrains.python.psi.PyFile)3 PyStringLiteralExpression (com.jetbrains.python.psi.PyStringLiteralExpression)2 PyFunction (com.jetbrains.python.psi.PyFunction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1