def test(pyth_code, expected_output, input_message=''): output, error = pyth.run_code(pyth_code, input_message) if error: raise NameError("Error thrown by %s on input %s:\n%s" %\ (pyth_code, input_message, error)) if output != expected_output: raise NameError("Bad output by %s on input %s." "\nExpected: %r.\nReceived: %r" %\ (pyth_code, input_message, expected_output, output))
def test(pyth_code, expected_output, input_message=''): output, error = pyth.run_code(pyth_code, input_message) if input_message != '': if error: sys.exit("Error thrown by %s on input %s:\n%s" % (pyth_code, input_message, error)) if output != expected_output and output != expected_output + '\n': sys.exit("Bad output by %s on input %s." "\nExpected: %r.\nReceived: %r" % (pyth_code, input_message, expected_output, output)) else: if error: sys.exit("Error thrown by %s:\n%s" % (pyth_code, error)) if output != expected_output and output != expected_output + '\n': sys.exit("Bad output by %s." "\nExpected: %r.\nReceived: %r" % (pyth_code, expected_output, output))
nargs='?', default='') parser.add_argument('-d', '--debug', help='Show Pyth program that was run', action='store_true') args = parser.parse_args() if args.file: with open(args.file, 'rb') as f: data = f.read() pyth_code_bytes = packed_bytes_to_str(data) pyth_code = pyth_code_bytes.decode('ascii') if args.debug: print(pyth_code) result, error = pyth.run_code(pyth_code, args.input) if error: print(error) else: print(result, end='') elif args.pack: src = args.pack[0] dst = args.pack[1] with open(src, 'rb') as f: data = f.read() packed_bytes = str_to_packed_bytes(data) str_ = packed_bytes_to_str(packed_bytes) assert data == str_, "Inverse works" with open(dst, 'wb') as f: writen = f.write(packed_bytes)
, metavar=('SRC', 'DST')) group.add_argument('-u', '--unpack', help='unpack packed file SRC into file DST', nargs=2 , metavar=('SRC', 'DST')) parser.add_argument('input', help='Input for Pyth program', nargs='?', default='') parser.add_argument('-d', '--debug', help='Show Pyth program that was run' , action='store_true') args = parser.parse_args() if args.file: with open(args.file, 'rb') as f: data = f.read() pyth_code_bytes = packed_bytes_to_str(data) pyth_code = pyth_code_bytes.decode('ascii') if args.debug: print(pyth_code) result, error = pyth.run_code(pyth_code, args.input) if error: print(error) else: print(result, end='') elif args.pack: src = args.pack[0] dst = args.pack[1] with open(src, 'rb') as f: data = f.read() packed_bytes = str_to_packed_bytes(data) str_ = packed_bytes_to_str(packed_bytes) assert data == str_, "Inverse works" with open(dst, 'wb') as f: writen = f.write(packed_bytes)