Skip to content

Commit

Permalink
Fix relative imports in packages + add tests + skip a test that canno…
Browse files Browse the repository at this point in the history
…t pass because of a SmaCC bug :(
  • Loading branch information
jecisc committed Oct 2, 2024
1 parent de79096 commit 7132125
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,47 @@ FamixPythonProject1Test >> testPackageImportsGlobalVariableFromAModule [
self assert: import importedEntity equals: global
]

{ #category : 'tests - from-import relative' }
FamixPythonProject1Test >> testPackageImportsGlobalVariableFromAModuleInAPackageTwoLevelHigherRelatively [

| package global import |
self skip. "There is currently a bug in SmaCC preventing to have this test green :(
https://github.com/j-brant/SmaCC/issues/27"
self denyEmpty: self model allImports.
package := self packageNamed: 'subsubpackage3'.
global := self globalVariableNamed: 'moduleInRoot3Variable'.
import := package outgoingImports detect: [ :pimport | pimport target name = 'moduleInRoot3Variable' ].

self assert: import importingEntity equals: package.
self assert: import importedEntity equals: global
]

{ #category : 'tests - from-import relative' }
FamixPythonProject1Test >> testPackageImportsGlobalVariableFromAModuleInaPackageOneLevelHigherRelatively [

| package global import |
self denyEmpty: self model allImports.
package := self packageNamed: 'subpackage3'.
global := self globalVariableNamed: 'moduleInRoot3Variable'.
import := package outgoingImports detect: [ :pimport | pimport target name = 'moduleInRoot3Variable' ].

self assert: import importingEntity equals: package.
self assert: import importedEntity equals: global
]

{ #category : 'tests - from-import relative' }
FamixPythonProject1Test >> testPackageImportsGlobalVariableFromAModuleRelatively [

| package global import |
self denyEmpty: self model allImports.
package := self packageNamed: 'subpackage3'.
global := self globalVariableNamed: 'moduleInSubpackage31Variable'.
import := package outgoingImports detect: [ :pimport | pimport target name = 'moduleInSubpackage31Variable' ].

self assert: import importingEntity equals: package.
self assert: import importedEntity equals: global
]

{ #category : 'tests - from-import' }
FamixPythonProject1Test >> testPackageImportsGlobalVariableFromAPackage [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ FamixPythonFromImportResolvable >> resolveInScope: aScope currentEntity: current
FamixPythonFromImportResolvable >> resolveRelativePathFor: currentEntity [

| possibleEntities splittedPath |
splittedPath := path.
possibleEntities := currentEntity.
splittedPath := path allButFirst.
possibleEntities := (currentEntity query ancestors ofType: FamixTPackage) anyOne. "If we have a module, we need to start with its parent package. If we have a package, it starts in itself."
[ splittedPath beginsWith: '.' ] whileTrue: [
possibleEntities := possibleEntities parentPackage.
splittedPath := splittedPath allButFirst ].
Expand Down

0 comments on commit 7132125

Please sign in to comment.