Mercurial > repos > bebatut > extract_sequence_file
diff test-data/src/compare_files.py @ 0:14fd6f3b0898 draft
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
author | bebatut |
---|---|
date | Wed, 27 Jan 2016 02:50:51 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/src/compare_files.py Wed Jan 27 02:50:51 2016 -0500 @@ -0,0 +1,52 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import sys +import os +import argparse + +def readfile(filepath): + content = [] + with open(filepath, 'r') as open_file: + for row in open_file.readlines(): + content.append(row[:-1].split(" ")) + return content + +def compare_content(expected, observed, comparison): + if len(expected) != len(observed): + string = comparison + ': ' + string += 'difference in line number\n' + string += '\t\texpected:' + str(len(expected)) + '\n' + string += '\t\tobserved:' + str(len(observed)) + '\n' + raise ValueError(string) + + for i in range(len(expected)): + if expected[i] != observed[i]: + string = comparison + ': ' + string += 'difference in line ' + str(i) + '\n' + string += '\t' + ' '.join(expected[i]) + '\n' + string += '\t' + ' '.join(observed[i]) + '\n' + raise ValueError(string) + +def test_file(filepath): + if not os.path.exists(filepath): + string = os.path.basename(__file__) + ':' + filepath + string += ' does not exist' + raise ValueError(string) + +def compare_files(expected_filepath, observed_filepath, comparison): + test_file(expected_filepath) + test_file(observed_filepath) + + expected_file_content = readfile(expected_filepath) + observed_file_content = readfile(observed_filepath) + compare_content(expected_file_content, observed_file_content, comparison) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--exp_file', required=True) + parser.add_argument('--obs_file', required=True) + parser.add_argument('--comparison', required=True) + args = parser.parse_args() + + compare_files(args.exp_file, args.obs_file, args.comparison) \ No newline at end of file