From d6406c33c485460b8061c92bcbb296a9faa6c3cf Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Fri, 27 Sep 2024 03:52:40 +0200 Subject: [PATCH] Add tests on from import in functions --- .../FamixPythonProject1Test.class.st | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 89fb366..f2aaf67 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -107,6 +107,84 @@ FamixPythonProject1Test >> testClassImportsModule [ self assert: import importedEntity equals: (self moduleNamed: 'moduleAtRoot3') ] +{ #category : 'tests - from-import' } +FamixPythonProject1Test >> testFunctionImportsClassFromAModule [ + + | function class import | + self denyEmpty: self model allImports. + function := self functionNamed: 'functionWithImportsInRoot2'. + class := self classNamed: 'Person'. + import := function outgoingImports detect: [ :pimport | pimport target name = 'Person' ]. + + self assert: import importingEntity equals: function. + self assert: import importedEntity equals: class +] + +{ #category : 'tests - from-import' } +FamixPythonProject1Test >> testFunctionImportsClassFromAPackage [ + + | function class import | + self denyEmpty: self model allImports. + function := self functionNamed: 'functionWithImportsInRoot2'. + class := self classNamed: 'Room'. + import := function outgoingImports detect: [ :pimport | pimport target name = 'Room' ]. + + self assert: import importingEntity equals: function. + self assert: import importedEntity equals: class +] + +{ #category : 'tests - from-import' } +FamixPythonProject1Test >> testFunctionImportsFunctionFromAModule [ + + | function function1 import | + self denyEmpty: self model allImports. + function := self functionNamed: 'functionWithImportsInRoot2'. + function1 := self functionNamed: 'sort_list'. + import := function outgoingImports detect: [ :pimport | pimport target name = 'sort_list' ]. + + self assert: import importingEntity equals: function. + self assert: import importedEntity equals: function1 +] + +{ #category : 'tests - from-import' } +FamixPythonProject1Test >> testFunctionImportsFunctionFromAPackage [ + + | function function1 import | + self denyEmpty: self model allImports. + function := self functionNamed: 'functionWithImportsInRoot2'. + function1 := self functionNamed: 'return2'. + import := function outgoingImports detect: [ :pimport | pimport target name = 'return2' ]. + + self assert: import importingEntity equals: function. + self assert: import importedEntity equals: function1 +] + +{ #category : 'tests - from-import' } +FamixPythonProject1Test >> testFunctionImportsGlobalVariableFromAModule [ + + | function global import | + self denyEmpty: self model allImports. + function := self functionNamed: 'functionWithImportsInRoot2'. + global := self globalVariableNamed: 'moduleAtRootVariable'. + import := function outgoingImports detect: [ :pimport | pimport target name = 'moduleAtRootVariable' ]. + + self assert: import importingEntity equals: function. + self assert: import importedEntity equals: global +] + +{ #category : 'tests - from-import' } +FamixPythonProject1Test >> testFunctionImportsGlobalVariableFromAPackage [ + + | function global import | + self denyEmpty: self model allImports. + function := self functionNamed: 'functionWithImportsInRoot2'. + global := self globalVariableNamed: 'rootPackageVariable'. + import := function outgoingImports detect: [ :pimport | pimport target name = 'rootPackageVariable' ]. + + self assert: import importingEntity equals: function. + self assert: import importedEntity equals: global +] + { #category : 'tests - imports' } FamixPythonProject1Test >> testFunctionImportsModule [