示例#1
0
 def test_python_launcher_missing_script(self):
     # test here that error handling works: script NOT available!
     from interface_scripts.launchers import py_launcher
     L = py_launcher(execute_as_shell=False)
     project_info = {}
     with self.assertRaises(ValueError):
         L.execute('nothing.py', project_info, 0, False)
示例#2
0
    def test_python_launcher_exectue_shell(self):
        # execute launcher in SHELL and check if output files existing
        from interface_scripts.launchers import py_launcher

        # generate some dummy python script that should be executed
        # this script will just save some file
        testoutput = self.tmpdir + 'test_result_shell.json'

        script = self.tmpdir + 'testscript.py'
        o = open(script, 'w')
        o.write('import json\n')
        o.write("d = {'A':1,'B':2}\n")
        o.write("json.dump(d, open('" + testoutput + "', 'w'))\n")
        o.close()

        L = py_launcher(execute_as_shell=True)
        project_info = {}
        L.execute(script, project_info, 0, False)
        self.assertTrue(os.path.exists(testoutput))
示例#3
0
    def test_python_launcher_execute_script_with_errors(self):
        # execute launcher in SCRIPT and check if output files existing
        from interface_scripts.launchers import py_launcher
        sys.path.append(self.tmpdir)

        # generate some dummy python script that should be executed
        # this script will just save some file

        script = self.tmpdir + 'testscript_script_fail.py'
        o = open(script, 'w')
        o.write('import json\n')
        o.write('def main(project_info):\n')
        o.write(
            "  here we introduce some syntax error this script should then fail"
        )
        o.close()

        L = py_launcher(execute_as_shell=False)
        project_info = {}
        with self.assertRaises(ValueError):
            L.execute(script, project_info, 0, False)
示例#4
0
 def test_python_launcher_init(self):
     from interface_scripts.launchers import py_launcher
     L = py_launcher()
     self.assertFalse(L.execute_as_shell)
     self.assertEqual(L.lang, 'PY ')