Skip to content

Commit

Permalink
Add more tests on references + fix a bug of a class referencing a class
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 5, 2024
1 parent e109e79 commit 26eac88
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Famix-Python-Entities/FamixPythonClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| Relation | Origin | Opposite | Type | Comment |
|---|
| `accesses` | `FamixTWithAccesses` | `accessor` | `FamixTAccess` | Accesses to variables made by this behaviour.|
| `outgoingReferences` | `FamixTWithReferences` | `referencer` | `FamixTReference` | References from this entity to other entities.|
| `superInheritances` | `FamixTWithInheritances` | `subclass` | `FamixTInheritance` | Superinheritance relationships, i.e. known superclasses of this type.|
### Incoming dependencies
Expand Down Expand Up @@ -54,8 +55,8 @@
Class {
#name : 'FamixPythonClass',
#superclass : 'FamixPythonType',
#traits : 'FamixTClass + FamixTImportable + FamixTShadowable + FamixTShadower + FamixTWithAccesses + FamixTWithAnnotationInstances + FamixTWithLambdas',
#classTraits : 'FamixTClass classTrait + FamixTImportable classTrait + FamixTShadowable classTrait + FamixTShadower classTrait + FamixTWithAccesses classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithLambdas classTrait',
#traits : 'FamixTClass + FamixTImportable + FamixTShadowable + FamixTShadower + FamixTWithAccesses + FamixTWithAnnotationInstances + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTClass classTrait + FamixTImportable classTrait + FamixTShadowable classTrait + FamixTShadower classTrait + FamixTWithAccesses classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#instVars : [
'#instancedClasses => FMMany type: #FamixPythonClass opposite: #metaclass',
'#isMetaclass => FMProperty',
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 @@ -93,6 +93,7 @@ FamixPythonGenerator >> defineHierarchy [
class --|> #TShadowable.
class --|> #TShadower.
class --|> #TWithAccesses.
class --|> #TWithReferences.

containerEntity --|> namedEntity.
containerEntity --|> #TWithClasses.
Expand Down
81 changes: 81 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,74 @@ FamixPythonProject1Test >> testReadAccessToParameter [
self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = parameter ])
]

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

| class class2 reference |
class := self classNamed: 'AClassToReference'.
class2 := self classNamed: 'AClassReferencingAClass'.

reference := (class incomingReferences select: [ :aReference | aReference referencer = class2 ]) detectMax: [ :aReference | aReference sourceAnchor startPos ].

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

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

| class function reference |
class := self classNamed: 'AClassToReference'.
function := self functionNamed: 'function_referencing_class'.

reference := (class incomingReferences select: [ :aReference | aReference referencer = function ]) detectMax: [ :aReference | aReference sourceAnchor startPos ].

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

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

| class lambda reference |
class := self classNamed: 'AClassToReference'.
lambda := (self functionNamed: 'function_with_lambda_referencing_class') lambdas anyOne.

reference := (class incomingReferences select: [ :aReference | aReference referencer = lambda ]) detectMax: [ :aReference | aReference sourceAnchor startPos ].

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

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

| class method reference |
class := self classNamed: 'AClassToReference'.
method := self methodNamed: 'method_referencing_class'.

reference := (class incomingReferences select: [ :aReference | aReference referencer = method ]) detectMax: [ :aReference | aReference sourceAnchor startPos ].

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

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

Expand Down Expand Up @@ -2227,6 +2295,19 @@ FamixPythonProject1Test >> testReferenceFromPackage [
self assert: (package outgoingReferences anySatisfy: [ :aReference | aReference referredType = class ])
]

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

| class package reference |
class := self classNamed: 'Room'.
package := self packageNamed: 'subsubpackage1'.

reference := (class incomingReferences select: [ :aReference | aReference referencer = package ]) detectMax: [ :aReference | aReference sourceAnchor startPos ].

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

{ #category : 'tests - modules' }
FamixPythonProject1Test >> testRootModule [

Expand Down

0 comments on commit 26eac88

Please sign in to comment.