Public Member Functions | Public Attributes | List of all members
runtests.Tester Class Reference

Public Member Functions

def __init__ (self, args, test)
 
def compare_ok (self, got_file, expected_file, name)
 
def get_config (self)
 
def prepare_test (self)
 
def update_test (self, testmgr)
 
def perform_test (self, testmgr)
 
def run (self, testmgr)
 

Public Attributes

 args
 
 test
 
 update
 
 config
 
 test_name
 
 test_id
 
 test_out
 

Detailed Description

Definition at line 8 of file runtests.py.

Constructor & Destructor Documentation

def runtests.Tester.__init__ (   self,
  args,
  test 
)

Definition at line 9 of file runtests.py.

9  def __init__(self,args,test):
10  self.args = args
11  self.test = test
12  self.update = args.updateref
13  self.config = self.get_config()
14  self.test_name = '[%s]: %s' % (self.test,self.config['objective'][0])
15  self.test_id = self.test.split('_')[0]
16  if self.update:
17  self.test_out = self.args.inputdir+'/'+self.test_id
18  else:
19  self.test_out = self.args.outputdir+'/test_output_'+self.test_id
20  self.prepare_test()
21 
def __init__(self, args, test)
Definition: runtests.py:9
def prepare_test(self)
Definition: runtests.py:47
def get_config(self)
Definition: runtests.py:33

Member Function Documentation

def runtests.Tester.compare_ok (   self,
  got_file,
  expected_file,
  name 
)

Definition at line 22 of file runtests.py.

22  def compare_ok(self,got_file,expected_file,name):
23  if not os.path.isfile(got_file):
24  return (True,'%s absent' % got_file)
25  elif not os.path.isfile(expected_file):
26  return (True,'%s absent' % expected_file)
27  else:
28  diff = os.popen('diff -b -w -u %s %s' % (got_file,expected_file)).read()
29  if diff and not diff.startswith("No differences"):
30  return (True,'Difference between generated output and reference:\n%s' % diff)
31  return (False,'')
32 
int read(int, char *, size_t)
Read bytes from a file descriptor.
def compare_ok(self, got_file, expected_file, name)
Definition: runtests.py:22
def runtests.Tester.get_config (   self)

Definition at line 33 of file runtests.py.

33  def get_config(self):
34  config = {}
35  with open(self.args.inputdir+'/'+self.test,'r') as f:
36  for line in f.readlines():
37  m = config_reg.match(line)
38  if m:
39  key = m.group('name')
40  value = m.group('value')
41  if (key=='config'):
42  value = value.replace('$INPUTDIR',self.args.inputdir)
43  #print('key=%s value=%s' % (key,value))
44  config.setdefault(key, []).append(value)
45  return config
46 
int open(const char *, int)
Opens a file descriptor.
def get_config(self)
Definition: runtests.py:33
def runtests.Tester.perform_test (   self,
  testmgr 
)

Definition at line 100 of file runtests.py.

100  def perform_test(self,testmgr):
101  # look for files to check against the reference
102  if 'check' in self.config:
103  for check in self.config['check']:
104  check_file='%s/out/%s' % (self.test_out,check)
105  # check if the file we need to check is actually generated
106  if not os.path.isfile(check_file):
107  testmgr.ok(False,self.test_name,msg='Non-existing file %s after \'check:\' statement' % check_file)
108  return
109  # convert output to canonical form
110  data = os.popen('%s --format --noblanks --nowarning %s' % (self.args.xmllint,check_file)).read()
111  if data:
112  # strip version
113  data = re.sub(r'xsd" version="[0-9.-]+"','xsd" version=""',data).rstrip('\n')
114  else:
115  testmgr.ok(False,self.test_name,msg='Failed to run %s on the doxygen output file %s' % (self.args.xmllint,self.test_out))
116  return
117  out_file='%s/%s' % (self.test_out,check)
118  with open(out_file,'w') as f:
119  print(data,file=f)
120  ref_file='%s/%s/%s' % (self.args.inputdir,self.test_id,check)
121  (failed,msg) = self.compare_ok(out_file,ref_file,self.test_name)
122  if failed:
123  testmgr.ok(False,self.test_name,msg)
124  return
125  shutil.rmtree(self.test_out,ignore_errors=True)
126  testmgr.ok(True,self.test_name)
127 
int open(const char *, int)
Opens a file descriptor.
def perform_test(self, testmgr)
Definition: runtests.py:100
int read(int, char *, size_t)
Read bytes from a file descriptor.
def compare_ok(self, got_file, expected_file, name)
Definition: runtests.py:22
def runtests.Tester.prepare_test (   self)

