Skip to content

Commit ac96e16

Browse files
joke1196sonartech
authored andcommitted
Fixing flaky test when Typshed builtins are poisoned with an incomplete Python Version Set (#1111)
GitOrigin-RevId: 28935d3d2f89344d3d68d5064fc21343e8a6d639
1 parent 7d22c16 commit ac96e16

15 files changed

Lines changed: 115 additions & 2 deletions

python-checks/src/test/java/org/sonar/python/checks/CompressionModulesFromNamespaceCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class CompressionModulesFromNamespaceCheckTest {
2830

31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2937
@Test
3038
void test() {
3139
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_314));

python-checks/src/test/java/org/sonar/python/checks/FStringNestingLevelCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@
2020

2121
import java.util.EnumSet;
2222

23+
import org.junit.jupiter.api.AfterEach;
2324
import org.junit.jupiter.api.Test;
2425
import org.sonar.plugins.python.api.ProjectPythonVersion;
2526
import org.sonar.plugins.python.api.PythonVersionUtils;
2627
import org.sonar.python.checks.utils.PythonCheckVerifier;
28+
import org.sonar.python.types.TypeShed;
2729

2830
class FStringNestingLevelCheckTest {
2931

32+
@AfterEach
33+
void reset_python_version() {
34+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
35+
TypeShed.resetBuiltinSymbols();
36+
}
37+
3038
@Test
3139
void test_1() {
3240
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_312));

python-checks/src/test/java/org/sonar/python/checks/GenericClassTypeParameterCheckTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class GenericClassTypeParameterCheckTest {
30+
31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2837
@Test
2938
void test_python_3_12_only() {
3039
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_312));

python-checks/src/test/java/org/sonar/python/checks/GenericFunctionTypeParameterCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class GenericFunctionTypeParameterCheckTest {
2830

31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2937
@Test
3038
void test_1() {
3139
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_312));

python-checks/src/test/java/org/sonar/python/checks/GenericTypeStatementCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class GenericTypeStatementCheckTest {
2830

2931
private static final GenericTypeStatementCheck check = new GenericTypeStatementCheck();
3032

33+
@AfterEach
34+
void reset_python_version() {
35+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
36+
TypeShed.resetBuiltinSymbols();
37+
}
38+
3139
@Test
3240
void test_1() {
3341
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_312));

python-checks/src/test/java/org/sonar/python/checks/NotImplementedBooleanContextCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class NotImplementedBooleanContextCheckTest {
2830

31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2937
@Test
3038
void test() {
3139
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_314));

python-checks/src/test/java/org/sonar/python/checks/PytzUsageCheckTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
class PytzUsageCheckTest {
28+
29+
@AfterEach
30+
void reset_python_version() {
31+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
32+
TypeShed.resetBuiltinSymbols();
33+
}
34+
2635
@Test
2736
void test_39_310_311_312() {
2837
ProjectPythonVersion

python-checks/src/test/java/org/sonar/python/checks/TemplateAndStrConcatenationCheckTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class TemplateAndStrConcatenationCheckTest {
2830

31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2937
@Test
3038
void test() {
3139
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_314));
@@ -39,4 +47,3 @@ void test_older_python_version() {
3947
assertThat(issues).isEmpty();
4048
}
4149
}
42-

python-checks/src/test/java/org/sonar/python/checks/TemplateStringStructuralPatternMatchingCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class TemplateStringStructuralPatternMatchingCheckTest {
2830

31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2937
@Test
3038
void test() {
3139
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_314));

python-checks/src/test/java/org/sonar/python/checks/TypeAliasAnnotationCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.sonar.python.checks;
1818

1919
import java.util.EnumSet;
20+
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.sonar.plugins.python.api.ProjectPythonVersion;
2223
import org.sonar.plugins.python.api.PythonVersionUtils;
2324
import org.sonar.python.checks.utils.PythonCheckVerifier;
25+
import org.sonar.python.types.TypeShed;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
class TypeAliasAnnotationCheckTest {
2830

31+
@AfterEach
32+
void reset_python_version() {
33+
ProjectPythonVersion.setCurrentVersions(PythonVersionUtils.allVersions());
34+
TypeShed.resetBuiltinSymbols();
35+
}
36+
2937
@Test
3038
void verify_python_312_issues() {
3139
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_312));

0 commit comments

Comments
 (0)