[IFT] Split sample for run and for debug lessons

IJ-CR-103403

GitOrigin-RevId: 35f8b09b22771d9ab32bf20db9a7aed1b0443053
This commit is contained in:
Alexey Merkulov
2023-02-17 20:58:37 +01:00
committed by intellij-monorepo-bot
parent deceed0798
commit 9df774fcda
3 changed files with 56 additions and 59 deletions

View File

@@ -4,23 +4,59 @@ package com.jetbrains.python.ift.lesson.run
import com.intellij.icons.AllIcons
import com.intellij.openapi.editor.LogicalPosition
import com.jetbrains.python.ift.PythonLessonsBundle
import training.dsl.LessonContext
import training.dsl.LessonUtil
import training.dsl.TaskTestContext
import training.dsl.highlightButtonById
import training.dsl.*
import training.learn.lesson.general.run.CommonDebugLesson
class PythonDebugLesson : CommonDebugLesson("python.debug.workflow") {
override val configurationName = PythonRunLessonsUtils.demoConfigurationName
override val sample = PythonRunLessonsUtils.demoSample
override val configurationName = "sandbox"
override var logicalPosition: LogicalPosition = LogicalPosition(4, 8)
override val confNameForWatches = "PythonConfigurationType"
override val quickEvaluationArgument = "int"
override val debuggingMethodName = "find_average"
override val methodForStepInto = "extract_number"
override val stepIntoDirectionToRight = false
override val sample = parseLessonSample("""
def find_average(value):
check_input(value)
result = 0
for s in value:
<caret>result += <select id=1>validate_number(extract_number(remove_quotes(s)))</select>
<caret id=3/>return <select id=4>result / len(value)</select>
def prepare_values():
return ["'apple 1'", "orange 2", "'tomato 3'"]
def extract_number(s):
return int(<select id=2>s.split()[0]</select>)
def check_input(value):
if (value is None) or (len(value) == 0):
raise ValueError(value)
def remove_quotes(s):
if len(s) > 1 and s[0] == "'" and s[-1] == "'":
return s[1:-1]
return s
def validate_number(number):
if number < 0:
raise ValueError(number)
return number
average = find_average(prepare_values())
print("The average is ", average)
""".trimIndent())
override val breakpointXRange: (width: Int) -> IntRange = { IntRange(13, it - 17) }
override fun LessonContext.applyProgramChangeTasks() {

View File

@@ -2,15 +2,22 @@
package com.jetbrains.python.ift.lesson.run
import com.jetbrains.python.ift.PythonLessonsBundle
import training.dsl.LessonContext
import training.dsl.LessonSample
import training.dsl.LessonUtil
import training.dsl.checkToolWindowState
import com.jetbrains.python.run.PythonRunConfiguration
import training.dsl.*
import training.learn.lesson.general.run.CommonRunConfigurationLesson
class PythonRunConfigurationLesson : CommonRunConfigurationLesson("python.run.configuration") {
override val sample: LessonSample = PythonRunLessonsUtils.demoSample
override val demoConfigurationName = PythonRunLessonsUtils.demoConfigurationName
override val demoConfigurationName = "sandbox"
override val sample: LessonSample = parseLessonSample("""
import sys
print('It is a run configurations sample')
for s in sys.argv:
print('Passed argument: ', s)
""".trimIndent())
override fun LessonContext.runTask() {
task("RunClass") {

View File

@@ -1,46 +0,0 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.ift.lesson.run
import training.dsl.parseLessonSample
object PythonRunLessonsUtils {
const val demoConfigurationName = "sandbox"
val demoSample = parseLessonSample("""
def find_average(value):
check_input(value)
result = 0
for s in value:
<caret>result += <select id=1>validate_number(extract_number(remove_quotes(s)))</select>
<caret id=3/>return <select id=4>result / len(value)</select>
def prepare_values():
return ["'apple 1'", "orange 2", "'tomato 3'"]
def extract_number(s):
return int(<select id=2>s.split()[0]</select>)
def check_input(value):
if (value is None) or (len(value) == 0):
raise ValueError(value)
def remove_quotes(s):
if len(s) > 1 and s[0] == "'" and s[-1] == "'":
return s[1:-1]
return s
def validate_number(number):
if number < 0:
raise ValueError(number)
return number
average = find_average(prepare_values())
print("The average is ", average)
""".trimIndent())
}