def test_all(quiet=False, generate_output=False, stop_on_failure=False, start_at=0): if not quiet: print "Testing %s" % get_version_string(False) try: index = 0 count = failed = skipped = 0 failed_symbols = set() output_xml = {} output_tex = {} for tests in documentation.get_tests(): sub_count, sub_failed, sub_skipped, symbols, index = test_tests( tests, index, quiet=quiet, stop_on_failure=stop_on_failure, start_at=start_at) if generate_output: create_output(tests, output_xml, output_tex) count += sub_count failed += sub_failed skipped += sub_skipped failed_symbols.update(symbols) if sub_failed and stop_on_failure: break builtin_count = len(builtins) except KeyboardInterrupt: print "\nAborted.\n" return if failed > 0: print '%s' % sep print "%d Tests for %d built-in symbols, %d passed, %d failed, %d skipped." % ( count, builtin_count, count - failed - skipped, failed, skipped) if failed_symbols: if stop_on_failure: print "(not all tests are accounted for due to --stop-on-failure)" print "Failed:" for part, chapter, section in sorted(failed_symbols): print ' - %s in %s / %s' % (section, part, chapter) if failed == 0: print '\nOK' if generate_output: print 'Save XML' with open_ensure_dir(settings.DOC_XML_DATA, 'w') as output_file: pickle.dump(output_xml, output_file, 0) print 'Save TEX' with open_ensure_dir(settings.DOC_TEX_DATA, 'w') as output_file: pickle.dump(output_tex, output_file, 0) else: print '\nFAILED' return sys.exit(1) # Travis-CI knows the tests have failed
def test_all(quiet=False): if not quiet: print "Testing %s" % get_version_string(False) try: index = 0 count = failed = 0 failed_symbols = set() output_xml = {} output_tex = {} for tests in documentation.get_tests(): sub_count, sub_failed, symbols, index = test_tests(tests, index, quiet=quiet) create_output(tests, output_xml, output_tex) count += sub_count failed += sub_failed failed_symbols.update(symbols) builtin_count = len(builtins) except KeyboardInterrupt: print "\nAborted.\n" return if failed > 0: print "%s" % sep print "%d Tests for %d built-in symbols, %d passed, %d failed." % (count, builtin_count, count - failed, failed) if failed_symbols: print "Failed:" for part, chapter, section in sorted(failed_symbols): print " - %s in %s / %s" % (section, part, chapter) if failed == 0: print "\nOK" print "Save XML" with open_ensure_dir(settings.DOC_XML_DATA, "w") as output_xml_file: pickle.dump(output_xml, output_xml_file, 0) print "Save TEX" with open_ensure_dir(settings.DOC_TEX_DATA, "w") as output_tex_file: pickle.dump(output_tex, output_tex_file, 0) else: print "\nFAILED" return sys.exit(1) # Travis-CI knows the tests have failed
def main(): argparser = argparse.ArgumentParser( prog='mathics', usage='%(prog)s [options] [FILE]', add_help=False, description="Mathics is a general-purpose computer algebra system.", epilog="""Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""") argparser.add_argument('FILE', nargs='?', type=argparse.FileType('r'), help='execute commands from FILE') argparser.add_argument('--help', '-h', help='show this help message and exit', action='help') argparser.add_argument( '--persist', help='go to interactive shell after evaluating FILE', action='store_true') argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true') argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true') argparser.add_argument('--execute', '-e', nargs='?', help='execute a command') argparser.add_argument('--colors', nargs='?', help='interactive shell colors') argparser.add_argument('--version', '-v', action='version', version=get_version_string(False)) args = argparser.parse_args() quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D' definitions = Definitions(add_builtin=True) definitions.set_ownvalue('$Line', Integer(1)) #Reset the line number to 1 shell = TerminalShell(definitions, args.colors) if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing {0}\n".format(quit_command) if args.execute: total_input = args.execute.decode(sys.stdin.encoding) # check encoding print shell.get_in_prompt() + total_input shell.evaluate(total_input) return if args.FILE is not None: total_input = '' for line_no, line in enumerate(args.FILE): try: line = line.decode('utf-8') # TODO: other encodings if args.script and line_no == 0 and line.startswith('#!'): continue print shell.get_in_prompt( continued=(total_input != '')) + line, total_input += ' ' + line if line != "" and wait_for_line(total_input): continue shell.evaluate(total_input) total_input = "" except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break if not args.persist: return total_input = "" while True: try: line = raw_input(shell.get_in_prompt(continued=total_input != '')) line = line.decode(sys.stdin.encoding) total_input += line if line != "" and wait_for_line(total_input): continue shell.evaluate(total_input) total_input = "" except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break
def main(): argparser = argparse.ArgumentParser( prog='mathics', usage='%(prog)s [options] [FILE]', add_help=False, description = "Mathics is a general-purpose computer algebra system.", epilog = """Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""") argparser.add_argument('FILE', nargs='?', type=argparse.FileType('r'), help='execute commands from FILE') argparser.add_argument('--help', '-h', help='show this help message and exit', action='help') argparser.add_argument('--persist', help='go to interactive shell after evaluating FILE', action='store_true') argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true') argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true') argparser.add_argument('--version', '-v', action='version', version=get_version_string(False)) args = argparser.parse_args() quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D' if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing %s" % quit_command print '' definitions = Definitions(add_builtin=True) trailing_ops = ['+', '-', '/', '*'] # TODO all binary operators? if args.FILE is not None: total_input = "" for line in args.FILE: if args.script and line.startswith('#!'): continue if total_input == "": print '>> ', line, else: print ' ', line, total_input += line if line == "": pass elif any(line.rstrip().endswith(op) for op in trailing_ops) or not brackets_balanced(total_input): continue evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print ' = %s' % to_output(unicode(result.result)) total_input = "" if not args.persist: return while True: try: total_input = "" line_input = raw_input('>> ') while line_input != "": total_input += ' ' + line_input if any([line_input.rstrip().endswith(op) for op in trailing_ops]): pass elif brackets_balanced(total_input): break line_input = raw_input(' ') evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print ' = %s' % to_output(unicode(result.result)) except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break
def main(): argparser = argparse.ArgumentParser( prog="mathics", usage="%(prog)s [options] [FILE]", add_help=False, description="Mathics is a general-purpose computer algebra system.", epilog="""Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""", ) argparser.add_argument("FILE", nargs="?", type=argparse.FileType("r"), help="execute commands from FILE") argparser.add_argument("--help", "-h", help="show this help message and exit", action="help") argparser.add_argument("--persist", help="go to interactive shell after evaluating FILE", action="store_true") argparser.add_argument("--quiet", "-q", help="don't print message at startup", action="store_true") argparser.add_argument("-script", help="run a mathics file in script mode", action="store_true") argparser.add_argument("--execute", "-e", nargs="?", help="execute a command") argparser.add_argument("--version", "-v", action="version", version=get_version_string(False)) args = argparser.parse_args() quit_command = "CTRL-BREAK" if sys.platform == "win32" else "CONTROL-D" definitions = Definitions(add_builtin=True) trailing_ops = ["+", "-", "/", "*"] # TODO all binary operators? if args.execute: print ">> %s" % args.execute evaluation = Evaluation(args.execute, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print " = %s" % to_output(unicode(result.result)) return if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing %s" % quit_command print "" if args.FILE is not None: total_input = "" for line in args.FILE: if args.script and line.startswith("#!"): continue if total_input == "": print ">> ", line, else: print " ", line, total_input += line if line == "": pass elif any(line.rstrip().endswith(op) for op in trailing_ops) or not brackets_balanced(total_input): continue evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print " = %s" % to_output(unicode(result.result)) total_input = "" if not args.persist: return while True: try: total_input = "" line_input = raw_input(">> ") while line_input != "": total_input += " " + line_input if any([line_input.rstrip().endswith(op) for op in trailing_ops]): pass elif brackets_balanced(total_input): break line_input = raw_input(" ") evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print " = %s" % to_output(unicode(result.result)) except (KeyboardInterrupt): print "\nKeyboardInterrupt" except (SystemExit, EOFError): print "\n\nGood bye!\n" break
def evaluate(self, evaluation): return String(get_version_string(True))
def main(): argparser = argparse.ArgumentParser( prog='mathics', usage='%(prog)s [options] [FILE]', add_help=False, description="Mathics is a general-purpose computer algebra system.", epilog="""Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""") argparser.add_argument('FILE', nargs='?', type=argparse.FileType('r'), help='execute commands from FILE') argparser.add_argument('--help', '-h', help='show this help message and exit', action='help') argparser.add_argument( '--persist', help='go to interactive shell after evaluating FILE', action='store_true') argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true') argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true') argparser.add_argument('--version', '-v', action='version', version=get_version_string(False)) args = argparser.parse_args() quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D' if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing %s" % quit_command print '' definitions = Definitions(add_builtin=True) trailing_ops = ['+', '-', '/', '*'] # TODO all binary operators? if args.FILE is not None: total_input = "" for line in args.FILE: if args.script and line.startswith('#!'): continue if total_input == "": print '>> ', line, else: print ' ', line, total_input += line if line == "": pass elif any(line.rstrip().endswith(op) for op in trailing_ops) or not brackets_balanced(total_input): continue evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print ' = %s' % to_output(unicode(result.result)) total_input = "" if not args.persist: return while True: try: total_input = "" line_input = raw_input('>> ') while line_input != "": total_input += ' ' + line_input if any( [line_input.rstrip().endswith(op) for op in trailing_ops]): pass elif brackets_balanced(total_input): break line_input = raw_input(' ') evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print ' = %s' % to_output(unicode(result.result)) except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break
def main(): argparser = argparse.ArgumentParser( prog='mathics', usage='%(prog)s [options] [FILE]', add_help=False, description="Mathics is a general-purpose computer algebra system.", epilog="""Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""") argparser.add_argument( 'FILE', nargs='?', type=argparse.FileType('r'), help='execute commands from FILE') argparser.add_argument( '--help', '-h', help='show this help message and exit', action='help') argparser.add_argument( '--persist', help='go to interactive shell after evaluating FILE', action='store_true') argparser.add_argument( '--quiet', '-q', help='don\'t print message at startup', action='store_true') argparser.add_argument( '-script', help='run a mathics file in script mode', action='store_true') argparser.add_argument( '--execute', '-e', nargs='?', help='execute a command') argparser.add_argument( '--colors', nargs='?', help='interactive shell colors') argparser.add_argument( '--version', '-v', action='version', version=get_version_string(False)) args = argparser.parse_args() quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D' definitions = Definitions(add_builtin=True) definitions.set_ownvalue('$Line', Integer(0)) # Reset the line number shell = TerminalShell(definitions, args.colors) if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing {0}\n".format(quit_command) if args.execute: total_input = args.execute.decode(shell.input_encoding) print shell.get_in_prompt() + total_input shell.evaluate(total_input) return if args.FILE is not None: total_input = '' for line_no, line in enumerate(args.FILE): try: line = line.decode('utf-8') # TODO: other encodings if args.script and line_no == 0 and line.startswith('#!'): continue print shell.get_in_prompt(continued=total_input != '') + line, total_input += ' ' + line if line != "" and wait_for_line(total_input): continue shell.evaluate(total_input) total_input = "" except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break if not args.persist: return total_input = "" while True: try: line = shell.read_line( shell.get_in_prompt(continued=total_input != '')) line = line.decode(shell.input_encoding) total_input += line if line != "" and wait_for_line(total_input): continue shell.evaluate(total_input) total_input = "" except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break
def main(): argparser = argparse.ArgumentParser( prog='mathics', usage='%(prog)s [options] [FILE]', add_help=False, description = "Mathics is a general-purpose computer algebra system.", epilog = """Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""") argparser.add_argument('FILE', nargs='?', type=argparse.FileType('r'), help='execute commands from FILE') argparser.add_argument('--help', '-h', help='show this help message and exit', action='help') argparser.add_argument('--persist', help='go to interactive shell after evaluating FILE', action='store_true') argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true') argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true') argparser.add_argument('--execute', '-e', nargs='?', help='execute a command') argparser.add_argument('--colors', nargs='?', help='interactive shell colors') argparser.add_argument('--version', '-v', action='version', version=get_version_string(False)) args = argparser.parse_args() quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D' definitions = Definitions(add_builtin=True) # TODO all binary operators? #Reset the line number to 1 definitions.set_ownvalue('$Line', Integer(1)) shell = TerminalShell(definitions, args.colors) if args.execute: total_input = args.execute.decode(sys.stdin.encoding) # check encoding print shell.get_in_prompt() + total_input evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print shell.get_out_prompt() + to_output(unicode(result.result)) + '\n' return if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing %s" % quit_command print '' if args.FILE is not None: total_input = "" for line in args.FILE: line = line.decode('utf-8') # TODO: other encodings if args.script and line.startswith('#!'): continue if total_input == "": print shell.get_in_prompt() + line, else: print ' ', line, total_input += line if line == "": pass elif wait_for_line(total_input): continue evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print shell.get_out_prompt() + to_output(unicode(result.result)) + '\n' total_input = "" if not args.persist: return while True: try: total_input = "" line_input = raw_input(shell.get_in_prompt()) line_input = line_input.decode(sys.stdin.encoding) while line_input != "": total_input += ' ' + line_input if not wait_for_line(total_input): break line_input = raw_input(' ') line_input = line_input.decode(sys.stdin.encoding) evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print shell.get_out_prompt() + to_output(unicode(result.result)) + '\n' except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break
def main(): argparser = argparse.ArgumentParser( prog='mathics', usage='%(prog)s [options] [FILE]', add_help=False, description="Mathics is a general-purpose computer algebra system.", epilog="""Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.""") argparser.add_argument('FILE', nargs='?', type=argparse.FileType('r'), help='execute commands from FILE') argparser.add_argument('--help', '-h', help='show this help message and exit', action='help') argparser.add_argument( '--persist', help='go to interactive shell after evaluating FILE', action='store_true') argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true') argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true') argparser.add_argument('--execute', '-e', nargs='?', help='execute a command') argparser.add_argument('--colors', nargs='?', help='interactive shell colors') argparser.add_argument('--version', '-v', action='version', version=get_version_string(False)) args = argparser.parse_args() quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D' definitions = Definitions(add_builtin=True) # TODO all binary operators? #Reset the line number to 1 definitions.set_ownvalue('$Line', Integer(1)) shell = TerminalShell(definitions, args.colors) if args.execute: print get_in_prompt() + args.execute evaluation = Evaluation(args.execute, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print shell.get_out_prompt() + to_output(unicode( result.result)) + '\n' return if not (args.quiet or args.script): print_version(is_server=False) print_license() print u"Quit by pressing %s" % quit_command print '' if args.FILE is not None: total_input = "" for line in args.FILE: if args.script and line.startswith('#!'): continue if total_input == "": print shell.get_in_prompt() + line, else: print ' ', line, total_input += line if line == "": pass elif wait_for_line(total_input): continue evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print shell.get_out_prompt() + to_output( unicode(result.result)) + '\n' total_input = "" if not args.persist: return while True: try: total_input = "" line_input = raw_input(shell.get_in_prompt()) while line_input != "": total_input += ' ' + line_input if not wait_for_line(total_input): break line_input = raw_input(' ') evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback) for result in evaluation.results: if result.result is not None: print shell.get_out_prompt() + to_output( unicode(result.result)) + '\n' except (KeyboardInterrupt): print '\nKeyboardInterrupt' except (SystemExit, EOFError): print "\n\nGood bye!\n" break