diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 7db6820..a77b7a7 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -515,6 +515,19 @@ FamixPythonProject1Test >> testModuleImportsGlobalVariableFromAModuleRelatively self assert: import importedEntity equals: global ] +{ #category : 'tests - from-import relative' } +FamixPythonProject1Test >> testModuleImportsGlobalVariableFromAModuleRelativelyWithSpacesInPath [ + + | module global import | + self denyEmpty: self model allImports. + module := self moduleNamed: 'moduleInSubSubPackage3'. + global := self globalVariableNamed: 'moduleInSubpackage31Variable'. + import := module outgoingImports detect: [ :pimport | pimport target name = 'moduleInSubpackage31Variable' ]. + + self assert: import importingEntity equals: module. + self assert: import importedEntity equals: global +] + { #category : 'tests - from-import' } FamixPythonProject1Test >> testModuleImportsGlobalVariableFromAPackage [ @@ -541,6 +554,18 @@ FamixPythonProject1Test >> testModuleImportsModuleInPackage [ self assert: import importedEntity equals: importedModule ] +{ #category : 'tests - imports' } +FamixPythonProject1Test >> testModuleImportsSubPackageWithSpacesInThePath [ + + | moduleAtRoot import | + self denyEmpty: self model allImports. + moduleAtRoot := self moduleNamed: 'moduleWithSpacedImports'. + import := moduleAtRoot outgoingImports detect: [ :pimport | pimport target name = 'subsubpackage1' ]. + + self assert: import importingEntity equals: moduleAtRoot. + self assert: import importedEntity equals: (self packageNamed: 'subsubpackage1') +] + { #category : 'tests - modules' } FamixPythonProject1Test >> testModuleInRootPackage [ diff --git a/src/Famix-Python-Importer/FamixPythonAbstractImportResolvable.class.st b/src/Famix-Python-Importer/FamixPythonAbstractImportResolvable.class.st index 40bf116..f568c4b 100644 --- a/src/Famix-Python-Importer/FamixPythonAbstractImportResolvable.class.st +++ b/src/Famix-Python-Importer/FamixPythonAbstractImportResolvable.class.st @@ -37,9 +37,9 @@ FamixPythonAbstractImportResolvable >> entity: anObject [ FamixPythonAbstractImportResolvable >> findTargetEntityFor: aPath from: startEntities [ | possibleEntities splittedPath | - possibleEntities := startEntities. - splittedPath := aPath splitOn: $.. - possibleEntities := possibleEntities select: [ :possibleEntity | possibleEntity name = splittedPath first ]. + "We need to trim because we can have spaces between the dots." + splittedPath := (aPath splitOn: $.) collect: [ :segment | segment trim ]. + possibleEntities := startEntities select: [ :possibleEntity | possibleEntity name = splittedPath first ]. splittedPath removeFirst. [ splittedPath isNotEmpty ] whileTrue: [ | childName | diff --git a/src/Famix-Python-Importer/FamixPythonFromImportResolvable.class.st b/src/Famix-Python-Importer/FamixPythonFromImportResolvable.class.st index 520f5ff..2a02b35 100644 --- a/src/Famix-Python-Importer/FamixPythonFromImportResolvable.class.st +++ b/src/Famix-Python-Importer/FamixPythonFromImportResolvable.class.st @@ -38,12 +38,12 @@ FamixPythonFromImportResolvable >> resolveInScope: aScope currentEntity: current currentPackage := currentPackage parentPackage. remainingPath := remainingPath allButFirst ]. possibleEntities := currentPackage children ] - ifFalse: [ - "If we have an absolute path we just start at the root." + ifFalse: [ "If we have an absolute path we just start at the root." remainingPath := path. possibleEntities := currentEntity mooseModel rootEntities ]. - possibleEntities := (self findTargetEntityFor: remainingPath from: possibleEntities) allChildren select: [ :child | + "We trim the path because we can have spaces after the dots in relativ paths." + possibleEntities := (self findTargetEntityFor: remainingPath trim from: possibleEntities) allChildren select: [ :child | child isNamedEntity and: [ child name = entityName ] ]. "It is possible that we have multiple entities with the same name and in that case, python select the last one declared. So we sort by source anchor position to find this one."