Skip to content

Commit

Permalink
Add tests on package references + manage it
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 20, 2024
1 parent ee52d62 commit 3638a9d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Famix-Python-Entities/FamixPythonClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
| Relation | Origin | Opposite | Type | Comment |
|---|
| `incomingImports` | `FamixTImportable` | `importedEntity` | `FamixTImport` | List of imports of this entity|
| `incomingReferences` | `FamixTReferenceable` | `referredType` | `FamixTReference` | References to this entity by other entities.|
| `incomingReferences` | `FamixTReferenceable` | `referredEntity` | `FamixTReference` | References to this entity by other entities.|
| `subInheritances` | `FamixTWithInheritances` | `superclass` | `FamixTInheritance` | Subinheritance relationships, i.e. known subclasses of this type.|
### Other
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Python-Entities/FamixPythonFunction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
|---|
| `incomingImports` | `FamixTImportable` | `importedEntity` | `FamixTImport` | List of imports of this entity|
| `incomingInvocations` | `FamixTInvocable` | `candidates` | `FamixTInvocation` | Incoming invocations from other behaviours computed by the candidate operator.|
| `incomingReferences` | `FamixTReferenceable` | `referredType` | `FamixTReference` | References to this entity by other entities.|
| `incomingReferences` | `FamixTReferenceable` | `referredEntity` | `FamixTReference` | References to this entity by other entities.|
### Other
| Relation | Origin | Opposite | Type | Comment |
Expand Down
5 changes: 3 additions & 2 deletions src/Famix-Python-Entities/FamixPythonPackage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
| Relation | Origin | Opposite | Type | Comment |
|---|
| `incomingImports` | `FamixTImportable` | `importedEntity` | `FamixTImport` | List of imports of this entity|
| `incomingReferences` | `FamixTReferenceable` | `referredEntity` | `FamixTReference` | References to this entity by other entities.|
### Other
| Relation | Origin | Opposite | Type | Comment |
Expand All @@ -45,8 +46,8 @@
Class {
#name : 'FamixPythonPackage',
#superclass : 'FamixPythonContainerEntity',
#traits : 'FamixTImportable + FamixTPackage + FamixTPackageable + FamixTWithAccesses + FamixTWithComments + FamixTWithFunctions + FamixTWithGlobalVariables + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTImportable classTrait + FamixTPackage classTrait + FamixTPackageable classTrait + FamixTWithAccesses classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithGlobalVariables classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#traits : 'FamixTImportable + FamixTPackage + FamixTPackageable + FamixTReferenceable + FamixTWithAccesses + FamixTWithComments + FamixTWithFunctions + FamixTWithGlobalVariables + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTImportable classTrait + FamixTPackage classTrait + FamixTPackageable classTrait + FamixTReferenceable classTrait + FamixTWithAccesses classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithGlobalVariables classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Incoming dependencies
| Relation | Origin | Opposite | Type | Comment |
|---|
| `incomingReferences` | `FamixTReferenceable` | `referredType` | `FamixTReference` | References to this entity by other entities.|
| `incomingReferences` | `FamixTReferenceable` | `referredEntity` | `FamixTReference` | References to this entity by other entities.|
### Other
| Relation | Origin | Opposite | Type | Comment |
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Python-Entities/FamixPythonReference.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Association target
| Relation | Origin | Opposite | Type | Comment |
|---|
| `referredType` | `FamixTReference` | `incomingReferences` | `FamixTReferenceable` | Target entity referenced. to-side of the association|
| `referredEntity` | `FamixTReference` | `incomingReferences` | `FamixTReferenceable` | Target entity referenced. to-side of the association|
### Other
| Relation | Origin | Opposite | Type | Comment |
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Python-Entities/FamixPythonType.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Incoming dependencies
| Relation | Origin | Opposite | Type | Comment |
|---|
| `incomingReferences` | `FamixTReferenceable` | `referredType` | `FamixTReference` | References to this entity by other entities.|
| `incomingReferences` | `FamixTReferenceable` | `referredEntity` | `FamixTReference` | References to this entity by other entities.|
### Other
| Relation | Origin | Opposite | Type | Comment |
Expand Down
1 change: 1 addition & 0 deletions src/Famix-Python-Generator/FamixPythonGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ FamixPythonGenerator >> defineHierarchy [
package --|> #TWithLambdas.
package --|> #TWithAccesses.
package --|> #TWithReferences.
package --|> #TReferenceable.

parameter --|> namedEntity.
parameter --|> #TParameter.
Expand Down
149 changes: 146 additions & 3 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ FamixPythonProject1Test >> testAllSourcedEntitiesNotSubHaveSourceAnchor [

(self model allUsing: FamixTSourceEntity)
reject: [ :entity | entity isStub or: [ entity isInheritance and: [ entity target name = 'object' ] ] ]
thenDo: [ :entity |
self assert: entity sourceAnchor isNotNil.
self denyEmpty: entity sourceText ]
thenDo: [ :entity | self assert: entity sourceAnchor isNotNil ]
]

{ #category : 'tests' }
Expand Down Expand Up @@ -2315,6 +2313,151 @@ FamixPythonProject1Test >> testPackageImportsSubSubPackage [
self assert: import sourceText equals: 'import root.subpackage1.subsubpackage1'
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromClass [

| package class reference |
package := self packageNamed: 'packagesToReference3'.
class := self classNamed: 'ClassReferencingAPackage'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = class ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: class.
self assert: reference referencer equals: class.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (class outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromFunction [

| package function reference |
package := self packageNamed: 'packagesToReference5'.
function := self functionNamed: 'function_referencing_package'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = function ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: function.
self assert: reference referencer equals: function.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (function outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromImportedEntityWithAlias [

| package class reference |
package := self packageNamed: 'packagesToReference7'.
class := self moduleNamed: 'modulesReferencingThings'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = class ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: class.
self assert: reference referencer equals: class.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (class outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromImportedEntityWithAliasSourceAnchor [

| package class reference |
package := self packageNamed: 'packagesToReference7'.
class := self moduleNamed: 'modulesReferencingThings'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = class ].

self assert: reference sourceAnchor isNotNil.
self assert: reference sourceText equals: 'package'
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromLambda [

| package lambda reference |
package := self packageNamed: 'packagesToReference6'.
lambda := (self functionNamed: 'function_with_lambda_with_package_ref') lambdas anyOne.

reference := package incomingReferences detect: [ :aReference | aReference referencer = lambda ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: lambda.
self assert: reference referencer equals: lambda.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (lambda outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromMethod [

| package method reference |
package := self packageNamed: 'packagesToReference4'.
method := self methodNamed: 'method_referencing_package'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = method ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: method.
self assert: reference referencer equals: method.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (method outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromModule [

| package module reference |
package := self packageNamed: 'packagesToReference2'.
module := self moduleNamed: 'modulesReferencingThings'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = module ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: module.
self assert: reference referencer equals: module.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (module outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceFromPackage [

| package package2 reference |
package := self packageNamed: 'packagesToReference1'.
package2 := self packageNamed: 'subsubpackage1'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = package2 ].

self assert: reference class equals: FamixPythonReference.
self assert: reference source equals: package2.
self assert: reference referencer equals: package2.
self assert: reference target equals: package.
self assert: reference referredEntity equals: package.
self assert: (package2 outgoingReferences anySatisfy: [ :aReference | aReference referredEntity = package ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testPackageReferenceSourceAnchor [

| package class reference |
package := self packageNamed: 'packagesToReference3'.
class := self classNamed: 'ClassReferencingAPackage'.

reference := package incomingReferences detect: [ :aReference | aReference referencer = class ].

self assert: reference sourceAnchor isNotNil.
self assert: reference sourceText equals: 'packagesToReference.packagesToReference3'
]

{ #category : 'tests - packages' }
FamixPythonProject1Test >> testPackageSourceAnchor [

Expand Down

0 comments on commit 3638a9d

Please sign in to comment.