d30bba454b52aebdee0a5031742acc8c277e240f
[idea/community.git] / python / testSrc / com / jetbrains / python / PyStructureViewTest.java
1 /*
2  * Copyright 2000-2014 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.jetbrains.python;
17
18 import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
19 import com.intellij.util.Consumer;
20 import com.jetbrains.python.fixtures.PyTestCase;
21
22 import static com.intellij.testFramework.PlatformTestUtil.assertTreeEqual;
23
24 /**
25  * @author vlan
26  */
27 public class PyStructureViewTest extends PyTestCase {
28   private static final String TEST_DIRECTORY = "structureView/";
29
30   public void testBaseClassNames() {
31     myFixture.configureByFiles(TEST_DIRECTORY + "baseClassNames.py",
32                                TEST_DIRECTORY + "lib1.py");
33     doTest("-baseClassNames.py\n" +
34            " -B1\n" +
35            "  f(self, x)\n" +
36            " -B2(object)\n" +
37            "  g(x)\n" +
38            " C(B1, B2)\n" +
39            " D1(C)\n" +
40            " D2(C)\n" +
41            " D3(lib1.C)\n" +
42            " D4(foo.bar.C)\n",
43            false);
44   }
45
46   // PY-3371
47   public void testAttributes() {
48     myFixture.configureByFile(TEST_DIRECTORY + "attributes.py");
49     doTest("-attributes.py\n" +
50            " -B(object)\n" +
51            "  f(self, x)\n" +
52            "  __init__(self, x, y)\n" +
53            "  g(cls, x)\n" +
54            "  c1\n" +
55            "  c2\n" +
56            "  i1\n" +
57            "  i2\n" +
58            "  i3\n" +
59            " g1\n" +
60            " -C(B)\n" +
61            "  __init__(self, x, y)\n" +
62            "  h(self)\n" +
63            "  c2\n" +
64            "  c3\n" +
65            "  i3\n" +
66            "  i4\n" +
67            "  i5\n" +
68            " g2\n",
69            false);
70   }
71
72   // PY-3936
73   public void testInherited() {
74     myFixture.configureByFile(TEST_DIRECTORY + "inherited.py");
75     doTest("-inherited.py\n" +
76            " -C(object)\n" +
77            "  f(self, x)\n" +
78            "  __str__(self)\n" +
79            "  x\n" +
80            "  __delattr__(self, name)\n" +
81            "  __format__(self, *args, **kwargs)\n" +
82            "  __getattribute__(self, name)\n" +
83            "  __hash__(self)\n" +
84            "  __init__(self)\n" +
85            "  __new__(cls, *more)\n" +
86            "  __reduce_ex__(self, *args, **kwargs)\n" +
87            "  __reduce__(self, *args, **kwargs)\n" +
88            "  __repr__(self)\n" +
89            "  __setattr__(self, name, value)\n" +
90            "  __sizeof__(self)\n" +
91            "  __subclasshook__(cls, subclass)\n" +
92            "  __class__\n" +
93            "  __dict__\n" +
94            "  __doc__\n" +
95            "  __module__\n",
96            true);
97   }
98
99   private void doTest(final String expected, final boolean inherited) {
100     myFixture.testStructureView(component -> {
101       component.setActionActive("SHOW_INHERITED", !inherited);
102       assertTreeEqual(component.getTree(), expected);
103     });
104   }
105 }