summaryrefslogtreecommitdiff
path: root/python/testSrc/com/jetbrains/env/python/dotNet/PyIronPythonTest.java
blob: a6f9dd68971dea2567186b04ea9212557dfac049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package com.jetbrains.env.python.dotNet;

import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.Result;
import com.jetbrains.env.PyEnvTestCase;
import com.jetbrains.python.psi.PyFile;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;

/**
 * IronPython.NET specific tests
 *
 * @author Ilya.Kazakevich
 */
public class PyIronPythonTest extends PyEnvTestCase {

  /**
   * IronPython tag
   */
  static final String IRON_TAG = "iron";

  public PyIronPythonTest() {
    super(IRON_TAG);
  }

  /**
   * Tests skeleton generation
   */
  public void testSkeletons() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "testSkeleton.py",
      null
    ));
  }

  /**
   * Tests skeleton generation with "from" statements
   */
  public void testClassFromModule() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_class_from_module.py",
      null
    ));
  }

  /**
   * Tests skeleton generation when imported as alias
   */
  public void testClassFromModuleAlias() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_class_from_module_alias.py",
      null
    ));
  }

  /**
   * Tests skeleton generation when module is imported
   */
  public void testModuleFromPackage() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_module_from_package.py",
      null
    ));
  }

  /**
   * Tests skeleton generation when several classes are imported
   */
  public void testSeveralClasses() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_several_classes_from_module.py",
      "com.just.like.java.LikeJavaClass"
    ));
  }

  /**
   * Tests skeletons for built-in classes. We can't compare files (CLR class may be changed from version to version),
   * but we are sure there should be class System.Web.AspNetHostingPermissionLevel which is part of public API
   */
  public void testImportBuiltInSystem() throws Exception {
    final SkeletonTestTask task = new SkeletonTestTask(
      null,
      "System.Web",
      "import_system.py",
      null
    );
    runPythonTest(task);
    final PyFile skeleton = task.getGeneratedSkeleton();
    new ReadAction() {
      @Override
      protected void run(@NotNull Result result) throws Throwable {
        Assert.assertNotNull("System.Web does not contain class AspNetHostingPermissionLevel. Error generating stub? It has classes  " +
                             skeleton.getTopLevelClasses(),
                             skeleton.findTopLevelClass("AspNetHostingPermissionLevel"));
      }
    }.execute();

  }

  /**
   * Test importing of inner classes
   */
  public void testImportInnerClass() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.Deep.py",
      "SingleNameSpace.Some.Deep",
      "inner_class.py",
      null
    ));
  }

  /**
   * Test importing of the whole namespace
   */
  public void testWholeNameSpace() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.SingleNameSpace.py",
      "SingleNameSpace",
      "whole_namespace.py",
      null
    ));
  }

  /**
   * Test importing of single class
   */
  public void testSingleClass() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.SingleNameSpace.py",
      "SingleNameSpace",
      "single_class.py",
      null
    ));
  }
}