* tests/python/except.py: Make sure exceptions are raised.

This commit is contained in:
Alexandre Duret-Lutz 2018-05-25 11:16:05 +02:00
parent a9293f329e
commit 23e0d718fd

View file

@ -23,19 +23,28 @@
import spot import spot
import buddy
def report_missing_exception():
raise RuntimeError("missing exception")
aut = spot.translate('GFa & GFb & GFc')
aut.set_acceptance(spot.acc_cond("parity min even 4"))
try: try:
spot.iar(spot.translate('GFa & GFb & GFc')) spot.iar(aut)
except RuntimeError as e: except RuntimeError as e:
assert 'iar() expects Rabin-like or Streett-like input' in str(e) assert 'iar() expects Rabin-like or Streett-like input' in str(e)
else:
report_missing_exception()
alt = spot.dualize(spot.translate('FGa | FGb')) alt = spot.dualize(spot.translate('FGa | FGb'))
try: try:
spot.tgba_determinize(alt) spot.tgba_determinize(alt)
except RuntimeError as e: except RuntimeError as e:
assert 'tgba_determinize() does not support alternation' in str(e) assert 'tgba_determinize() does not support alternation' in str(e)
else:
report_missing_exception()
aut = spot.translate('a U b U c') aut = spot.translate('a U b U c')
aps = aut.ap() aps = aut.ap()
@ -47,11 +56,15 @@ try:
rem.add_ap('"a=0,b') rem.add_ap('"a=0,b')
except ValueError as e: except ValueError as e:
assert """missing closing '"'""" in str(e) assert """missing closing '"'""" in str(e)
else:
report_missing_exception()
try: try:
rem.add_ap('a=0=b') rem.add_ap('a=0=b')
except ValueError as e: except ValueError as e:
assert """unexpected '=' at position 3""" in str(e) assert """unexpected '=' at position 3""" in str(e)
else:
report_missing_exception()
si = spot.scc_info(aut) si = spot.scc_info(aut)
for meth in ('scc_has_rejecting_cycle', 'is_inherently_weak_scc', for meth in ('scc_has_rejecting_cycle', 'is_inherently_weak_scc',
@ -60,37 +73,59 @@ for meth in ('scc_has_rejecting_cycle', 'is_inherently_weak_scc',
getattr(spot, meth)(si, 20) getattr(spot, meth)(si, 20)
except ValueError as e: except ValueError as e:
assert "invalid SCC number" in str(e) assert "invalid SCC number" in str(e)
else:
report_missing_exception()
s1 = alt.new_state()
s2 = alt.new_state()
alt.new_edge(0, s1, buddy.bddtrue)
alt.new_edge(s1, s2, buddy.bddtrue, [0])
alt.new_edge(s2, s1, buddy.bddtrue)
alt.prop_inherently_weak(False)
alt.prop_state_acc(False)
si = spot.scc_info(alt) si = spot.scc_info(alt)
try: try:
si.determine_unknown_acceptance() si.determine_unknown_acceptance()
except RuntimeError as e: except RuntimeError as e:
assert "scc_info::determine_unknown_acceptance() does not supp" in str(e) assert "scc_info::determine_unknown_acceptance() does not supp" in str(e)
else:
report_missing_exception()
r = spot.twa_run(aut) r = spot.twa_run(aut)
try: try:
a = r.as_twa() a = r.as_twa()
except RuntimeError as e: except RuntimeError as e:
assert "empty cycle" in str(e) assert "empty cycle" in str(e)
else:
report_missing_exception()
try: try:
a = r.replay(spot.get_cout()) a = r.replay(spot.get_cout())
except RuntimeError as e: except RuntimeError as e:
assert "empty cycle" in str(e) assert "empty cycle" in str(e)
else:
report_missing_exception()
try: try:
a = r.reduce() a = r.reduce()
except RuntimeError as e: except RuntimeError as e:
assert "empty cycle" in str(e) assert "empty cycle" in str(e)
else:
report_missing_exception()
f = spot.formula('GF(a | Gb)') f = spot.formula('GF(a | Gb)')
try: try:
spot.gf_guarantee_to_ba(f, spot._bdd_dict) spot.gf_guarantee_to_ba(f, spot._bdd_dict)
except RuntimeError as e: except RuntimeError as e:
assert "guarantee" in str(e) assert "guarantee" in str(e)
else:
report_missing_exception()
f = spot.formula('FG(a | Fb)') f = spot.formula('FG(a | Fb)')
try: try:
spot.fg_safety_to_dca(f, spot._bdd_dict) spot.fg_safety_to_dca(f, spot._bdd_dict)
except RuntimeError as e: except RuntimeError as e:
assert "safety" in str(e) assert "safety" in str(e)
else:
report_missing_exception()