def testSegmentation(self): self.otpl_file.write('1\n1\n\n2\n2\n2\n\n3\n\n4\n\n5\n5\n\n6\n\n7\n\n') self.otpl_file.close() basename, ext = splitext(self.otpl_file.name) expected = ["%s-%i%s" % (basename, i, ext) for i in range(4)] result = segment_otpl_file(self.otpl_file.name, 2, Configuration.ENCODING) self.assertEqual(expected, result) expected = ['1\n1\n\n2\n2\n2\n\n', '3\n\n4\n\n', '5\n5\n\n6\n\n', '7\n\n'] for i, outfile in enumerate(result): content = open(outfile, encoding=Configuration.ENCODING).read() self.assertEqual(expected[i], content) remove(outfile)
format='%(levelname)-8s %(module) 10s: %(funcName)s %(message)s') logging.info('verbosity increased') logging.debug('verbosity increased') try: config = Configuration(args.files) except AssertionError as e: logging.error(str(e)) sys.exit(-2) if args.colspec: try: config.colspec = ColumnSpecification.from_string(args.colspec) except ValueError as e: logging.error("colspec parsing failed: %s", str(e)) sys.exit(-3) config.text_suffix = args.text_suffix config.filter = args.filter config.separator = args.separator if args.segment > 0: segment_file_names = [] for otpl_file in config.input_files: segment_file_names.extend(segment_otpl_file(otpl_file, args.segment, config.encoding)) config.input_files = segment_file_names sys.exit(otpl_to_text(config))