Skip to content

Commit

Permalink
Add a bunch of tests on read accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 4, 2024
1 parent 522531a commit f6591a5
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,44 @@ FamixPythonProject1Test >> testPlaceholderVariablesDoNotCreateStubs [
self assertEmpty: ((self model allUsing: FamixTNamedEntity) select: [ :entity | entity name = '_' ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromFunction [

| temporary function access |
temporary := self localVariableNamed: 'local_in_function3'.
function := self functionNamed: 'function_with_local_variables'.

access := (temporary incomingAccesses select: [ :anAccess | anAccess accessor = function ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].

self assert: access class equals: FamixPythonAccess.
self assert: access source equals: function.
self assert: access accessor equals: function.
self assert: access target equals: temporary.
self assert: access variable equals: temporary.
self deny: access isWrite.
self assert: access isRead.
self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = temporary ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromLambda [

| parameter lambda access |
parameter := self localVariableNamed: 'temporary_in_lambda'.
lambda := lambda := (self functionNamed: 'function_with_lambda_with_temporary') lambdas anyOne.

access := (parameter incomingAccesses select: [ :anAccess | anAccess accessor = lambda ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].

self assert: access class equals: FamixPythonAccess.
self assert: access source equals: lambda.
self assert: access accessor equals: lambda.
self assert: access target equals: parameter.
self assert: access variable equals: parameter.
self deny: access isWrite.
self assert: access isRead.
self assert: (lambda accesses anySatisfy: [ :anAccess | anAccess variable = parameter ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromLambdaToParameter [

Expand All @@ -1883,6 +1921,64 @@ FamixPythonProject1Test >> testReadAccessFromLambdaToParameter [
self assert: (lambda accesses anySatisfy: [ :anAccess | anAccess variable = parameter ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromMethod [

| locale method access |
locale := self localVariableNamed: 'local_in_method2'.
method := self methodNamed: 'method_with_local_variables'.

"We want to have the reading and not the writing."
access := (locale incomingAccesses select: [ :anAccess | anAccess accessor = method ]) detectMax: [ :entity | entity sourceAnchor startPos ].

self assert: access class equals: FamixPythonAccess.
self assert: access source equals: method.
self assert: access accessor equals: method.
self assert: access target equals: locale.
self assert: access variable equals: locale.
self deny: access isWrite.
self assert: access isRead.
self assert: (method accesses anySatisfy: [ :anAccess | anAccess variable = locale ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromModule [

| global module access |
global := self globalVariableNamed: 'moduleAtRootVariable'.
module := self moduleNamed: 'moduleAtRoot'.

access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ] .

self assert: access class equals: FamixPythonAccess.
self assert: access source equals: module.
self assert: access accessor equals: module.
self assert: access target equals: global.
self assert: access variable equals: global.
self deny: access isWrite.
self assert: access isRead.
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromPackage [

| global package access |
global := self globalVariableNamed: 'rootPackageVariable'.
package := self packageNamed: 'root'.

access := (global incomingAccesses select: [ :anAccess | anAccess accessor = package ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ] .

self assert: access class equals: FamixPythonAccess.
self assert: access source equals: package.
self assert: access accessor equals: package.
self assert: access target equals: global.
self assert: access variable equals: global.
self deny: access isWrite.
self assert: access isRead.
self assert: (package accesses anySatisfy: [ :anAccess | anAccess variable = global ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessToCVar [

Expand Down

0 comments on commit f6591a5

Please sign in to comment.