def fixture_vm_class(fixture_data):
_, _, fork_name, _ = fixture_data
if fork_name == 'Frontier':
return FrontierVMForTesting
elif fork_name == 'Homestead':
return HomesteadVMForTesting
elif fork_name == 'EIP150':
return EIP150VMForTesting
elif fork_name == 'EIP158':
return SpuriousDragonVMForTesting
elif fork_name == 'Byzantium':
return ByzantiumVMForTesting
elif fork_name == 'Constantinople':
pytest.skip("Constantinople VM has not been implemented")
elif fork_name == 'Metropolis':
pytest.skip("Metropolis VM has not been implemented")
else:
raise ValueError("Unknown Fork Name: {0}".format(fork_name))
python类skip()的实例源码
test_serialization.py 文件源码
项目:django-performance-testing
作者: PaesslerAG
项目源码
文件源码
阅读 42
收藏 0
点赞 0
评论 0
def sample_result(collector_cls, collector_cls_with_sample_result):
if collector_cls != collector_cls_with_sample_result[0]:
pytest.skip('this sample result is not for this plugin')
result = collector_cls_with_sample_result[-1]
return result
def test_plat_name_ext(temp_ext_pkg):
try:
subprocess.check_call(
[sys.executable, 'setup.py', 'bdist_wheel', '--plat-name=testplat.arch'],
cwd=str(temp_ext_pkg))
except subprocess.CalledProcessError:
pytest.skip("Cannot compile C Extensions")
dist_dir = temp_ext_pkg.join('dist')
assert dist_dir.check(dir=1)
wheels = dist_dir.listdir()
assert len(wheels) == 1
assert wheels[0].basename.endswith('-testplat_arch.whl')
assert wheels[0].ext == '.whl'
def test_plat_name_ext_in_setupcfg(temp_ext_pkg):
temp_ext_pkg.join('setup.cfg').write('[bdist_wheel]\nplat_name=testplat.arch')
try:
subprocess.check_call(
[sys.executable, 'setup.py', 'bdist_wheel'],
cwd=str(temp_ext_pkg))
except subprocess.CalledProcessError:
pytest.skip("Cannot compile C Extensions")
dist_dir = temp_ext_pkg.join('dist')
assert dist_dir.check(dir=1)
wheels = dist_dir.listdir()
assert len(wheels) == 1
assert wheels[0].basename.endswith('-testplat_arch.whl')
assert wheels[0].ext == '.whl'
def test_verifying_zipfile():
if not hasattr(zipfile.ZipExtFile, '_update_crc'):
pytest.skip('No ZIP verification. Missing ZipExtFile._update_crc.')
sio = StringIO()
zf = zipfile.ZipFile(sio, 'w')
zf.writestr("one", b"first file")
zf.writestr("two", b"second file")
zf.writestr("three", b"third file")
zf.close()
# In default mode, VerifyingZipFile checks the hash of any read file
# mentioned with set_expected_hash(). Files not mentioned with
# set_expected_hash() are not checked.
vzf = wheel.install.VerifyingZipFile(sio, 'r')
vzf.set_expected_hash("one", hashlib.sha256(b"first file").digest())
vzf.set_expected_hash("three", "blurble")
vzf.open("one").read()
vzf.open("two").read()
try:
vzf.open("three").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
# In strict mode, VerifyingZipFile requires every read file to be
# mentioned with set_expected_hash().
vzf.strict = True
try:
vzf.open("two").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
vzf.set_expected_hash("two", None)
vzf.open("two").read()
def check_requirements_integrity():
raw_requirements = _get_all_raw_requirements()
if not raw_requirements:
raise AssertionError(
'check-requirements expects at least requirements-minimal.txt '
'and requirements.txt',
)
incorrect = []
for req, filename in raw_requirements:
version = to_version(req)
if version is None: # Not pinned, just skip
continue
if req.key not in installed_things:
raise AssertionError(
'{} is required in {}, but is not installed'.format(
req.key, filename,
)
)
installed_version = to_version(parse_requirement('{}=={}'.format(
req.key, installed_things[req.key].version,
)))
if installed_version != version:
incorrect.append((filename, req.key, version, installed_version))
if incorrect:
raise AssertionError(
'Installed requirements do not match requirement files!\n'
'Rebuild your virtualenv:\n{}'.format(''.join(
' - ({}) {}=={} (installed) {}=={}\n'.format(
filename, pkg, depped, pkg, installed,
)
for filename, pkg, depped, installed in incorrect
))
)
def test_requirements_pinned():
raw_requirements = _get_all_raw_requirements()
if raw_requirements is None: # pragma: no cover
pytest.skip('No requirements files found')
unpinned_requirements = find_unpinned_requirements(raw_requirements)
if unpinned_requirements:
raise AssertionError(
'Unpinned requirements detected!\n\n{}'.format(
format_unpinned_requirements(unpinned_requirements),
)
)
def create_server(dbtype=None):
if dbtype in (None, 'sqlite3', 'sqlite'):
return SqliteMemoryDB()
if dbtype in ('mysql', 'MySQLdb'):
return MysqlDB()
if dbtype in ('psycopg2', 'postgres'):
return PostgresDB()
pytest.skip('Unknown dbtype: %s' % dbtype)
def __init__(db, dbtype):
pytest.importorskip(dbtype)
import tempfile
db.installation_dir = py.path.local(tempfile.mkdtemp(prefix='abe-test-'))
print("Created temporary directory %s" % db.installation_dir)
try:
db.server = db.install_server()
except Exception as e:
#print("EXCEPTION %s" % e)
db._delete_tmpdir()
pytest.skip(e)
raise
DB.__init__(db, dbtype, db.get_connect_args())
def max200(testdb):
try:
Abe.util.sha3_256('x')
except Exception as e:
pytest.skip('SHA3 not working: e')
dirname = os.path.join(os.path.split(__file__)[0], 'max200')
store = testdb.load('--datadir', dirname)
return store
def tagschecker(request):
tags = set(request.config.getini('TAGS'))
tags_marker = request.node.get_marker('tags')
xfailtags_marker = request.node.get_marker('xfailtags')
skiptags_marker = request.node.get_marker('skiptags')
if xfailtags_marker and not tags.isdisjoint(set(xfailtags_marker.args)):
request.node.add_marker(pytest.mark.xfail())
elif (
tags_marker and tags.isdisjoint(set(tags_marker.args)) or
skiptags_marker and not tags.isdisjoint(set(skiptags_marker.args))
):
pytest.skip('skipped for this tags: {}'.format(tags))
def test_plat_name_ext(temp_ext_pkg):
try:
subprocess.check_call(
[sys.executable, 'setup.py', 'bdist_wheel', '--plat-name=testplat.arch'],
cwd=str(temp_ext_pkg))
except subprocess.CalledProcessError:
pytest.skip("Cannot compile C Extensions")
dist_dir = temp_ext_pkg.join('dist')
assert dist_dir.check(dir=1)
wheels = dist_dir.listdir()
assert len(wheels) == 1
assert wheels[0].basename.endswith('-testplat_arch.whl')
assert wheels[0].ext == '.whl'
def test_plat_name_ext_in_setupcfg(temp_ext_pkg):
temp_ext_pkg.join('setup.cfg').write('[bdist_wheel]\nplat_name=testplat.arch')
try:
subprocess.check_call(
[sys.executable, 'setup.py', 'bdist_wheel'],
cwd=str(temp_ext_pkg))
except subprocess.CalledProcessError:
pytest.skip("Cannot compile C Extensions")
dist_dir = temp_ext_pkg.join('dist')
assert dist_dir.check(dir=1)
wheels = dist_dir.listdir()
assert len(wheels) == 1
assert wheels[0].basename.endswith('-testplat_arch.whl')
assert wheels[0].ext == '.whl'
def test_verifying_zipfile():
if not hasattr(zipfile.ZipExtFile, '_update_crc'):
pytest.skip('No ZIP verification. Missing ZipExtFile._update_crc.')
sio = StringIO()
zf = zipfile.ZipFile(sio, 'w')
zf.writestr("one", b"first file")
zf.writestr("two", b"second file")
zf.writestr("three", b"third file")
zf.close()
# In default mode, VerifyingZipFile checks the hash of any read file
# mentioned with set_expected_hash(). Files not mentioned with
# set_expected_hash() are not checked.
vzf = wheel.install.VerifyingZipFile(sio, 'r')
vzf.set_expected_hash("one", hashlib.sha256(b"first file").digest())
vzf.set_expected_hash("three", "blurble")
vzf.open("one").read()
vzf.open("two").read()
try:
vzf.open("three").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
# In strict mode, VerifyingZipFile requires every read file to be
# mentioned with set_expected_hash().
vzf.strict = True
try:
vzf.open("two").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
vzf.set_expected_hash("two", None)
vzf.open("two").read()
def test_verifying_zipfile():
if not hasattr(zipfile.ZipExtFile, '_update_crc'):
pytest.skip('No ZIP verification. Missing ZipExtFile._update_crc.')
sio = StringIO()
zf = zipfile.ZipFile(sio, 'w')
zf.writestr("one", b"first file")
zf.writestr("two", b"second file")
zf.writestr("three", b"third file")
zf.close()
# In default mode, VerifyingZipFile checks the hash of any read file
# mentioned with set_expected_hash(). Files not mentioned with
# set_expected_hash() are not checked.
vzf = wheel.install.VerifyingZipFile(sio, 'r')
vzf.set_expected_hash("one", hashlib.sha256(b"first file").digest())
vzf.set_expected_hash("three", "blurble")
vzf.open("one").read()
vzf.open("two").read()
try:
vzf.open("three").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
# In strict mode, VerifyingZipFile requires every read file to be
# mentioned with set_expected_hash().
vzf.strict = True
try:
vzf.open("two").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
vzf.set_expected_hash("two", None)
vzf.open("two").read()
def test_verifying_zipfile():
if not hasattr(zipfile.ZipExtFile, '_update_crc'):
pytest.skip('No ZIP verification. Missing ZipExtFile._update_crc.')
sio = StringIO()
zf = zipfile.ZipFile(sio, 'w')
zf.writestr("one", b"first file")
zf.writestr("two", b"second file")
zf.writestr("three", b"third file")
zf.close()
# In default mode, VerifyingZipFile checks the hash of any read file
# mentioned with set_expected_hash(). Files not mentioned with
# set_expected_hash() are not checked.
vzf = wheel.install.VerifyingZipFile(sio, 'r')
vzf.set_expected_hash("one", hashlib.sha256(b"first file").digest())
vzf.set_expected_hash("three", "blurble")
vzf.open("one").read()
vzf.open("two").read()
try:
vzf.open("three").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
# In strict mode, VerifyingZipFile requires every read file to be
# mentioned with set_expected_hash().
vzf.strict = True
try:
vzf.open("two").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
vzf.set_expected_hash("two", None)
vzf.open("two").read()
def test_verifying_zipfile():
if not hasattr(zipfile.ZipExtFile, '_update_crc'):
pytest.skip('No ZIP verification. Missing ZipExtFile._update_crc.')
sio = StringIO()
zf = zipfile.ZipFile(sio, 'w')
zf.writestr("one", b"first file")
zf.writestr("two", b"second file")
zf.writestr("three", b"third file")
zf.close()
# In default mode, VerifyingZipFile checks the hash of any read file
# mentioned with set_expected_hash(). Files not mentioned with
# set_expected_hash() are not checked.
vzf = wheel.install.VerifyingZipFile(sio, 'r')
vzf.set_expected_hash("one", hashlib.sha256(b"first file").digest())
vzf.set_expected_hash("three", "blurble")
vzf.open("one").read()
vzf.open("two").read()
try:
vzf.open("three").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
# In strict mode, VerifyingZipFile requires every read file to be
# mentioned with set_expected_hash().
vzf.strict = True
try:
vzf.open("two").read()
except wheel.install.BadWheelFile:
pass
else:
raise Exception("expected exception 'BadWheelFile()'")
vzf.set_expected_hash("two", None)
vzf.open("two").read()
def connection(gremlin_url, event_loop, provider):
try:
conn = event_loop.run_until_complete(
driver.Connection.open(
gremlin_url,
event_loop,
message_serializer=GraphSONMessageSerializer,
provider=provider))
except OSError:
pytest.skip('Gremlin Server is not running')
return conn
def remote_connection(event_loop, gremlin_url):
try:
remote_conn = event_loop.run_until_complete(
DriverRemoteConnection.open(gremlin_url, 'g'))
except OSError:
pytest.skip('Gremlin Server is not running')
else:
return remote_conn