def test_all(self): self.converter = Converter(self.test_cpp_source_path) self.converter.convert() self.maxDiff = None with open(self.test_py_source_path) as file: self.assertEqual(self.converter.python_source.as_text, file.read())
class TestConverter(unittest.TestCase): working_directory = os.path.dirname(os.path.abspath(__file__)) test_cpp_source_path = working_directory + "/source_converter.cms.txt" test_py_source_path = working_directory + "/source_converter.py.txt" def test_all(self): self.converter = Converter(self.test_cpp_source_path) self.converter.convert() self.maxDiff = None with open(self.test_py_source_path) as file: self.assertEqual(self.converter.python_source.as_text, file.read())
def convert_file(full_file_name: str) -> str: if not '.cpp' in full_file_name: return "Wrong file type: [{}].".format(full_file_name) if not os.path.isfile(full_file_name): return "File doesn't exist: [{}].".format(full_file_name) converter = Converter(full_file_name) converter.convert() with open(full_file_name + ".py", "w") as file: file.write(converter.get_python_source()) return ""
from threading import RLock from flask import Flask, request, send_file from tempfile import mkstemp from werkzeug.wsgi import ClosingIterator from werkzeug.exceptions import HTTPException from pantomime import FileName, normalize_mimetype, mimetype_extension from convert.converter import Converter, ConversionFailure from convert.formats import load_mime_extensions from .document_types import * logging.basicConfig(level=logging.DEBUG) log = logging.getLogger('convert') lock = RLock() extensions = load_mime_extensions() converter = Converter() class ShutdownMiddleware: def __init__(self, application): self.application = application def post_request(self): if app.is_dead: os._exit(127) def __call__(self, environ, after_response): iterator = self.application(environ, after_response) try: return ClosingIterator(iterator, [self.post_request]) except Exception: