Mercurial > repos > bebatut > extract_sequence_file
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:14fd6f3b0898 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 import sys | |
5 import os | |
6 import argparse | |
7 | |
8 def readfile(filepath): | |
9 content = [] | |
10 with open(filepath, 'r') as open_file: | |
11 for row in open_file.readlines(): | |
12 content.append(row[:-1].split(" ")) | |
13 return content | |
14 | |
15 def compare_content(expected, observed, comparison): | |
16 if len(expected) != len(observed): | |
17 string = comparison + ': ' | |
18 string += 'difference in line number\n' | |
19 string += '\t\texpected:' + str(len(expected)) + '\n' | |
20 string += '\t\tobserved:' + str(len(observed)) + '\n' | |
21 raise ValueError(string) | |
22 | |
23 for i in range(len(expected)): | |
24 if expected[i] != observed[i]: | |
25 string = comparison + ': ' | |
26 string += 'difference in line ' + str(i) + '\n' | |
27 string += '\t' + ' '.join(expected[i]) + '\n' | |
28 string += '\t' + ' '.join(observed[i]) + '\n' | |
29 raise ValueError(string) | |
30 | |
31 def test_file(filepath): | |
32 if not os.path.exists(filepath): | |
33 string = os.path.basename(__file__) + ':' + filepath | |
34 string += ' does not exist' | |
35 raise ValueError(string) | |
36 | |
37 def compare_files(expected_filepath, observed_filepath, comparison): | |
38 test_file(expected_filepath) | |
39 test_file(observed_filepath) | |
40 | |
41 expected_file_content = readfile(expected_filepath) | |
42 observed_file_content = readfile(observed_filepath) | |
43 compare_content(expected_file_content, observed_file_content, comparison) | |
44 | |
45 if __name__ == "__main__": | |
46 parser = argparse.ArgumentParser() | |
47 parser.add_argument('--exp_file', required=True) | |
48 parser.add_argument('--obs_file', required=True) | |
49 parser.add_argument('--comparison', required=True) | |
50 args = parser.parse_args() | |
51 | |
52 compare_files(args.exp_file, args.obs_file, args.comparison) |