From 974095be6df4cc9f36b072d1884d78721de3f196 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Wed, 8 Jan 2025 17:55:55 +0100 Subject: [PATCH] Add more tests on invocations Test invocation of functions from package, class, method, function, recursive function, simple source anchor and imported functions without aliases --- .../FamixPythonProject1Test.class.st | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index ce68de0..5740145 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -779,6 +779,57 @@ FamixPythonProject1Test >> testFunctionInAPackage [ self assert: function functionOwner equals: (self packageNamed: 'subsubpackage1') ] +{ #category : 'tests - invocations' } +FamixPythonProject1Test >> testFunctionInvocationFromClass [ + + | class function invocation | + function := self functionNamed: 'sort_list'. + class := self classNamed: 'Employee'. + + invocation := function incomingInvocations detect: [ :aReference | aReference sender = class ]. + + self assert: invocation class equals: FamixPythonInvocation. + self assert: invocation source equals: class. + self assert: invocation sender equals: class. + self assertCollection: invocation target hasSameElements: { function }. + self assert: invocation anyCandidate equals: function. + self assert: (class outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ]) +] + +{ #category : 'tests - invocations' } +FamixPythonProject1Test >> testFunctionInvocationFromFunction [ + + | function2 function invocation | + function := self functionNamed: 'sort_list'. + function2 := self functionNamed: 'functionWithImportsInRoot2'. + + invocation := function incomingInvocations detect: [ :aReference | aReference sender = function2 ]. + + self assert: invocation class equals: FamixPythonInvocation. + self assert: invocation source equals: function2. + self assert: invocation sender equals: function2. + self assertCollection: invocation target hasSameElements: { function }. + self assert: invocation anyCandidate equals: function. + self assert: (function2 outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ]) +] + +{ #category : 'tests - invocations' } +FamixPythonProject1Test >> testFunctionInvocationFromMethod [ + + | method function invocation | + function := self functionNamed: 'sort_list'. + method := self methodNamed: 'print_info_2'. + + invocation := function incomingInvocations detect: [ :aReference | aReference sender = method ]. + + self assert: invocation class equals: FamixPythonInvocation. + self assert: invocation source equals: method. + self assert: invocation sender equals: method. + self assertCollection: invocation target hasSameElements: { function }. + self assert: invocation anyCandidate equals: function. + self assert: (method outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ]) +] + { #category : 'tests - invocations' } FamixPythonProject1Test >> testFunctionInvocationFromModule [ @@ -796,6 +847,36 @@ FamixPythonProject1Test >> testFunctionInvocationFromModule [ self assert: (module outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ]) ] +{ #category : 'tests - invocations' } +FamixPythonProject1Test >> testFunctionInvocationFromPackage [ + + | package function invocation | + function := self functionNamed: 'function_with_lambda_with_function_ref'. + package := self packageNamed: 'subsubpackage1'. + + invocation := function incomingInvocations detect: [ :aReference | aReference sender = package ]. + + self assert: invocation class equals: FamixPythonInvocation. + self assert: invocation source equals: package. + self assert: invocation sender equals: package. + self assertCollection: invocation target hasSameElements: { function }. + self assert: invocation anyCandidate equals: function. + self assert: (package outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ]) +] + +{ #category : 'tests - invocations' } +FamixPythonProject1Test >> testFunctionInvocationSourceAnchor [ + + | function2 function invocation | + function := self functionNamed: 'sort_list'. + function2 := self functionNamed: 'functionWithImportsInRoot2'. + + invocation := function incomingInvocations detect: [ :aReference | aReference sender = function2 ]. + + self assert: invocation sourceAnchor isNotNil. + self assert: invocation sourceText equals: 'sort_list(x, y)' +] + { #category : 'tests - references' } FamixPythonProject1Test >> testFunctionReferenceFromClass [ @@ -3066,6 +3147,22 @@ FamixPythonProject1Test >> testReadAccessToParameter [ self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = parameter ]) ] +{ #category : 'tests - invocations' } +FamixPythonProject1Test >> testRecursiveFunctionInvocation [ + + | function invocation | + function := self functionNamed: 'fibonacci'. + + invocation := function incomingInvocations detect: [ :aReference | aReference sender = function ]. + + self assert: invocation class equals: FamixPythonInvocation. + self assert: invocation source equals: function. + self assert: invocation sender equals: function. + self assertCollection: invocation target hasSameElements: { function }. + self assert: invocation anyCandidate equals: function. + self assert: (function outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ]) +] + { #category : 'tests - modules' } FamixPythonProject1Test >> testRootModule [