From 50740c5adfa68aa0c58680adc79e3300040e9205 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Mon, 2 Sep 2024 16:06:44 +0200 Subject: [PATCH] Migrate modules tests to new test infra --- .../FamixPythonAbstractImporterTest.class.st | 39 +++++++++++- .../FamixPythonImporterTest.class.st | 60 +------------------ ...amixPythonImporterWithClassesTest.class.st | 48 +++++++++++++-- ...ixPythonImporterWithFunctionsTest.class.st | 12 ---- 4 files changed, 80 insertions(+), 79 deletions(-) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonAbstractImporterTest.class.st b/src/Famix-Python-Importer-Tests/FamixPythonAbstractImporterTest.class.st index 4a9f420..2201205 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonAbstractImporterTest.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonAbstractImporterTest.class.st @@ -1,13 +1,46 @@ Class { #name : 'FamixPythonAbstractImporterTest', #superclass : 'TestCase', - #instVars : [ - 'importer' - ], #category : 'Famix-Python-Importer-Tests', #package : 'Famix-Python-Importer-Tests' } +{ #category : 'accessing' } +FamixPythonAbstractImporterTest >> classNamed: aName [ + + ^ self model allClasses detect: [ :class | class name = aName ] +] + +{ #category : 'accessing' } +FamixPythonAbstractImporterTest >> functionNamed: aName [ + + ^ self model allFunctions detect: [ :function | function name = aName ] +] + +{ #category : 'accessing' } +FamixPythonAbstractImporterTest >> importNamed: aName [ + + ^ self model allImports detect: [ :import | import entityName = aName ] +] + +{ #category : 'accessing' } +FamixPythonAbstractImporterTest >> model [ + self subclassResponsibility +] + +{ #category : 'running' } +FamixPythonAbstractImporterTest >> moduleName [ + ^ 'sprite_collect_blocks' + + +] + +{ #category : 'accessing' } +FamixPythonAbstractImporterTest >> moduleNamed: aName [ + + ^ self model allModules detect: [ :module | module name = aName ] +] + { #category : 'running' } FamixPythonAbstractImporterTest >> setUp [ diff --git a/src/Famix-Python-Importer-Tests/FamixPythonImporterTest.class.st b/src/Famix-Python-Importer-Tests/FamixPythonImporterTest.class.st index ecad9b1..b1697b1 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonImporterTest.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonImporterTest.class.st @@ -6,7 +6,8 @@ Class { 'fileSystem', 'file', 'pyDoc2', - 'file2' + 'file2', + 'importer' ], #category : 'Famix-Python-Importer-Tests', #package : 'Famix-Python-Importer-Tests' @@ -18,13 +19,6 @@ FamixPythonImporterTest >> codeBig1 [ ^ PythonParser parseFileWithErrors: (fileSystem / (self moduleName2 , '.py')) ] -{ #category : 'running' } -FamixPythonImporterTest >> moduleName [ - ^ 'sprite_collect_blocks' - - -] - { #category : 'running' } FamixPythonImporterTest >> moduleName2 [ ^ 'sprite_collect_blocks_2' @@ -570,17 +564,6 @@ FamixPythonImporterTest >> testIsModel [ ] -{ #category : 'tests - module' } -FamixPythonImporterTest >> testKnowsItsModule [ - - | import module | - importer accept: pyDoc. - import := importer importNamed: 'pygame'. - module := importer moduleNamed: self moduleName. - self assert: import manualImportingEntity equals: module. - -] - { #category : 'tests - methods' } FamixPythonImporterTest >> testMethod [ @@ -628,31 +611,6 @@ FamixPythonImporterTest >> testMethodWithParameter [ self assert: param isNotNil ] -{ #category : 'tests - module' } -FamixPythonImporterTest >> testModule [ - - | module | - importer accept: pyDoc. - module := importer moduleNamed: self moduleName. - - self assert: module isNotNil. - self assert: module class equals: FamixPythonModule. - self assert: module name equals: self moduleName. - -] - -{ #category : 'tests - module' } -FamixPythonImporterTest >> testModuleKnowsItsImport [ - - | module | - importer accept: pyDoc. - module := importer moduleNamed: self moduleName. - self assert: module manualIncomingImports size equals: 2. - "does not work probably because of the bidirectional slots - self assert: module incomingImports size equals: 2." - -] - { #category : 'tests - lambdas' } FamixPythonImporterTest >> testMultiFunctionsMultiLambdas [ @@ -840,17 +798,3 @@ class B: assert: (importer model allWithType: FamixPythonClass) size equals: 3 ] - -{ #category : 'tests - module' } -FamixPythonImporterTest >> testTwoSiblingImportsHaveTheSameModule [ - - | import module import2 | - importer accept: pyDoc. - import := importer importNamed: 'pygame'. - import2 := importer importNamed: 'random'. - module := importer moduleNamed: self moduleName. - self assert: import manualImportingEntity equals: module. - self assert: import2 manualImportingEntity equals: module. - self assert: import manualImportingEntity equals: import2 manualImportingEntity - -] diff --git a/src/Famix-Python-Importer-Tests/FamixPythonImporterWithClassesTest.class.st b/src/Famix-Python-Importer-Tests/FamixPythonImporterWithClassesTest.class.st index 4c8054d..73a1102 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonImporterWithClassesTest.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonImporterWithClassesTest.class.st @@ -10,12 +10,6 @@ FamixPythonImporterWithClassesTest class >> resources [ ^ { FamixPythonWithClassesTestResource } ] -{ #category : 'accessing' } -FamixPythonImporterWithClassesTest >> classNamed: aName [ - - ^ self model allClasses detect: [ :class | class name = aName ] -] - { #category : 'accessing' } FamixPythonImporterWithClassesTest >> model [ ^ FamixPythonWithClassesTestResource current model @@ -62,8 +56,50 @@ FamixPythonImporterWithClassesTest >> testClasses [ self assert: (self classNamed: 'Player') isNotNil ] +{ #category : 'tests - module' } +FamixPythonImporterWithClassesTest >> testKnowsItsModule [ + + | import module | + import := self importNamed: 'pygame'. + module := self moduleNamed: self moduleName. + self assert: import manualImportingEntity equals: module +] + +{ #category : 'tests - module' } +FamixPythonImporterWithClassesTest >> testModule [ + + | module | + module := self moduleNamed: self moduleName. + + self assert: module isNotNil. + self assert: module class equals: FamixPythonModule. + self assert: module name equals: self moduleName +] + +{ #category : 'tests - module' } +FamixPythonImporterWithClassesTest >> testModuleKnowsItsImport [ + + | module | + module := self moduleNamed: self moduleName. + self assert: module manualIncomingImports size equals: 2 + "does not work probably because of the bidirectional slots + self assert: module incomingImports size equals: 2." +] + { #category : 'tests - classes' } FamixPythonImporterWithClassesTest >> testRightNumberOfClasses [ self assert: self model numberOfClasses equals: 4 ] + +{ #category : 'tests - module' } +FamixPythonImporterWithClassesTest >> testTwoSiblingImportsHaveTheSameModule [ + + | import module import2 | + import := self importNamed: 'pygame'. + import2 := self importNamed: 'random'. + module := self moduleNamed: self moduleName. + self assert: import manualImportingEntity equals: module. + self assert: import2 manualImportingEntity equals: module. + self assert: import manualImportingEntity equals: import2 manualImportingEntity +] diff --git a/src/Famix-Python-Importer-Tests/FamixPythonImporterWithFunctionsTest.class.st b/src/Famix-Python-Importer-Tests/FamixPythonImporterWithFunctionsTest.class.st index 3c640f7..1b9f6da 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonImporterWithFunctionsTest.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonImporterWithFunctionsTest.class.st @@ -10,23 +10,11 @@ FamixPythonImporterWithFunctionsTest class >> resources [ ^ { FamixPythonWithFunctionsTestResource } ] -{ #category : 'accessing' } -FamixPythonImporterWithFunctionsTest >> functionNamed: aName [ - - ^ self model allFunctions detect: [ :function | function name = aName ] -] - { #category : 'accessing' } FamixPythonImporterWithFunctionsTest >> model [ ^ FamixPythonWithFunctionsTestResource current model ] -{ #category : 'accessing' } -FamixPythonImporterWithFunctionsTest >> moduleNamed: aName [ - - ^ self model allModules detect: [ :module | module name = aName ] -] - { #category : 'tests - functions' } FamixPythonImporterWithFunctionsTest >> testFunction [