def _get_output(path, language): binstdout = io.BytesIO() [old_stdout, old_argv] = [sys.stdout, sys.argv] try: sys.argv = ['mwic', '--language', language, path] textstdout = sys.stdout = io.TextIOWrapper(binstdout, encoding='utf-8') try: M.main() sys.stdout.flush() return binstdout.getvalue().decode('utf-8') finally: textstdout.close() finally: [sys.stdout, sys.argv] = [old_stdout, old_argv]
def _get_output(path, language): argv = ['mwic', '--language', language, path] binstdout = io.BytesIO() textstdout = io.TextIOWrapper(binstdout, encoding='UTF-8') with unittest.mock.patch.multiple(sys, argv=argv, stdout=textstdout): try: try: M.main() except SystemExit as exc: if exc.code != 0: raise sys.stdout.flush() return binstdout.getvalue().decode('UTF-8') finally: textstdout.close()
from __future__ import unicode_literals import sys from lib.cli import main if __name__ == "__main__": if len(sys.argv) < 2: db = ":memory:" else: db = sys.argv[1] main(db)
# !/usr/bin/env python # -*- encoding: utf-8 -*- # From [email protected] http://www.cdxy.me from lib.cli import main if __name__ == '__main__': main()