本文整理汇总了Python中py.test.raises方法的典型用法代码示例。如果您正苦于以下问题:Python test.raises方法的具体用法?Python test.raises怎么用?Python test.raises使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py.test
的用法示例。
在下文中一共展示了test.raises方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compute_normalization
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_compute_normalization():
data = np.array([[10, 10, 10], [20, 20, 20]])
counts_a = [1, 2]
counts_b = [1, 2, 5]
out = compute_normalization(data, counts_a, 'A')
assert np.array_equal(out, np.array([[10, 10, 10], [10, 10, 10]]))
out = compute_normalization(data, counts_b, 'B')
assert np.array_equal(out, np.array([[10, 5, 2], [20, 10, 4]]))
# Test error is shapes don't work
with raises(ValueError):
compute_normalization(data, counts_b, 'A')
# Test error for if dimension specifier is bad
with raises(ValueError):
compute_normalization(data, counts_b, 'C')
示例2: test_term_consistency
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_term_consistency(tbase_terms):
tbase_terms._check_term_consistency()
tbase_terms.exclusions = ['need', 'required']
tbase_terms._check_term_consistency()
tbase_terms.exclusions = ['not', 'avoid']
tbase_terms._check_term_consistency()
with raises(InconsistentDataError):
tbase_terms.inclusions = ['need']
tbase_terms._check_term_consistency()
with raises(InconsistentDataError):
tbase_terms.exclusions = ['not', 'avoid', 'bad']
tbase_terms._check_term_consistency()
示例3: test_get_item
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_get_item():
words = Words()
# Test error for empty object
with raises(IndexError):
words['not a thing']
words.add_results(Articles(Term('test', [], [], [])))
# Test error for wrong key
with raises(IndexError):
words['wrong']
# Test properly extracting item
assert words['test']
示例4: test_update_sim_ap_params
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_update_sim_ap_params():
sim_params = SimParams([1, 1], [10, 1, 1], 0.05)
# Check updating of a single specified parameter
new_sim_params = update_sim_ap_params(sim_params, 1, 'exponent')
assert new_sim_params.aperiodic_params == [1, 2]
# Check updating of multiple specified parameters
new_sim_params = update_sim_ap_params(sim_params, [1, 1], ['offset', 'exponent'])
assert new_sim_params.aperiodic_params == [2, 2]
# Check updating of all parameters
new_sim_params = update_sim_ap_params(sim_params, [1, 1])
assert new_sim_params.aperiodic_params == [2, 2]
# Check error with invalid overwrite
with raises(InconsistentDataError):
new_sim_params = update_sim_ap_params(sim_params, [1, 1, 1])
示例5: test_fooof_fit_measures
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_fooof_fit_measures():
"""Test goodness of fit & error metrics, post model fitting."""
tfm = FOOOF(verbose=False)
# Hack fake data with known properties: total error magnitude 2
tfm.power_spectrum = np.array([1, 2, 3, 4, 5])
tfm.fooofed_spectrum_ = np.array([1, 2, 5, 4, 5])
# Check default goodness of fit and error measures
tfm._calc_r_squared()
assert np.isclose(tfm.r_squared_, 0.75757575)
tfm._calc_error()
assert np.isclose(tfm.error_, 0.4)
# Check with alternative error fit approach
tfm._calc_error(metric='MSE')
assert np.isclose(tfm.error_, 0.8)
tfm._calc_error(metric='RMSE')
assert np.isclose(tfm.error_, np.sqrt(0.8))
with raises(ValueError):
tfm._calc_error(metric='BAD')
示例6: test_combine_errors
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_combine_errors(tfm, tfg):
# Incompatible settings
for f_obj in [tfm, tfg]:
f_obj2 = f_obj.copy()
f_obj2.peak_width_limits = [2, 4]
f_obj2._reset_internal_settings()
with raises(IncompatibleSettingsError):
combine_fooofs([f_obj, f_obj2])
# Incompatible data information
for f_obj in [tfm, tfg]:
f_obj2 = f_obj.copy()
f_obj2.freq_range = [5, 30]
with raises(IncompatibleSettingsError):
combine_fooofs([f_obj, f_obj2])
示例7: test_should_query_only_fields
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_should_query_only_fields():
with raises(Exception):
class ReporterType(DjangoObjectType):
class Meta:
model = Reporter
fields = ("articles",)
schema = graphene.Schema(query=ReporterType)
query = """
query ReporterQuery {
articles
}
"""
result = schema.execute(query)
assert not result.errors
示例8: test_prohibits_putting_non_object_types_in_unions
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_prohibits_putting_non_object_types_in_unions():
bad_union_types = [
GraphQLInt,
GraphQLNonNull(GraphQLInt),
GraphQLList(GraphQLInt),
InterfaceType,
UnionType,
EnumType,
InputObjectType,
]
for x in bad_union_types:
with raises(Exception) as excinfo:
GraphQLSchema(
GraphQLObjectType(
"Root",
fields={"union": GraphQLField(GraphQLUnionType("BadUnion", [x]))},
)
)
assert "BadUnion may only contain Object types, it cannot contain: " + str(
x
) + "." == str(excinfo.value)
示例9: test_save_object
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_save_object(tdb, tcounts, twords):
save_object(tcounts, 'test_counts', directory=tdb)
save_object(twords, 'test_words', directory=tdb)
assert os.path.exists(os.path.join(tdb.get_folder_path('counts'), 'test_counts.p'))
assert os.path.exists(os.path.join(tdb.get_folder_path('words'), 'test_words.p'))
with raises(ValueError):
save_object(['bad dat'], 'test_bad', directory=tdb)
示例10: test_extract
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_extract():
# Create a complex tag
out = bs4.element.Tag(name='Out')
inn1 = bs4.element.Tag(name='Inn')
inn2 = bs4.element.Tag(name='Inn')
inn1.append('words words')
inn2.append('more words')
out.append(inn1)
out.append(inn2)
# Test error - bad how
with raises(ValueError):
out_err = extract(out, 'Inn', 'bad')
# Test how = 'raw'
out_raw = extract(out, 'Inn', 'raw')
assert type(out_raw) is bs4.element.Tag
# Test how = 'str'
out_str = extract(out, 'Inn', 'str')
assert isinstance(out_str, str)
assert out_str == 'words words'
# Test how = 'all'
out_all = extract(out, 'Inn', 'all')
assert type(out_all) is bs4.element.ResultSet
# Test with non-existent tag name
out_none = extract(out, 'bad', 'raw')
assert out_none is None
示例11: test_check_results
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_check_results(tarts_full):
tarts_full._check_results()
tarts_full.ids = [1]
with raises(InconsistentDataError):
assert tarts_full._check_results()
示例12: test_urls_settings
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_urls_settings():
urls = EUtils(db='database', retmax=500, retmode='xml')
assert urls.settings['db'] == 'database'
assert urls.settings['retmax'] == '500'
with raises(KeyError):
urls.settings['field']
示例13: test_dependency
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_dependency():
dep = Dependency('test_module')
with raises(ImportError):
dep.method_call
示例14: test_check_url
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_check_url():
base = 'fake_base'
utils = {'fake_util' : 'not_a_url'}
urls = URLs(base, utils)
urls.check_url('fake_util')
with raises(ValueError):
urls.check_url('wrong_name')
示例15: test_get_cmap
# 需要导入模块: from py import test [as 别名]
# 或者: from py.test import raises [as 别名]
def test_get_cmap():
assert get_cmap('purple')
assert get_cmap('blue')
with raises(ValueError):
get_cmap('Not a thing.')