EDU-300 Incomplete test for lesson 10/ task 1
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 9 Dec 2014 14:31:41 +0000 (17:31 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 9 Dec 2014 14:31:41 +0000 (17:31 +0300)
python/edu/course-creator/resources/fileTemplates/internal/test_helper.py.ft
python/edu/learn-python/resources/courses/introduction_course.zip

index f9043263bc1aa9ccf34aec582bf8a19d1b241294..49afee982c0ef1c53d96265137ee429f27c5fbe8 100644 (file)
@@ -9,19 +9,17 @@ def get_file_text(path):
     return text
 
 
-def get_file_output():
-    """ Returns answer file output using import system """
-    saved_stdout = sys.stdout
-    try:
-        from StringIO import StringIO
+def get_file_output(encoding="utf-8", path=sys.argv[-1]):
+    """
+    Returns answer file output
+    :param encoding: to decode output in python3
+    :param path: path of file to execute
+    :return: list of strings
+    """
+    import subprocess
 
-        out = StringIO()
-        sys.stdout = out
-        import_task_file()
-        output = out.getvalue().strip()
-        return output
-    finally:
-        sys.stdout = saved_stdout
+    proc = subprocess.Popen([sys.executable, path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    return list(map(lambda x: x.decode(encoding), proc.communicate()[0].splitlines()))
 
 
 def test_file_importable():
@@ -55,6 +53,7 @@ def import_file(path):
     """ Returns imported file """
     if sys.version_info[0] == 2 or sys.version_info[1] < 3:
         import imp
+
         return imp.load_source("tmp", path)
     elif sys.version_info[0] == 3:
         import importlib.machinery
index a17ee9a1151721f5ac5c253915f5134ec5b0e786..45de3580bf6cf8e2293c08de7f3ae0ed873e55bf 100644 (file)
Binary files a/python/edu/learn-python/resources/courses/introduction_course.zip and b/python/edu/learn-python/resources/courses/introduction_course.zip differ