Skip to content

Commit

Permalink
Add tests on functions and local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Sep 10, 2024
1 parent 60408cb commit 2e4fb65
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Famix-Python-Entities/FamixPythonEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ FamixPythonEntity >> isMethod [
^ false
]

{ #category : 'testing' }
FamixPythonEntity >> isModule [

<generated>
^ false
]

{ #category : 'testing' }
FamixPythonEntity >> isNamedEntity [

Expand Down
56 changes: 56 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonImporterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ from maths import add, subtract
self assert: (self importNamed: 'add') fromName equals: 'maths'
]

{ #category : 'tests - functions' }
FamixPythonImporterTest >> testInnerFunctions [

| outer inner |
self parseCode: 'def outer_func():
def inner_func():
print("Hello, World!")
inner_func()'.

self assert: self model allFunctions size equals: 2.
outer := self functionNamed: 'outer_func'.
inner := self functionNamed: 'inner_func'.

self assert: inner functionOwner equals: outer.
self assert: outer functionOwner isModule
]

{ #category : 'tests - attributes' }
FamixPythonImporterTest >> testInstanceAttributes [

Expand Down Expand Up @@ -450,6 +467,45 @@ test(x, 25)
self assert: ((invocation cacheAt: 'args' ifAbsent: [ false ]) second at: 'value') equals: '25'
]

{ #category : 'tests - local variables' }
FamixPythonImporterTest >> testLocalVariablesKnowTheirFunction [

| temporary1 temporary2 |
self parseCode: 'def myFirstFunction():
temporary = []
def mySecondFunction():
temporary = 3'.

self assert: (self model allLocalVariables size) equals: 2.
temporary1 := self model allLocalVariables first.
temporary2 := self model allLocalVariables second.

self assert: temporary1 parentBehaviouralEntity name equals: 'myFirstFunction'.
self assert: temporary2 parentBehaviouralEntity name equals: 'mySecondFunction'.
]

{ #category : 'tests - local variables' }
FamixPythonImporterTest >> testLocalVariablesWithSameName [

| function1 function2 |
self parseCode: 'def myFirstFunction():
temporary = []
def mySecondFunction():
temporary = 3'.

self assert: self model allFunctions size equals: 2.
self assert: self model allLocalVariables size equals: 2.
function1 := self functionNamed: 'myFirstFunction'.
function2 := self functionNamed: 'mySecondFunction'.

self assert: function1 localVariables size equals: 1.
self assert: function1 localVariables anyOne name equals: 'temporary'.
self assert: function2 localVariables size equals: 1.
self assert: function2 localVariables anyOne name equals: 'temporary'
]

{ #category : 'tests - lambdas' }
FamixPythonImporterTest >> testMultiFunctionsMultiLambdas [

Expand Down

0 comments on commit 2e4fb65

Please sign in to comment.