From 3638a9d70485146b3758e03d74652dcf4415a5cf Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Fri, 20 Dec 2024 16:52:58 +0100 Subject: [PATCH] Add tests on package references + manage it --- .../FamixPythonClass.class.st | 2 +- .../FamixPythonFunction.class.st | 2 +- .../FamixPythonPackage.class.st | 5 +- .../FamixPythonPrimitiveType.class.st | 2 +- .../FamixPythonReference.class.st | 2 +- .../FamixPythonType.class.st | 2 +- .../FamixPythonGenerator.class.st | 1 + .../FamixPythonProject1Test.class.st | 149 +++++++++++++++++- 8 files changed, 155 insertions(+), 10 deletions(-) diff --git a/src/Famix-Python-Entities/FamixPythonClass.class.st b/src/Famix-Python-Entities/FamixPythonClass.class.st index c543dfe..bf99ff9 100644 --- a/src/Famix-Python-Entities/FamixPythonClass.class.st +++ b/src/Famix-Python-Entities/FamixPythonClass.class.st @@ -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 diff --git a/src/Famix-Python-Entities/FamixPythonFunction.class.st b/src/Famix-Python-Entities/FamixPythonFunction.class.st index 0402ecb..47bae77 100644 --- a/src/Famix-Python-Entities/FamixPythonFunction.class.st +++ b/src/Famix-Python-Entities/FamixPythonFunction.class.st @@ -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 | diff --git a/src/Famix-Python-Entities/FamixPythonPackage.class.st b/src/Famix-Python-Entities/FamixPythonPackage.class.st index 1a06092..f9f1b14 100644 --- a/src/Famix-Python-Entities/FamixPythonPackage.class.st +++ b/src/Famix-Python-Entities/FamixPythonPackage.class.st @@ -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 | @@ -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' diff --git a/src/Famix-Python-Entities/FamixPythonPrimitiveType.class.st b/src/Famix-Python-Entities/FamixPythonPrimitiveType.class.st index 250393a..02f14ad 100644 --- a/src/Famix-Python-Entities/FamixPythonPrimitiveType.class.st +++ b/src/Famix-Python-Entities/FamixPythonPrimitiveType.class.st @@ -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 | diff --git a/src/Famix-Python-Entities/FamixPythonReference.class.st b/src/Famix-Python-Entities/FamixPythonReference.class.st index 2ca33a0..40f5fe4 100644 --- a/src/Famix-Python-Entities/FamixPythonReference.class.st +++ b/src/Famix-Python-Entities/FamixPythonReference.class.st @@ -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 | diff --git a/src/Famix-Python-Entities/FamixPythonType.class.st b/src/Famix-Python-Entities/FamixPythonType.class.st index 9e24b2c..4d0560f 100644 --- a/src/Famix-Python-Entities/FamixPythonType.class.st +++ b/src/Famix-Python-Entities/FamixPythonType.class.st @@ -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 | diff --git a/src/Famix-Python-Generator/FamixPythonGenerator.class.st b/src/Famix-Python-Generator/FamixPythonGenerator.class.st index a9857bb..e1df12b 100644 --- a/src/Famix-Python-Generator/FamixPythonGenerator.class.st +++ b/src/Famix-Python-Generator/FamixPythonGenerator.class.st @@ -183,6 +183,7 @@ FamixPythonGenerator >> defineHierarchy [ package --|> #TWithLambdas. package --|> #TWithAccesses. package --|> #TWithReferences. + package --|> #TReferenceable. parameter --|> namedEntity. parameter --|> #TParameter. diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 0c4d959..81d8619 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -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' } @@ -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 [