|
38 | 38 | import org.sonar.plugins.python.api.symbols.Symbol;
|
39 | 39 | import org.sonar.plugins.python.api.symbols.Usage;
|
40 | 40 | import org.sonar.plugins.python.api.tree.CallExpression;
|
| 41 | +import org.sonar.plugins.python.api.tree.ClassDef; |
41 | 42 | import org.sonar.plugins.python.api.tree.FileInput;
|
42 | 43 | import org.sonar.plugins.python.api.tree.FunctionDef;
|
43 | 44 | import org.sonar.plugins.python.api.tree.ImportFrom;
|
44 | 45 | import org.sonar.plugins.python.api.tree.QualifiedExpression;
|
| 46 | +import org.sonar.plugins.python.api.tree.Statement; |
45 | 47 | import org.sonar.plugins.python.api.tree.Tree;
|
46 | 48 | import org.sonar.python.PythonTestUtils;
|
47 | 49 | import org.sonar.python.index.Descriptor;
|
48 | 50 | import org.sonar.python.index.DescriptorUtils;
|
49 | 51 | import org.sonar.python.index.VariableDescriptor;
|
| 52 | +import org.sonar.python.tree.TreeUtils; |
50 | 53 | import org.sonar.python.types.DeclaredType;
|
51 | 54 | import org.sonar.python.types.InferredTypes;
|
52 | 55 |
|
@@ -697,7 +700,25 @@ public void class_having_itself_as_superclass_should_not_trigger_error() {
|
697 | 700 | FileInput fileInput = parseWithoutSymbols("class A(A): pass");
|
698 | 701 | Set<Symbol> globalSymbols = globalSymbols(fileInput, "mod");
|
699 | 702 | ClassSymbol a = (ClassSymbol) globalSymbols.iterator().next();
|
| 703 | + // SONARPY-1350: The parent "A" is not yet defined at the time it is read, so this is actually not correct |
700 | 704 | assertThat(a.superClasses()).containsExactly(a);
|
| 705 | + ClassDef classDef = (ClassDef) fileInput.statements().statements().get(0); |
| 706 | + assertThat(TreeUtils.getParentClassesFQN(classDef)).containsExactly("mod.mod.A"); |
| 707 | + } |
| 708 | + |
| 709 | + |
| 710 | + @Test |
| 711 | + public void class_having_another_class_with_same_name_should_not_trigger_error() { |
| 712 | + FileInput fileInput = parseWithoutSymbols( |
| 713 | + "from external import B", |
| 714 | + "class A:", |
| 715 | + " class B(B): pass" |
| 716 | + ); |
| 717 | + globalSymbols(fileInput, "mod"); |
| 718 | + ClassDef outerClassDef = (ClassDef) fileInput.statements().statements().get(1); |
| 719 | + ClassDef innerClassDef = (ClassDef) outerClassDef.body().statements().get(0); |
| 720 | + // SONARPY-1350: Parent should be external.B |
| 721 | + assertThat(TreeUtils.getParentClassesFQN(innerClassDef)).containsExactly("mod.mod.A.B"); |
701 | 722 | }
|
702 | 723 |
|
703 | 724 | @Test
|
|
0 commit comments