Skip to content

Commit

Permalink
feat(python): add PythonContextTest class and related imports
Browse files Browse the repository at this point in the history
This commit adds a new PythonContextTest class to the pycharm/src/test/kotlin directory, along with necessary imports for the test class. It also modifies the gradle.properties file to update the pycharmVersion to PC-2023.2.4.
  • Loading branch information
phodal committed May 8, 2024
1 parent 108fcda commit 358f045
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pluginVersion = 1.8.3-RC

# Supported IDEs: idea, pycharm
baseIDE=idea
pycharmVersion=PC-2022.2.4
pycharmVersion=PC-2023.2.4
golandVersion=GO-2023.3.2
webstormVersion=WS-2022.2.4
riderVersion=RD-2022.2.4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cc.unitmesh.python.context

import cc.unitmesh.devti.context.ClassContext
import cc.unitmesh.devti.context.ClassContextProvider
import com.intellij.psi.PsiFileFactory
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.jetbrains.python.PythonLanguage
import com.jetbrains.python.psi.PyFile

class PythonContextTest : BasePlatformTestCase() {
private val fileFactory: PsiFileFactory get() = PsiFileFactory.getInstance(project)
private val classCode = """class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("John", 36)
print(p1.name)
print(p1.age) """

fun testShould_convert_class_to_string() {
val psiFile = fileFactory.createFileFromText(PythonLanguage.INSTANCE, classCode)
val psiElement = (psiFile as PyFile).topLevelClasses[0]
val classContext: ClassContext = ClassContextProvider(false).from(psiElement)

assertEquals(classContext.format(), """'package: /foo.bar
class Person {
}""");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cc.unitmesh.rust.context

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.extensions.ExtensionPoint
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import org.rust.lang.core.psi.RsEnumItem
Expand Down

0 comments on commit 358f045

Please sign in to comment.