Definition at line 47 of file runtests.py.

47  def prepare_test(self):
48  # prepare test environment
49  shutil.rmtree(self.test_out,ignore_errors=True)
50  os.mkdir(self.test_out)
51  shutil.copy(self.args.inputdir+'/Doxyfile',self.test_out)
52  with open(self.test_out+'/Doxyfile','a') as f:
53  print('INPUT=%s/%s' % (self.args.inputdir,self.test), file=f)
54  print('STRIP_FROM_PATH=%s' % self.args.inputdir, file=f)
55  print('XML_OUTPUT=%s/out' % self.test_out, file=f)
56  print('EXAMPLE_PATH=%s' % self.args.inputdir, file=f)
57  if 'config' in self.config:
58  for option in self.config['config']:
59  print(option, file=f)
60 
61  if 'check' not in self.config or not self.config['check']:
62  print('Test doesn\'t specify any files to check')
63  sys.exit(1)
64 
65  # run doxygen
66  if (sys.platform == 'win32'):
67  redir=' > nul:'
68  else:
69  redir=' 2> /dev/null'
70  if os.system('%s %s/Doxyfile %s' % (self.args.doxygen,self.test_out, redir))!=0:
71  print('Error: failed to run %s on %s/Doxyfile' % (self.args.doxygen,self.test_out));
72  sys.exit(1)
73 
int open(const char *, int)
Opens a file descriptor.
def prepare_test(self)
Definition: runtests.py:47
def runtests.Tester.run (   self,
  testmgr 
)

Definition at line 128 of file runtests.py.

128  def run(self,testmgr):
129  if self.update:
130  self.update_test(testmgr)
131  else:
132  self.perform_test(testmgr)
133 
def run(self, testmgr)
Definition: runtests.py:128
def perform_test(self, testmgr)
Definition: runtests.py:100
def update_test(self, testmgr)
Definition: runtests.py:75
def runtests.Tester.update_test (   self,
  testmgr 
)

Definition at line 75 of file runtests.py.

75  def update_test(self,testmgr):
76  print('Updating reference for %s' % self.test_name)
77 
78  if 'check' in self.config:
79  for check in self.config['check']:
80  check_file='%s/out/%s' % (self.test_out,check)
81  # check if the file we need to check is actually generated
82  if not os.path.isfile(check_file):
83  print('Non-existing file %s after \'check:\' statement' % check_file)
84  return
85  # convert output to canonical form
86  data = os.popen('%s --format --noblanks --nowarning %s' % (self.args.xmllint,check_file)).read()
87  if data:
88  # strip version
89  data = re.sub(r'xsd" version="[0-9.-]+"','xsd" version=""',data).rstrip('\n')
90  else:
91  print('Failed to run %s on the doxygen output file %s' % (self.args.xmllint,self.test_out))
92  return
93  out_file='%s/%s' % (self.test_out,check)
94  with open(out_file,'w') as f:
95  print(data,file=f)
96  shutil.rmtree(self.test_out+'/out',ignore_errors=True)
97  os.remove(self.test_out+'/Doxyfile')
98 
int open(const char *, int)
Opens a file descriptor.
int read(int, char *, size_t)
Read bytes from a file descriptor.
def update_test(self, testmgr)
Definition: runtests.py:75

Member Data Documentation

runtests.Tester.args

Definition at line 10 of file runtests.py.

runtests.Tester.config

Definition at line 13 of file runtests.py.

runtests.Tester.test

Definition at line 11 of file runtests.py.

runtests.Tester.test_id

Definition at line 15 of file runtests.py.

runtests.Tester.test_name

Definition at line 14 of file runtests.py.

runtests.Tester.test_out

Definition at line 17 of file runtests.py.

runtests.Tester.update

Definition at line 12 of file runtests.py.


The documentation for this class was generated from the following file: