Exemplo n.º 1
0
    def exec_and_capture_output(self, test_name=None, expected_exception=None):
        self.sub_test_counter += 1
        if test_name is None:
            test_name = self.which_test
        test_name = f"{self.sub_test_counter}_{test_name}"

        self.python_batch_file_path = os.fspath(self.path_inside_test_folder(test_name+".py"))
        config_vars["__MAIN_OUT_FILE__"] = self.python_batch_file_path
        config_vars["__MAIN_COMMAND__"] = f"{self.which_test} test #{self.sub_test_counter};"
        bc_repr = repr(self.batch_accum)
        with open(self.python_batch_file_path, "w", encoding='utf-8', errors='replace') as wfd:
            wfd.write(bc_repr)
        bc_compiled = compile(bc_repr, self.python_batch_file_path, 'exec')
        output_file_name = self.path_inside_test_folder(f'{test_name}_output.txt')
        if output_file_name != self.output_file_name:
            if self.output_file_name:
                utils.teardown_file_logging(self.output_file_name)
            self.output_file_name = output_file_name
            utils.setup_file_logging(self.output_file_name, level=logging.INFO)

        if not expected_exception:
            try:
                ops = exec(bc_compiled, globals(), locals())
            except SyntaxError:
                log.error(f"> > > > SyntaxError in {test_name}")
                raise
        else:
            with self.uni_test_obj.assertRaises(expected_exception):
                ops = exec(bc_compiled, globals(), locals())
Exemplo n.º 2
0
 def tearDown(self):
     if self.output_file_name:
         utils.teardown_file_logging(self.output_file_name)