本文整理汇总了Python中nose.runmodule函数的典型用法代码示例。如果您正苦于以下问题:Python runmodule函数的具体用法?Python runmodule怎么用?Python runmodule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了runmodule函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv=sys.argv[1:]):
parser = argparse.ArgumentParser()
parser.add_argument(
'-v', '--verbose',
action='store_true',
help="Logging is normally set to an INFO level. When this flag "
"is used logging is set to DEBUG. ")
args = parser.parse_args(argv)
# Configure logging
logging_level = logging.DEBUG if args.verbose is True else logging.INFO
logging.basicConfig()
logging.getLogger().setLevel(logging_level)
xunit_file = os.path.join(os.environ.get('RIFT_MODULE_TEST'),
"restconf_systest.xml")
nose.runmodule(
argv=[sys.argv[0],
"--logging-level={}".format(logging.getLevelName(logging_level)),
"--logging-format={}".format(
'%(asctime)-15s %(levelname)s %(message)s'),
"--nocapture", # display stdout immediately
"--with-xunit",
"--xunit-file=%s" % xunit_file])
示例2: main
def main():
"""The main routine."""
# Parse arguments
local_url = 'http://localhost:{}'.format(LOCAL_TEST_PORT)
parser = argparse.ArgumentParser(description='Run web-service tests')
parser.add_argument(
'-e', '--endpoint', dest='endpoint', default='auto',
help='Which server to test against.\n'
'auto: {} (server starts automatically)\n'
'local: http://localhost:8080\n'
'prod: https://url-caster.appspot.com\n'
'dev: https://url-caster-dev.appspot.com\n'
'*: Other values interpreted literally'
.format(local_url))
parser.add_argument('-x', '--experimental', dest='experimental', action='store_true', default=False)
args = parser.parse_args()
# Setup the endpoint
endpoint = args.endpoint
server = None
if endpoint.lower() == 'auto':
endpoint = local_url
print 'Starting local server1...',
server = subprocess.Popen([
'/usr/bin/python /home/happy/google_appengine/dev_appserver.py', os.path.dirname(__file__),
'--port', str(LOCAL_TEST_PORT),
'--admin_port', str(LOCAL_TEST_PORT + 1),
], bufsize=1, stderr=subprocess.PIPE, preexec_fn=os.setsid)
# Wait for the server to start up
while True:
line = server.stderr.readline()
if 'Unable to bind' in line:
print 'Rogue server already running.'
return 1
if 'running at: {}'.format(local_url) in line:
break
print 'done'
elif endpoint.lower() == 'local':
endpoint = 'http://localhost:8080'
elif endpoint.lower() == 'prod':
endpoint = 'https://url-caster.appspot.com'
elif endpoint.lower() == 'dev':
endpoint = 'https://url-caster-dev.appspot.com'
PwsTest.HOST = endpoint
PwsTest.ENABLE_EXPERIMENTAL = args.experimental
# Run the tests
try:
nose.runmodule()
finally:
# Teardown the endpoint
if server:
os.killpg(os.getpgid(server.pid), signal.SIGINT)
server.wait()
# We should never get here since nose.runmodule will call exit
return 0
示例3: main
def main():
"""The main routine."""
# Parse arguments
local_url = 'http://localhost:{}'.format(LOCAL_TEST_PORT)
parser = argparse.ArgumentParser(description='Run web-service tests')
parser.add_argument(
'-e', '--endpoint', dest='endpoint', default='AUTO',
help='Which server to test against.\n'
'AUTO: {} (server starts automatically)\n'
'LOCAL: http://localhost:8080\n'
'PROD: http://url-caster.appspot.com\n'
'DEV: http://url-caster-dev.appspot.com\n'
'*: Other values interpreted literally'
.format(local_url))
args = parser.parse_args()
# Setup the endpoint
endpoint = args.endpoint
server = None
if endpoint == 'AUTO':
endpoint = local_url
print 'Starting local server...',
server = subprocess.Popen([
'dev_appserver.py', os.path.dirname(__file__),
'--port', str(LOCAL_TEST_PORT),
'--admin_port', str(LOCAL_TEST_PORT + 1),
], bufsize=1, stderr=subprocess.PIPE, preexec_fn=os.setsid)
# Wait for the server to start up
while True:
line = server.stderr.readline()
if 'Unable to bind' in line:
print 'Rogue server already running.'
return 1
if 'running at: {}'.format(local_url) in line:
break
print 'done'
elif endpoint == 'LOCAL':
endpoint = 'http://localhost:8080'
elif endpoint == 'PROD':
endpoint = 'http://url-caster.appspot.com'
elif endpoint == 'DEV':
endpoint = 'http://url-caster-dev.appspot.com'
PwsTest.HOST = endpoint
# Run the tests
try:
nose.runmodule()
finally:
# Teardown the endpoint
if server:
os.killpg(os.getpgid(server.pid), signal.SIGINT)
server.wait()
# We should never get here since nose.runmodule will call exit
return 0
示例4: run_module
def run_module(name, file):
"""Run current test cases of the file.
Args:
name: __name__ attribute of the file.
file: __file__ attribute of the file.
"""
if name == '__main__':
nose.runmodule(argv=[file, '-vvs', '-x', '--pdb', '--pdb-failure'],
exit=False)
示例5: _run_tests
def _run_tests(path):
"""Runs tests on a library located at path"""
global rx_h5, nucs, npert, G
rx_h5 = tb.openFile(path, 'r')
nucs = rx_h5.root.transmute_nucs_LL[:]
npert = len(rx_h5.root.perturbations)
G = len(rx_h5.root.energy[0]) - 1
nose.runmodule(__name__, argv=[__file__])
rx_h5.close()
示例6: main
def main():
'''Run test'''
# Get line
argv = list(sys.argv)
# Add configuration
argv.extend([
'--verbosity=2',
'--exe',
'--nocapture',
'--with-nosango',
])
# Run test
nose.runmodule(argv=argv)
示例7: runmodule
def runmodule(level=logging.INFO, verbosity=1, argv=[]):
"""
:param argv: optional list of string with additional options passed to nose.run
see http://nose.readthedocs.org/en/latest/usage.html
"""
if argv is None:
return nose.runmodule()
setlog(level)
""" ensures stdout is printed after the tests results"""
import sys
from io import StringIO
module_name = sys.modules["__main__"].__file__
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
result = nose.run(
argv=[
sys.argv[0],
module_name,
'-s','--nologcapture',
'--verbosity=%d'%verbosity,
]+argv
)
sys.stdout = old_stdout
print(mystdout.getvalue())
示例8: test
def test(**kwargs):
""" Run all pylada nose tests
Does not include some C++ only tests, nor tests that require
external programs such as vasp. Those should be run via ctest.
"""
from os.path import dirname
from nose import runmodule
return runmodule(dirname(__file__), **kwargs)
示例9: main
def main():
"""Main routine, executed when this file is run as a script """
# Create a tempdir, as a subdirectory of the current one, which all tests
# use for their storage. By default, it is removed at the end.
global TESTDIR
cwd = os.getcwd()
TESTDIR = tempfile.mkdtemp(prefix='tmp-testdata-',dir=cwd)
print "Running tests:"
# This call form is ipython-friendly
try:
os.chdir(TESTDIR)
nose.runmodule(argv=[__file__,'-vvs'],
exit=False)
finally:
os.chdir(cwd)
print
print "Cleanup - removing temp directory:", TESTDIR
# If you need to debug a problem, comment out the next line that cleans
# up the temp directory, and you can see in there all temporary files
# created by the test code
shutil.rmtree(TESTDIR)
print """
***************************************************************************
TESTS FINISHED
***************************************************************************
If the printout above did not finish in 'OK' but instead says 'FAILED', copy
and send the *entire* output, including the system information below, for help.
We'll do our best to assist you. You can send your message to the Scipy user
mailing list:
http://mail.scipy.org/mailman/listinfo/scipy-user
but feel free to also CC directly: [email protected]
"""
sys_info()
示例10: main
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())
示例11: main
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())
示例12: DatetimeIndex
self.assertTrue(idx.equals(DatetimeIndex(dates, tz="US/Eastern")))
idx = idx.tz_convert("UTC")
self.assertTrue(idx.equals(DatetimeIndex(dates, tz="UTC")))
dates = ["2010-12-01 00:00", "2010-12-02 00:00", NaT]
idx = DatetimeIndex(dates)
idx = idx.tz_localize("US/Pacific")
self.assertTrue(idx.equals(DatetimeIndex(dates, tz="US/Pacific")))
idx = idx.tz_convert("US/Eastern")
expected = ["2010-12-01 03:00", "2010-12-02 03:00", NaT]
self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Eastern")))
idx = idx + offsets.Hour(5)
expected = ["2010-12-01 08:00", "2010-12-02 08:00", NaT]
self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Eastern")))
idx = idx.tz_convert("US/Pacific")
expected = ["2010-12-01 05:00", "2010-12-02 05:00", NaT]
self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Pacific")))
idx = idx + np.timedelta64(3, "h")
expected = ["2010-12-01 08:00", "2010-12-02 08:00", NaT]
self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Pacific")))
idx = idx.tz_convert("US/Eastern")
expected = ["2010-12-01 11:00", "2010-12-02 11:00", NaT]
self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Eastern")))
if __name__ == "__main__":
nose.runmodule(argv=[__file__, "-vvs", "-x", "--pdb", "--pdb-failure"], exit=False)
示例13: pml_hybrid
out = pml_hybrid(synthetic_data(), theta=(0., 1.))
assert_equals(out.shape, (4, 5, 5))
assert_equals(np.isnan(out).sum(), 0)
def test_pml_quad():
out = pml_quad(synthetic_data(), theta=(0., 1.))
assert_equals(out.shape, (4, 5, 5))
assert_equals(np.isnan(out).sum(), 0)
def test_sirt():
out = sirt(synthetic_data(), theta=(0., 1.))
assert_equals(out.shape, (4, 5, 5))
assert_equals(np.isnan(out).sum(), 0)
def test_write_center():
dpath = os.path.join('test', 'tmp')
write_center(synthetic_data(), [0., 1.], dpath, center=[3, 5, 0.5])
assert_equals(os.path.isfile(os.path.join(dpath, '3.00.tiff')), True)
assert_equals(os.path.isfile(os.path.join(dpath, '3.50.tiff')), True)
assert_equals(os.path.isfile(os.path.join(dpath, '4.00.tiff')), True)
assert_equals(os.path.isfile(os.path.join(dpath, '4.50.tiff')), True)
shutil.rmtree(dpath)
if __name__ == '__main__':
import nose
nose.runmodule(exit=False)
示例14: list
# check calling w/ named arguments
shape_args = list(shape_args)
vals = [meth(x, *shape_args) for meth in meths]
npt.assert_(np.all(np.isfinite(vals)))
names, a, k = shape_argnames[:], shape_args[:], {}
while names:
k.update({names.pop(): a.pop()})
v = [meth(x, *a, **k) for meth in meths]
npt.assert_array_equal(vals, v)
if not 'n' in k.keys():
# `n` is first parameter of moment(), so can't be used as named arg
npt.assert_equal(distfn.moment(3, *a, **k),
distfn.moment(3, *shape_args))
# unknown arguments should not go through:
k.update({'kaboom': 42})
npt.assert_raises(TypeError, distfn.cdf, x, **k)
def check_scale_docstring(distfn):
if distfn.__doc__ is not None:
# Docstrings can be stripped if interpreter is run with -OO
npt.assert_('scale' not in distfn.__doc__)
if __name__ == "__main__":
# nose.run(argv=['', __file__])
nose.runmodule(argv=[__file__,'-s'], exit=False)
示例15: test_endog_only_raise
def test_endog_only_raise(self):
np.testing.assert_raises(Exception, sm_data.handle_data,
(self.y, None, 'raise'))
def test_endog_only_drop(self):
y = self.y
y = y.dropna()
data = sm_data.handle_data(self.y, None, 'drop')
np.testing.assert_array_equal(data.endog, y.values)
def test_mv_endog(self):
y = self.X
y = y.ix[~np.isnan(y.values).any(axis=1)]
data = sm_data.handle_data(self.X, None, 'drop')
np.testing.assert_array_equal(data.endog, y.values)
def test_labels(self):
2, 10, 14
labels = pandas.Index([0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24])
data = sm_data.handle_data(self.y, self.X, 'drop')
np.testing.assert_(data.row_labels.equals(labels))
if __name__ == "__main__":
import nose
#nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
# exit=False)
nose.runmodule(argv=[__file__, '-vvs', '-x'], exit=False)