def test_decode_2(): current = decode('1\n1\n-2\n') eq_(current, 0)
def test_decode_1(): current = decode('1\n1\n1\n') eq_(current, 3)
def test_bad_decode(): """Tests for bad input""" with pytest.raises(one.DecodingException) as e_info: one.decode("1234 5678 9012")
import argparse import one if __name__ == '__main__': parser = argparse.ArgumentParser( description="Encodes or decodes secret messages") parser.add_argument( 'action', help= "States whether the message should be encoded or decoded, or whether a key should be created.", choices=["encode", "decode"]) parser.add_argument( 'message', nargs='?', help="The message to encode / decode, (must be in \"quotes\")") parser.add_argument('-v', '--version', help="Returns the sha256 hash for this code", action='version', version=one.get_version()) args = parser.parse_args() if args.action == "version": print(one.get_version()) elif args.action == "decode": print("Message: " + one.decode(args.message)) elif args.action == "encode": print("Code: " + one.encode(args.message))
def test_decode(): """Tests the one.decode() function - going to two ways.""" assert one.decode(one.encode("Hello World")) == "hello world"