#!/usr/bin/python from __future__ import with_statement import sys import xz_mod import python2x3 def main(): '''main function''' all_good = True with open('/etc/protocols', 'rb') as protocols_file: protocols = protocols_file.read() for string in [ 'Rush Rocks', 'flurfl', protocols ]: b_string = python2x3.string_to_binary(string) compressed = xz_mod.compress(b_string) decompressed = xz_mod.decompress(compressed) if b_string != decompressed: all_good = False sys.stderr.write('%s: Bad round trip: "%s", "%s"\n' % (sys.argv[0], string[:40], decompressed[:40])) if 1 == 2: # This facilitates debugging, but normally we want info about all 3, not just the first to fail with open('1', 'wb') as one: one.write(b_string) with open('2', 'wb') as two: two.write(decompressed) sys.exit(1) if not all_good: sys.stderr.write('%s: One or more tests failed\n' % sys.argv[0]) sys.exit(1) main()