Fix EDU-550 Educational projects and console input.
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Fri, 5 Aug 2016 12:17:47 +0000 (15:17 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Fri, 5 Aug 2016 14:58:26 +0000 (17:58 +0300)
python/educational-python/resources/fileTemplates/internal/test_helper.py.ft
python/educational-python/student-python/resources/courses/Introduction to Python.zip

index c858ac375be06c15c946406d291fdc5e418d3667..691cfe595628c81b8b47a277023e7341fc20538e 100644 (file)
@@ -48,14 +48,45 @@ def check_importable_path(path):
     """ Checks that file is importable.
         Reports failure otherwise.
     """
+    saved_input = patch_input()
     try:
         import_file(path)
     except:
         failed("The file contains syntax errors", test_file_importable.__name__)
         return
+    finally:
+        revert_input(saved_input)
+
     passed(test_file_importable.__name__)
 
 
+def patch_input():
+    def mock_fun(_m=""):
+        return "mock"
+
+    if sys.version_info[0] == 3:
+        import builtins
+        save_input = builtins.input
+        builtins.input = mock_fun
+        return save_input
+    elif sys.version_info[0] == 2 or sys.version_info[1] < 3:
+        import __builtin__
+        save_input = __builtin__.raw_input
+        __builtin__.raw_input = mock_fun
+        __builtin__.input = mock_fun
+        return save_input
+
+
+def revert_input(saved_input):
+    if sys.version_info[0] == 3:
+        import builtins
+        builtins.input = saved_input
+    elif sys.version_info[0] == 2 or sys.version_info[1] < 3:
+        import __builtin__
+        __builtins__.raw_input = saved_input
+        __builtin__.input = saved_input
+
+
 def import_file(path):
     """ Returns imported file """
     if sys.version_info[0] == 2 or sys.version_info[1] < 3:
index 5504b822eef8a302cf86e7a9c80806a6b8253292..87469d547aa057cacde4d0146bffdcfd2d0f62f8 100644 (file)
Binary files a/python/educational-python/student-python/resources/courses/Introduction to Python.zip and b/python/educational-python/student-python/resources/courses/Introduction to Python.zip differ