本文整理汇总了Python中py.test.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raises函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_combo
def test_combo(self):
x_obj = qterm.Variable('x', pq('obj'))
x_var = qterm.Variable('x', pq('?a'))
phi_var = qterm.Constant('phi', pq('?b->bool'))
phi_obj = qterm.Constant('phi', pq('obj->bool'))
combo_var = term_builder.build_combination(phi_var, x_var)
combo_obj = term_builder.build_combination(phi_obj, x_obj)
combo_var2 = term_builder.build_combination(phi_var, x_obj)
x, combo = unify_types([x_obj, combo_var])
assert x == x_obj
assert combo == combo_obj
phi_a, phi_b = unify_types([phi_var, phi_obj])
assert phi_a == phi_var
assert phi_b == phi_obj
combo_a, combo_b = unify_types([combo_var, combo_obj])
assert combo_a == combo_obj
assert combo_b == combo_obj
combo_a, combo_b = unify_types([combo_var2, combo_obj])
assert combo_a == combo_obj
assert combo_b == combo_obj
f = qterm.Variable('f', pq('?x->?y'))
raises(UnificationError, term_builder.build_combination, f, f)
raises(UnificationError, term_builder.build_combination, x_var, x_var)
示例2: test_help
def test_help(self):
"""tests getting help (returning the help_string so further tests can be done)"""
stdout = sys.stdout
helpfile = self.open_testfile("help.txt", "w")
sys.stdout = helpfile
try:
test.raises(SystemExit, self.run_command, help=True)
finally:
sys.stdout = stdout
helpfile.close()
help_string = self.read_testfile("help.txt")
print help_string
convertsummary = self.convertmodule.__doc__.split("\n")[0]
# the convertsummary might be wrapped. this will probably unwrap it
assert convertsummary in help_string.replace("\n", " ")
usageline = help_string[:help_string.find("\n")]
# Different versions of optparse might contain either upper or
# lowercase versions of 'Usage:' and 'Options:', so we need to take
# that into account
assert (usageline.startswith("Usage: ") or usageline.startswith("usage: ")) \
and "[--version] [-h|--help]" in usageline
options = help_string[help_string.find("ptions:\n"):]
options = options[options.find("\n")+1:]
options = self.help_check(options, "--progress=PROGRESS")
options = self.help_check(options, "--version")
options = self.help_check(options, "-h, --help")
options = self.help_check(options, "--manpage")
options = self.help_check(options, "--errorlevel=ERRORLEVEL")
if psyco:
options = self.help_check(options, "--psyco=MODE")
options = self.help_check(options, "-i INPUT, --input=INPUT")
options = self.help_check(options, "-x EXCLUDE, --exclude=EXCLUDE")
options = self.help_check(options, "-o OUTPUT, --output=OUTPUT")
return options
示例3: test_too_much_colons
def test_too_much_colons(self, p):
s = """
name = s
key_format = 32s
type = HashIndex
hash_lim = 1
make_key_value:
1<=2:1:1,None
make_key:
1"""
with raises(IndexCreatorFunctionException):
p.parse(s, 'TestIndex')
s2 = """
name = s
key_format = 32s
type = HashIndex
hash_lim = 1
make_key_value:
1<=2:1,None
make_key:
a>1::"""
with raises(IndexCreatorFunctionException):
p.parse(s2, 'TestIndex')
s3 = """
name = s
key_format = : 32s
type = HashIndex
hash_lim = 1
make_key_value:
1<=2:1,None
make_key:
a>1:1"""
with raises(IndexCreatorValueException):
p.parse(s3, 'TestIndex')
示例4: test_filter_values_req_opt_2
def test_filter_values_req_opt_2():
r = [
to_dict(
Attribute(
friendly_name="surName",
name="urn:oid:2.5.4.4",
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
ONTS),
to_dict(
Attribute(
friendly_name="givenName",
name="urn:oid:2.5.4.42",
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
ONTS),
to_dict(
Attribute(
friendly_name="mail",
name="urn:oid:0.9.2342.19200300.100.1.3",
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
ONTS)]
o = [
to_dict(
Attribute(
friendly_name="title",
name="urn:oid:2.5.4.12",
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
ONTS)]
ava = {"surname": ["Hedberg"], "givenName": ["Roland"],
"eduPersonAffiliation": ["staff"], "uid": ["rohe0002"]}
raises(MissingValue, "filter_on_attributes(ava, r, o)")
示例5: test_finditer
def test_finditer(self):
import re
it = re.finditer("b(.)", "brabbel")
assert "br" == it.next().group(0)
assert "bb" == it.next().group(0)
raises(StopIteration, it.next)
示例6: test
def test():
for puzzle in puzzles.itervalues():
puzzle = load(puzzle)
puzzle.solve()
assert puzzle.is_solved()
for puzzle in bad_puzzles.itervalues():
raises(InconsistentPuzzleError, load(puzzle).solve)
示例7: test_filesystem_loader
def test_filesystem_loader():
env = Environment(loader=filesystem_loader)
tmpl = env.get_template('test.html')
assert tmpl.render().strip() == 'BAR'
tmpl = env.get_template('foo/test.html')
assert tmpl.render().strip() == 'FOO'
raises(TemplateNotFound, env.get_template, 'missing.html')
示例8: test_choice_loader
def test_choice_loader():
env = Environment(loader=choice_loader)
tmpl = env.get_template('justdict.html')
assert tmpl.render().strip() == 'FOO'
tmpl = env.get_template('test.html')
assert tmpl.render().strip() == 'BAR'
raises(TemplateNotFound, env.get_template, 'missing.html')
示例9: test_coordinate_attribute_assignment_01
def test_coordinate_attribute_assignment_01( ):
'''Coordinates are immutable.
Attributes cannot be set (rebound).'''
t = Coordinate(1, 2)
assert raises(AttributeError, 't.xy = 2')
assert raises(AttributeError, 't.foo = 3')
assert raises(TypeError, 't[0] = 2')
示例10: test_surface
def test_surface():
# TypeError: The Surface type cannot be instantiated
test.raises(TypeError, "s = cairo.Surface()")
if cairo.HAS_IMAGE_SURFACE:
f, w, h = cairo.FORMAT_ARGB32, 100, 100
s = cairo.ImageSurface(f, w, h)
assert s.get_format() == f
assert s.get_width() == w
assert s.get_height() == h
if cairo.HAS_PDF_SURFACE:
f, w, h = tfi.TemporaryFile(mode="w+b"), 100, 100
s = cairo.PDFSurface(f, w, h)
if cairo.HAS_PS_SURFACE:
f, w, h = tfi.TemporaryFile(mode="w+b"), 100, 100
s = cairo.PSSurface(f, w, h)
if cairo.HAS_RECORDING_SURFACE:
s = cairo.RecordingSurface(cairo.CONTENT_COLOR, None)
s = cairo.RecordingSurface(cairo.CONTENT_COLOR, (1, 1, 10, 10))
if cairo.HAS_SVG_SURFACE:
f, w, h = tfi.TemporaryFile(mode="w+b"), 100, 100
s = cairo.SVGSurface(f, w, h)
示例11: test_ueimporterror
def test_ueimporterror():
ue = uecommunication()
raises(UeImportError, ue.valid_response, "<Response><Import>Import not ok</Import></Response>")
assert (
ue.valid_response("<Response><Import>Import ok</Import></Response>")
== "<Response><Import>Import ok</Import></Response>"
)
示例12: test_creation_fail2
def test_creation_fail2():
"""
Try to create two Managers with the same position.
This should fail without leaving any partial records in
the database.
"""
setupClass([DIManager, DIEmployee, DIPerson])
kwargs = {'firstName': 'John', 'lastName': 'Doe',
'position': 'Project Manager'}
DIManager(**kwargs)
persons = DIEmployee.select(DIPerson.q.firstName == 'John')
assert persons.count() == 1
kwargs = {'firstName': 'John', 'lastName': 'Doe II',
'position': 'Project Manager'}
raises(Exception, DIManager, **kwargs)
persons = DIPerson.select(DIPerson.q.firstName == 'John')
assert persons.count() == 1
if not supports('transactions'):
skip("Transactions aren't supported")
transaction = DIPerson._connection.transaction()
kwargs = {'firstName': 'John', 'lastName': 'Doe III',
'position': 'Project Manager'}
raises(Exception, DIManager, connection=transaction, **kwargs)
transaction.rollback()
transaction.begin()
persons = DIPerson.select(DIPerson.q.firstName == 'John',
connection=transaction)
assert persons.count() == 1
示例13: test_cjk
def test_cjk(self):
import sys
import unicodedata
cases = ((0x3400, 0x4DB5),
(0x4E00, 0x9FA5))
if unicodedata.unidata_version >= "4.1":
cases = ((0x3400, 0x4DB5),
(0x4E00, 0x9FBB),
(0x20000, 0x2A6D6))
for first, last in cases:
# Test at and inside the boundary
for i in (first, first + 1, last - 1, last):
charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
char = ('\\U%08X' % i).decode('unicode-escape')
assert unicodedata.name(char) == charname
assert unicodedata.lookup(charname) == char
# Test outside the boundary
for i in first - 1, last + 1:
charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
char = ('\\U%08X' % i).decode('unicode-escape')
try:
unicodedata.name(char)
except ValueError, e:
assert e.message == 'no such name'
raises(KeyError, unicodedata.lookup, charname)
示例14: test_copy
def test_copy(self):
import re
# copy support is disabled by default in _sre.c
m = re.match("bla", "bla")
raises(TypeError, m.__copy__)
raises(TypeError, m.__deepcopy__)
示例15: test_prefix_loader
def test_prefix_loader():
env = Environment(loader=prefix_loader)
tmpl = env.get_template('a/test.html')
assert tmpl.render().strip() == 'BAR'
tmpl = env.get_template('b/justdict.html')
assert tmpl.render().strip() == 'FOO'
raises(TemplateNotFound, env.get_template, 'missing')