irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

run_tests.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 from __future__ import print_function
3 
4 try:
5  import importlib
6 except ImportError:
7  from __builtin__ import __import__
8 import itertools
9 import logging
10 import optparse
11 import os
12 import subprocess
13 import sys
14 import json
15 
16 if sys.version_info < (2, 7):
17  import unittest2 as unittest
18 else:
19  import unittest
20 
21 from irods.configuration import IrodsConfig
22 import irods.test
23 import irods.test.settings
24 import irods.log
25 import irods.paths
26 
28  irodsctl = os.path.join(IrodsConfig().irods_directory, 'irodsctl')
29  subprocess.check_call([irodsctl, arg])
30 
32  print('devtesty is currently disabled', file=sys.stderr)
33  # run_irodsctl_with_arg('devtesty')
34 
36  subprocess.check_call('rulebase_fastswap_test_2276.sh')
37 
39  unittest.installHandler()
40 
41 def optparse_callback_use_ssl(*args, **kwargs):
42  irods.test.settings.USE_SSL = True
43 
44 def optparse_callback_use_mungefs(*args, **kwargs):
45  irods.test.settings.USE_MUNGEFS = True
46 
47 def optparse_callback_topology_test(option, opt_str, value, parser):
48  irods.test.settings.RUN_IN_TOPOLOGY = True
49  irods.test.settings.TOPOLOGY_FROM_RESOURCE_SERVER = value == 'resource'
50  irods.test.settings.HOSTNAME_1 = 'resource1.example.org'
51  irods.test.settings.HOSTNAME_2 = 'resource2.example.org'
52  irods.test.settings.HOSTNAME_3 = 'resource3.example.org'
53  irods.test.settings.ICAT_HOSTNAME = 'icat.example.org'
54 
55 def optparse_callback_federation(option, opt_str, value, parser):
56  irods.test.settings.FEDERATION.REMOTE_IRODS_VERSION = tuple(map(int, value[0].split('.')))
57  irods.test.settings.FEDERATION.REMOTE_ZONE = value[1]
58  irods.test.settings.FEDERATION.REMOTE_HOST = value[2]
59  if irods.test.settings.FEDERATION.REMOTE_IRODS_VERSION < (4,2):
60  irods.test.settings.FEDERATION.REMOTE_VAULT = '/var/lib/irods/iRODS/Vault'
61 
62 def is_testfile(filename):
63  name, ext = os.path.splitext(filename)
64  return name.startswith('test_') and ext == 'py'
65 
67  additional_plugin_tests = []
69  for curdir, _, entries in os.walk(os.path.join(root, 'plugins')):
70  for entry in entries:
71  module = '.'.join(os.path.split(os.path.relpath(curdir, root)))
72  if is_testfile(entry):
73  additional_plugin_tests.append('.'.join([module, os.path.splitext(filename)[0]]))
74  return additional_plugin_tests
75 
76 def run_tests_from_names(names, buffer_test_output, xml_output):
77  loader = unittest.TestLoader()
78  suites = []
79  for name in names:
80  full_name = 'irods.test.' + name
81  try:
82  suite = loader.loadTestsFromName(full_name)
83  suites.append(suite)
84  except AttributeError:
85  raise ImportError("Could not load '" + full_name + "'. Please ensure the file exists and all imports (including imports in imported files) are valid.")
86  super_suite = unittest.TestSuite(suites)
87  if xml_output:
88  import xmlrunner
89  runner = xmlrunner.XMLTestRunner(output='test-reports', verbosity=2)
90  else:
91  runner = unittest.TextTestRunner(verbosity=2, failfast=True, buffer=buffer_test_output, resultclass=RegisteredTestResult)
92  results = runner.run(super_suite)
93  return results
94 
95 class RegisteredTestResult(unittest.TextTestResult):
96  def __init__(self, *args, **kwargs):
97  super(RegisteredTestResult, self).__init__(*args, **kwargs)
98  unittest.registerResult(self)
99 
100  def startTest(self, test):
101  # TextTestResult's impl prints as "test (module.class)" which prevents copy/paste
102  print('{0} ... '.format(test.id()), end='', file=self.stream)
103  unittest.TestResult.startTest(self, test)
104 
105 if __name__ == '__main__':
106  logging.getLogger().setLevel(logging.NOTSET)
107  l = logging.getLogger(__name__)
108 
109  irods.log.register_tty_handler(sys.stderr, logging.WARNING, None)
111 
112  parser = optparse.OptionParser()
113  parser.add_option('--run_specific_test', metavar='dotted name')
114  parser.add_option('--run_python_suite', action='store_true')
115  parser.add_option('--run_plugin_tests', action='store_true')
116  parser.add_option('--include_auth_tests', action='store_true')
117  parser.add_option('--include_timing_tests', action='store_true')
118  parser.add_option('--run_devtesty', action='store_true')
119  parser.add_option('--topology_test', type='choice', choices=['icat', 'resource'], action='callback', callback=optparse_callback_topology_test, metavar='<icat|resource>')
120  parser.add_option('--catch_keyboard_interrupt', action='callback', callback=optparse_callback_catch_keyboard_interrupt)
121  parser.add_option('--use_ssl', action='callback', callback=optparse_callback_use_ssl)
122  parser.add_option('--use_mungefs', action='callback', callback=optparse_callback_use_mungefs)
123  parser.add_option('--no_buffer', action='store_false', dest='buffer_test_output', default=True)
124  parser.add_option('--xml_output', action='store_true', dest='xml_output', default=False)
125  parser.add_option('--federation', type='str', nargs=3, action='callback', callback=optparse_callback_federation, metavar='<remote irods version, remote zone, remote host>')
126  options, _ = parser.parse_args()
127 
128  if len(sys.argv) == 1:
129  parser.print_help()
130  sys.exit(0)
131 
132  univmss_testing = os.path.join(IrodsConfig().irods_directory, 'msiExecCmd_bin', 'univMSSInterface.sh')
133  if not os.path.exists(univmss_testing):
134  univmss_template = os.path.join(IrodsConfig().irods_directory, 'msiExecCmd_bin', 'univMSSInterface.sh.template')
135  with open(univmss_template) as f:
136  univmss_contents = f.read().replace('template-','')
137  with open(univmss_testing, 'w') as f:
138  f.write(univmss_contents)
139  os.chmod(univmss_testing, 0o544)
140 
141  test_identifiers = []
142  if options.run_specific_test:
143  test_identifiers.append(options.run_specific_test)
144  if options.include_auth_tests:
145  test_identifiers.append('test_auth')
146  if options.include_timing_tests:
147  test_identifiers.append('timing_tests')
148  if options.run_python_suite:
149  with open(os.path.join(IrodsConfig().scripts_directory, 'core_tests_list.json'), 'r') as f:
150  test_identifiers.extend(json.loads(f.read()))
151  if options.run_plugin_tests:
152  test_identifiers.extend(get_plugin_tests())
153 
154  results = run_tests_from_names(test_identifiers, options.buffer_test_output, options.xml_output)
155  print(results)
156 
157  os.remove(univmss_testing)
158 
159  if not results.wasSuccessful():
160  sys.exit(1)
161 
162  if options.run_devtesty:
163  run_devtesty()
irods.configuration.IrodsConfig
Definition: configuration.py:22
run_tests.get_plugin_tests
def get_plugin_tests()
Definition: run_tests.py:66
run_tests.RegisteredTestResult.__init__
def __init__(self, *args, **kwargs)
Definition: run_tests.py:96
run_tests.optparse_callback_federation
optparse_callback_federation
Definition: run_tests.py:125
run_tests.is_testfile
def is_testfile(filename)
Definition: run_tests.py:62
run_tests.RegisteredTestResult.startTest
def startTest(self, test)
Definition: run_tests.py:100
irods.configuration
Definition: configuration.py:1
run_tests.run_irodsctl_with_arg
def run_irodsctl_with_arg(arg)
Definition: run_tests.py:27
replace
void replace(Hashtable *varTypes, int a, ExprType *b)
run_tests.optparse_callback_use_mungefs
def optparse_callback_use_mungefs(*args, **kwargs)
Definition: run_tests.py:44
run_tests.optparse_callback_use_ssl
def optparse_callback_use_ssl(*args, **kwargs)
Definition: run_tests.py:41
run_tests.RegisteredTestResult
Definition: run_tests.py:95
irods.log
Definition: log.py:1
irods.paths
Definition: paths.py:1
run_tests.run_tests_from_names
def run_tests_from_names(names, buffer_test_output, xml_output)
Definition: run_tests.py:76
irods::join
std::string join(std::vector< std::string > &strs, const std::string &separator)
Definition: irods_serialization.cpp:169
irods.paths.test_directory
def test_directory()
Definition: paths.py:28
run_tests.run_fastswap_test
def run_fastswap_test()
Definition: run_tests.py:35
irods.log.register_tty_handler
def register_tty_handler(stream, minlevel, maxlevel)
Definition: log.py:46
irods.log.register_file_handler
def register_file_handler(log_file_path, level=logging.DEBUG)
Definition: log.py:57
run_tests.optparse_callback_topology_test
optparse_callback_topology_test
Definition: run_tests.py:119
run_tests.optparse_callback_catch_keyboard_interrupt
def optparse_callback_catch_keyboard_interrupt(*args, **kwargs)
Definition: run_tests.py:38
run_tests.run_devtesty
def run_devtesty()
Definition: run_tests.py:31