override fun createCourse()

in intellij-plugin/Edu-Python/testSrc/com/jetbrains/edu/python/slow/checker/PyNewCheckErrorsTest.kt [24:145]


  override fun createCourse(): Course {
    val test = """
      |import unittest
      |from task import sum
      |class TestCase(unittest.TestCase):
      |    def test_add(self):
      |        self.assertEqual(sum(1, 2), 3, msg="error")
      |""".trimMargin()

    return course(language = PythonLanguage.INSTANCE, environment = "unittest") {
      lesson {
        eduTask("EduTestsFailed") {
          pythonTaskFile("task.py", """
            def sum(a, b):
                return a + b + 1
            """)
          dir("tests") {
            taskFile("__init__.py")
            taskFile("tests.py", test)
          }
        }
        eduTask("EduNoTestsRun") {
          pythonTaskFile("task.py", """
            def sum(a, b):
                return a + b
            """)
          dir("tests") {
            taskFile("__init__.py")
            taskFile("tests.py")
          }
        }
        eduTask("SyntaxError") {
          pythonTaskFile("task.py", """
            def sum(a, b):
                return a + b hello goodbye
            """)
          dir("tests") {
            taskFile("__init__.py")
            taskFile("tests.py", test)
          }
        }
        eduTask("AssertionError") {
          pythonTaskFile("task.py")
          dir("tests") {
            taskFile("__init__.py")
            taskFile("tests.py", """
              |import unittest
              |class TestCase(unittest.TestCase):
              |    def test_add(self):
              |        self.assertTrue(False, "My own message")
              |""".trimMargin())
          }
        }
        eduTask("DoNotEscapeMessageInFailedTest") {
          pythonTaskFile("task.py")
          dir("tests") {
            taskFile("__init__.py")
            taskFile("tests.py", """
              |import unittest
              |class TestCase(unittest.TestCase):
              |    def test_add(self):
              |        self.assertTrue(False, "<br>")
              |""".trimMargin())
          }
        }
        eduTask("CustomRunConfiguration") {
          pythonTaskFile("task.py", """
            import os


            def hello():
                return os.getenv("EXAMPLE_ENV")
            """)
          dir("tests") {
            taskFile("__init__.py")
            taskFile("tests.py", """
              import unittest

              from task import hello


              class TestCase(unittest.TestCase):
                  def test_hello(self):
                      self.assertEqual(hello(), "Hello", msg="Error message")
              """)
          }
          dir("runConfigurations") {
            xmlTaskFile("CustomCheck.run.xml", $$"""
              <component name="ProjectRunConfigurationManager">
                <configuration name="CustomCheck" type="tests" factoryName="Unittests">
                  <module name="Python Course14" />
                  <option name="INTERPRETER_OPTIONS" value="" />
                  <option name="PARENT_ENVS" value="true" />
                  <envs>
                    <env name="EXAMPLE_ENV" value="Hello!" />
                  </envs>
                  <option name="SDK_HOME" value="$PROJECT_DIR$/.idea/VirtualEnvironment/bin/python" />
                  <option name="WORKING_DIRECTORY" value="$TASK_DIR$" />
                  <option name="IS_MODULE_SDK" value="true" />
                  <option name="ADD_CONTENT_ROOTS" value="true" />
                  <option name="ADD_SOURCE_ROOTS" value="true" />
                  <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
                  <option name="_new_pattern" value="&quot;&quot;" />
                  <option name="_new_additionalArguments" value="&quot;&quot;" />
                  <option name="_new_target" value="&quot;tests.TestCase&quot;" />
                  <option name="_new_targetType" value="&quot;PYTHON&quot;" />
                  <method v="2" />
                </configuration>
              </component>
            """)
          }
        }

        outputTask("OutputTestsFailed") {
          pythonTaskFile("hello_world.py", """print("Hello, World")""")
          taskFile("output.txt") {
            withText("Hello, World!\n")
          }
        }
      }
    }
  }