test.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # Desc: Test program for the Stage worldfile
4 # Author: Andrew Howard
5 # Date; 6 Jun 2002
6 # CVS: $Id: test.py,v 1.1 2002-06-07 16:28:40 inspectorg Exp $
7 
8 import os
9 import string
10 import sys
11 
12 
13 def test_file(filename):
14  """Runs stage with the given filename and validates the output."""
15 
16  file = open(filename)
17  a = read_lists(file)
18  del file
19 
20  file = os.popen('../../src/stage %s' % filename, 'r')
21  b = read_lists(file)
22  del file
23 
24  print '%s : errors ' % filename,
25  if compare_lists(a[2], b[2]) != 0:
26  print ': \033[41mfail\033[0m'
27  print_lists(a[2], b[2])
28  return 1
29  else:
30  print ': pass'
31 
32  print '%s : sections' % filename,
33  if compare_lists(a[0], b[0]) != 0:
34  print ': \033[41mfail\033[0m'
35  print_lists(a[0], b[0])
36  else:
37  print ': pass'
38 
39  print '%s : items ' % filename,
40  if compare_lists(a[1], b[1]) != 0:
41  print ': \033[41mfail\033[0m'
42  print_lists(a[1], b[1])
43  else:
44  print ': pass'
45 
46  return 0
47 
48 
49 def read_lists(file):
50  """Read and return the various lists from a file object."""
51 
52  list = None
53  sections = []
54  items = []
55  errors = []
56 
57  while 1:
58 
59  line = file.readline()
60  if not line:
61  break
62  bits = string.split(line)
63  if not bits:
64  continue
65  if bits[0] == '##':
66  if bits[1] == 'begin':
67  if bits[2] == 'sections':
68  list = sections
69  elif bits[2] == 'items':
70  list = items
71  elif bits[1] == 'end':
72  list = None
73  elif bits[1] == 'stage' and bits[2] == 'error':
74  errors.append(string.join(bits[4:]))
75  elif list != None:
76  list.append(string.join(bits[1:]))
77  elif bits[0] == 'stage' and bits[1] == 'error':
78  errors.append(string.join(bits[3:]))
79 
80  return (sections, items, errors)
81 
82 
83 def compare_lists(la, lb):
84  """Compare two lists."""
85 
86  if len(la) != len(lb):
87  return 1
88  for i in range(0, len(la)):
89  sa = la[i]
90  sb = lb[i]
91  if sa != sb:
92  return 1
93  return 0
94 
95 
96 def print_lists(la, lb):
97  """Print two lists."""
98 
99  for i in range(0, max(len(la), len(lb))):
100  if i < len(la):
101  sa = la[i]
102  else:
103  sa = ''
104  if i < len(lb):
105  sb = lb[i]
106  else:
107  sb = ''
108  if sa == sb:
109  print sa
110  print sb
111  else:
112  print '\033[42m' + sa + '\33[K\033[0m'
113  print '\033[41m' + sb + '\33[K\033[0m'
114  return
115 
116 
117 
118 
119 def main(argv):
120  """Run the tests."""
121 
122  for test in argv[1:]:
123  test_file(test)
124 
125  return
126 
127 
128 
129 
130 if __name__ == '__main__':
131 
132  main(sys.argv)
def print_lists(la, lb)
Definition: test.py:96
def read_lists(file)
Definition: test.py:49
def main(argv)
Definition: test.py:119
def test_file(filename)
Definition: test.py:13
def compare_lists(la, lb)
Definition: test.py:83


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:10