test.py
Go to the documentation of this file.
1 # -*- Python -*-
2 # -*- coding: utf-8 -*-
3 
4 '''rtsprofile
5 
6 Copyright (C) 2009-2010
7  Geoffrey Biggs
8  RT-Synthesis Research Group
9  Intelligent Systems Research Institute,
10  National Institute of Advanced Industrial Science and Technology (AIST),
11  Japan
12  All rights reserved.
13 Licensed under the Eclipse Public License -v 1.0 (EPL)
14 http://www.opensource.org/licenses/eclipse-1.0.txt
15 
16 File: test.py
17 
18 Unit tests.
19 
20 '''
21 
22 __version__ = '$Revision: $'
23 # $Source$
24 
25 
26 import os.path
27 from rtsprofile.rts_profile import RtsProfile
28 import sys
29 import tempfile
30 from traceback import print_exc
31 
32 
33 def main(argv):
34  print \
35 '''This test loads a given XML or YAML file (type determined by the extension)
36 into an RtsProfile object. The object is printed to a string, which is stored.
37 
38 It then attempts to save the object using the XML output. This output is loaded
39 back in, printed to a string, and that string compared to the original. They
40 should be the same.
41 
42 This save-load-check process is then repeated for the YAML output.
43 '''
44 
45  # Load the input
46  input_name = argv[1]
47  type = os.path.splitext(input_name)[1][1:]
48  f = open(input_name)
49  if type == 'xml':
50  orig_prof = RtsProfile(xml_spec=f)
51  elif type == 'yaml':
52  orig_prof = RtsProfile(yaml_spec=f)
53  else:
54  print >>sys.stderr, 'Unknown input type: {0}'.format(type)
55  return 1
56  f.close()
57  orig_prof_str = str(orig_prof)
58  print 'Loaded original.'
59  print
60 
61  # Test XML output
62  failed = False
63  xml_output = ''
64  xml_prof_str = ''
65  try:
66  xml_output = orig_prof.save_to_xml()
67  print 'Saved as XML.'
68  xml_prof = RtsProfile(xml_spec=xml_output)
69  print 'Loaded XML.'
70  xml_prof_str = str(xml_prof)
71  print 'Printed XML.'
72  print
73  except:
74  print_exc()
75  print
76  failed = True
77  if xml_prof_str != orig_prof_str:
78  print 'XML profile does not equal original profile.'
79  failed = True
80  if failed:
81  print >>sys.stderr, 'XML test failed.'
82  f = open('original_prof.dump', 'w')
83  f.write(orig_prof_str)
84  f.close()
85  f = open('xml_prof.dump', 'w')
86  f.write(xml_prof_str)
87  f.close()
88  f = open('xml_raw.dump', 'w')
89  f.write(xml_output)
90  f.close()
91  return 1
92 
93  # Test YAML output
94  failed = False
95  yaml_output = ''
96  yaml_prof_str = ''
97  try:
98  yaml_output = orig_prof.save_to_yaml()
99  print 'Saved as YAML.'
100  yaml_prof = RtsProfile(yaml_spec=yaml_output)
101  print 'Loaded YAML.'
102  yaml_prof_str = str(yaml_prof)
103  print 'Printed YAML.'
104  print
105  except:
106  print_exc()
107  print
108  failed = True
109  if yaml_prof_str != orig_prof_str:
110  print 'YAML profile does not equal original profile.'
111  failed = True
112  if failed:
113  print >>sys.stderr, 'YAML test failed.'
114  f = open('original_prof.dump', 'w')
115  f.write(orig_prof_str)
116  f.close()
117  f = open('yaml_prof.dump', 'w')
118  f.write(yaml_prof_str)
119  f.close()
120  f = open('yaml_raw.dump', 'w')
121  f.write(yaml_output)
122  f.close()
123  return 1
124 
125  print >>sys.stderr, 'Tests passed.'
126  return 0
127 
128 
129 if __name__ == '__main__':
130  sys.exit(main(sys.argv))
131 
132 
133 # vim: tw=79
134 
def main(argv)
Definition: test.py:33


rtsprofile
Author(s): Geoffrey Biggs
autogenerated on Fri Jun 7 2019 21:52:35