respect "super()" in python post processing (#964)

if a method call is qualified with "super()" only record edges pointing to the base class of the context of the callee
This commit is contained in:
Malte Langkabel
2020-04-06 20:16:27 +02:00
committed by GitHub
parent 6ae55b3281
commit 54c6f189b1
2 changed files with 157 additions and 85 deletions
+35 -8
View File
@@ -100,23 +100,50 @@ TEST_CASE("python post processing regards class name in call context when adding
{
std::shared_ptr<TestStorage> storage = parseCode(
"class A:\n"
" def init(self):\n"
" def __init__(self):\n"
" pass\n"
"\n"
"class A1(A):\n"
" def init(self):\n"
" A.init()\n"
" def __init__(self):\n"
" A.__init__()\n"
"\n"
"class B:\n"
" def init(self):\n"
" def __init__(self):\n"
" pass\n");
REQUIRE(storage->calls.size() == 1);
REQUIRE(utility::containsElement<std::wstring>(storage->calls, L"test.A1.init -> test.A.init"));
REQUIRE(utility::containsElement<std::wstring>(
storage->calls, L"test.A1.__init__ -> test.A.__init__"));
REQUIRE(
!utility::containsElement<std::wstring>(storage->calls, L"test.A1.init -> test.A1.init"));
REQUIRE(!utility::containsElement<std::wstring>(storage->calls, L"test.A1.init -> test.B.init"));
REQUIRE(!utility::containsElement<std::wstring>(
storage->calls, L"test.A1.__init__ -> test.A1.__init__"));
REQUIRE(!utility::containsElement<std::wstring>(
storage->calls, L"test.A1.__init__ -> test.B.__init__"));
}
TEST_CASE("python post processing regards super() in call context when adding ambiguous edges")
{
std::shared_ptr<TestStorage> storage = parseCode(
"class A:\n"
" def __init__(self):\n"
" pass\n"
"\n"
"class A1(A):\n"
" def __init__(self):\n"
" super().__init__()\n"
"\n"
"class B:\n"
" def __init__(self):\n"
" pass\n");
REQUIRE(storage->calls.size() == 2);
REQUIRE(utility::containsElement<std::wstring>(
storage->calls, L"test.A1.__init__ -> test.A.__init__"));
REQUIRE(!utility::containsElement<std::wstring>(
storage->calls, L"test.A1.__init__ -> test.A1.__init__"));
REQUIRE(!utility::containsElement<std::wstring>(
storage->calls, L"test.A1.__init__ -> test.B.__init__"));
}
#endif // BUILD_PYTHON_LANGUAGE_PACKAGE