def main(args=None): """ run tests for module """ options = parse_test_args(args) if options.nonose or options.test: # Run tests outside of nose. module = sys.modules['__main__'] functions = inspect.getmembers(module, inspect.isfunction) if options.test: func = module.__dict__.get('_test_' + options.test) if func is None: print 'No test named _test_%s' % options.test print 'Known tests are:', [ name[6:] for name, func in functions if name.startswith('_test_') ] sys.exit(1) tests = [func] else: # Run all tests. tests = [ func for name, func in functions if name.startswith('_test_') ] TEST_CONFIG['modname'] = '__main__' setup_server(virtual_display=False) browser = SafeDriver(setup_chrome()) try: for test in tests: try: test(browser) except SkipTest: pass finally: if not options.noclose: try: browser.quit() except WindowsError: # if it already died, calling kill on a defunct process # raises a WindowsError: Access Denied pass teardown_server() else: # Run under nose. import nose sys.argv.append('--cover-package=openmdao.') sys.argv.append('--cover-erase') sys.exit(nose.runmodule())
def main(args=None): """ run tests for module """ options = parse_test_args(args) if options.nonose or options.test: # Run tests outside of nose. module = sys.modules['__main__'] functions = inspect.getmembers(module, inspect.isfunction) if options.test: func = module.__dict__.get('_test_' + options.test) if func is None: print 'No test named _test_%s' % options.test print 'Known tests are:', [name[6:] for name, func in functions if name.startswith('_test_')] sys.exit(1) tests = [func] else: # Run all tests. tests = [func for name, func in functions if name.startswith('_test_')] TEST_CONFIG['modname'] = '__main__' setup_server(virtual_display=False) browser = SafeDriver(setup_chrome()) try: for test in tests: try: test(browser) except SkipTest: pass finally: if not options.noclose: try: browser.quit() except WindowsError: # if it already died, calling kill on a defunct process # raises a WindowsError: Access Denied pass teardown_server() else: # Run under nose. import nose sys.argv.append('--cover-package=openmdao.') sys.argv.append('--cover-erase') sys.exit(nose.runmodule())
def main(args=None): """ run tests for module """ options = parse_test_args(args) if options.nonose or options.test: # Run tests outside of nose. module = sys.modules['__main__'] functions = inspect.getmembers(module, inspect.isfunction) if options.test: func = module.__dict__.get('_test_' + options.test) if func is None: print 'No test named _test_%s' % options.test print 'Known tests are:', [ name[6:] for name, func in functions if name.startswith('_test_') ] sys.exit(1) tests = [func] else: # Run all tests. tests = [ func for name, func in functions if name.startswith('_test_') ] setup_server(virtual_display=False) browser = SafeDriver(setup_chrome()) try: for test in tests: test(browser) finally: if not options.noclose: browser.quit() teardown_server() else: # Run under nose. import nose sys.argv.append('--cover-package=openmdao.') sys.argv.append('--cover-erase') sys.exit(nose.runmodule())
def main(args=None): """ run tests for module """ options = parse_test_args(args) if options.nonose or options.test: # Run tests outside of nose. module = sys.modules['__main__'] functions = inspect.getmembers(module, inspect.isfunction) if options.test: func = module.__dict__.get('_test_' + options.test) if func is None: print 'No test named _test_%s' % options.test print 'Known tests are:', [name[6:] for name, func in functions if name.startswith('_test_')] sys.exit(1) tests = [func] else: # Run all tests. tests = [func for name, func in functions if name.startswith('_test_')] setup_server(virtual_display=False) browser = SafeDriver(setup_chrome()) try: for test in tests: test(browser) finally: if not options.noclose: browser.quit() teardown_server() else: # Run under nose. import nose sys.argv.append('--cover-package=openmdao.') sys.argv.append('--cover-erase') sys.exit(nose.runmodule())
def generate(modname): """ Generates tests for all configured browsers for `modname`. """ global _display_set # Check if functional tests are to be skipped. if int(os.environ.get('OPENMDAO_SKIP_GUI', '0')): return # Search for tests to run. module = sys.modules[modname] functions = inspect.getmembers(module, inspect.isfunction) tests = [func for name, func in functions if name.startswith('_test_')] if not tests: return # Check if any configured browsers are available. available_browsers = [] for name in sorted(_browsers_to_test.keys()): if _browsers_to_test[name][0](): available_browsers.append(name) if not available_browsers: msg = 'No browsers available for GUI functional testing' _display_set = True # Avoids starting the server. yield _Runner(tests[0]), SkipTest(msg) return # Due to the way nose handles generator functions, setup_server() # won't be called until *after* we yield a test, which is too late. if not _display_set: TEST_CONFIG['modname'] = modname setup_server() for name in available_browsers: try: # Open browser and verify we can get page title. browser = SafeDriver(_browsers_to_test[name][1]()) browser.title except Exception as exc: msg = '%s setup failed: %s' % (name, exc) logging.critical(msg) yield _Runner(tests[0]), SkipTest(msg) continue abort(False) cleanup = True runner = None for test in tests: if runner is not None and runner.failed: cleanup = False runner = _Runner(test) logging.critical('') if abort(): msg = '%s tests aborting' % name logging.critical(msg) yield runner, SkipTest(msg) else: logging.critical('Run %s using %s', test.__name__, name) yield runner, browser if runner is not None and runner.failed: cleanup = False if abort(): logging.critical('Aborting tests, skipping browser close') else: try: browser.close() except Exception as exc: print 'browser.close failed:', exc try: browser.quit() except Exception as exc: # if it already died, calling kill on a defunct process # raises a WindowsError: Access Denied print 'browser.quit failed:', exc if name == 'Chrome': if sys.platform == 'win32': time.sleep(2) # Kill any stubborn chromedriver processes. proc = subprocess.Popen( ['taskkill', '/f', '/t', '/im', 'chromedriver.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = proc.communicate() stdout = stdout.strip() if stdout != 'ERROR: The process "chromedriver.exe" not found.': print 'taskkill output: %r' % stdout if cleanup and os.path.exists('chromedriver.log'): try: os.remove('chromedriver.log') except Exception as exc: print 'Could not delete chromedriver.log: %s' % exc
def generate(modname): """ Generates tests for all configured browsers for `modname`. """ global _display_set # Check if functional tests are to be skipped. if int(os.environ.get('OPENMDAO_SKIP_GUI', '0')): return # Search for tests to run. module = sys.modules[modname] functions = inspect.getmembers(module, inspect.isfunction) tests = [func for name, func in functions if name.startswith('_test_')] if not tests: return # Check if any configured browsers are available. available_browsers = [] for name in sorted(_browsers_to_test.keys()): if _browsers_to_test[name][0](): available_browsers.append(name) if not available_browsers: msg = 'No browsers available for GUI functional testing' _display_set = True # Avoids starting the server. yield _Runner(tests[0]), SkipTest(msg) return # Due to the way nose handles generator functions, setup_server() # won't be called until *after* we yield a test, which is too late. if not _display_set: TEST_CONFIG['modname'] = modname setup_server() for name in available_browsers: try: # Open browser and verify we can get page title. browser = SafeDriver(_browsers_to_test[name][1]()) browser.title except Exception as exc: msg = '%s setup failed: %s' % (name, exc) logging.critical(msg) yield _Runner(tests[0]), SkipTest(msg) continue abort(False) cleanup = True runner = None for test in tests: if runner is not None and runner.failed: cleanup = False runner = _Runner(test) logging.critical('') if abort(): msg = '%s tests aborting' % name logging.critical(msg) yield runner, SkipTest(msg) else: logging.critical('Run %s using %s', test.__name__, name) yield runner, browser if runner is not None and runner.failed: cleanup = False if abort(): logging.critical('Aborting tests, skipping browser close') else: try: browser.close() except Exception as exc: print 'browser.close failed:', exc try: browser.quit() except Exception as exc: # if it already died, calling kill on a defunct process # raises a WindowsError: Access Denied print 'browser.quit failed:', exc if name == 'Chrome': if sys.platform == 'win32': time.sleep(2) # Kill any stubborn chromedriver processes. proc = subprocess.Popen(['taskkill', '/f', '/t', '/im', 'chromedriver.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = proc.communicate() stdout = stdout.strip() if stdout != 'ERROR: The process "chromedriver.exe" not found.': print 'taskkill output: %r' % stdout if cleanup and os.path.exists('chromedriver.log'): try: os.remove('chromedriver.log') except Exception as exc: print 'Could not delete chromedriver.log: %s' % exc
def generate(modname): """ Generates tests for all configured browsers for `modname`. """ global _display_set # Because Xvfb does not exist on Windows, it's difficult to do # headless (EC2) testing on Windows. So for now we don't test there. if sys.platform == 'win32': return # Check if functional tests are to be skipped. skip = int(os.environ.get('OPENMDAO_SKIP_GUI', '0')) if skip: return # Search for tests to run. module = sys.modules[modname] functions = inspect.getmembers(module, inspect.isfunction) tests = [func for name, func in functions if name.startswith('_test_')] if not tests: return # Check if any configured browsers are available. available_browsers = [] for name in sorted(_browsers_to_test.keys()): if _browsers_to_test[name][0](): available_browsers.append(name) if not available_browsers: msg = 'No browsers available for GUI functional testing' _display_set = True # Avoids starting the server. yield _Runner(tests[0]), SkipTest(msg) return # Due to the way nose handles generator functions, setup_server() # won't be called until *after* we yield a test, which is too late. if not _display_set: setup_server() for name in available_browsers: try: # Open browser and verify we can get page title. browser = SafeDriver(_browsers_to_test[name][1]()) browser.title except Exception as exc: msg = '%s setup failed: %s' % (name, exc) logging.critical(msg) yield _Runner(tests[0]), SkipTest(msg) continue abort(False) cleanup = True runner = None for test in tests: if runner is not None and runner.failed: cleanup = False runner = _Runner(test) logging.critical('') if abort(): msg = '%s tests aborting' % name logging.critical(msg) yield runner, SkipTest(msg) else: logging.critical('Run %s using %s', test.__name__, name) yield runner, browser if runner is not None and runner.failed: cleanup = False if abort(): logging.critical('Aborting tests, skipping browser close') else: browser.quit() if cleanup and name == 'Chrome' and os.path.exists( 'chromedriver.log'): os.remove('chromedriver.log')
def generate(modname): """ Generates tests for all configured browsers for `modname`. """ global _display_set # Because Xvfb does not exist on Windows, it's difficult to do # headless (EC2) testing on Windows. So for now we don't test there. if sys.platform == 'win32': return # Check if functional tests are to be skipped. skip = int(os.environ.get('OPENMDAO_SKIP_GUI', '0')) if skip: return # Search for tests to run. module = sys.modules[modname] functions = inspect.getmembers(module, inspect.isfunction) tests = [func for name, func in functions if name.startswith('_test_')] if not tests: return # Check if any configured browsers are available. available_browsers = [] for name in sorted(_browsers_to_test.keys()): if _browsers_to_test[name][0](): available_browsers.append(name) if not available_browsers: msg = 'No browsers available for GUI functional testing' _display_set = True # Avoids starting the server. yield _Runner(tests[0]), SkipTest(msg) return # Due to the way nose handles generator functions, setup_server() # won't be called until *after* we yield a test, which is too late. if not _display_set: setup_server() for name in available_browsers: try: # Open browser and verify we can get page title. browser = SafeDriver(_browsers_to_test[name][1]()) browser.title except Exception as exc: msg = '%s setup failed: %s' % (name, exc) logging.critical(msg) yield _Runner(tests[0]), SkipTest(msg) continue abort(False) cleanup = True runner = None for test in tests: if runner is not None and runner.failed: cleanup = False runner = _Runner(test) logging.critical('') if abort(): msg = '%s tests aborting' % name logging.critical(msg) yield runner, SkipTest(msg) else: logging.critical('Run %s using %s', test.__name__, name) yield runner, browser if runner is not None and runner.failed: cleanup = False if abort(): logging.critical('Aborting tests, skipping browser close') else: browser.quit() if cleanup and name == 'Chrome' and os.path.exists('chromedriver.log'): os.remove('chromedriver.log')