tests: replace all "assert" by unittest assertions

If the assert fails because of a comparison, it is useful that the
test suite log contains a comparison of these values.
unittest.assertEqual() and friends do that for us.

* HACKING: Add a section about Python tests.
* tests/sanity/style.test: Forbid the use of "assert" in
Python tests.
* tests/python/298.py, tests/python/341.py, tests/python/471.py,
tests/python/accparse2.py, tests/python/aiger.py,
tests/python/aliases.py, tests/python/alternating.py,
tests/python/bdddict.py, tests/python/bdditer.py,
tests/python/bugdet.py, tests/python/complement_semidet.py,
tests/python/declenv.py, tests/python/decompose_scc.py,
tests/python/det.py, tests/python/dualize.py, tests/python/ecfalse.py,
tests/python/except.py, tests/python/game.py, tests/python/gen.py,
tests/python/genem.py, tests/python/implies.py,
tests/python/intrun.py, tests/python/kripke.py,
tests/python/langmap.py, tests/python/ltl2tgba.py,
tests/python/ltlf.py, tests/python/ltlparse.py,
tests/python/ltlsimple.py, tests/python/mealy.py,
tests/python/merge.py, tests/python/mergedge.py,
tests/python/misc-ec.py, tests/python/optionmap.py,
tests/python/origstate.py, tests/python/otfcrash.py,
tests/python/parity.py, tests/python/parsetgba.py,
tests/python/pdegen.py, tests/python/prodexpt.py,
tests/python/randgen.py, tests/python/relabel.py,
tests/python/remfin.py, tests/python/removeap.py,
tests/python/rs_like.py, tests/python/satmin.py,
tests/python/sbacc.py, tests/python/sccfilter.py,
tests/python/sccinfo.py, tests/python/sccsplit.py,
tests/python/semidet.py, tests/python/setacc.py,
tests/python/setxor.py, tests/python/simplacc.py,
tests/python/simstate.py, tests/python/sonf.py, tests/python/split.py,
tests/python/streett_totgba.py, tests/python/streett_totgba2.py,
tests/python/stutter.py, tests/python/sum.py,
tests/python/synthesis.py, tests/python/toparity.py,
tests/python/toweak.py, tests/python/tra2tba.py,
tests/python/trival.py, tests/python/twagraph.py,
tests/python/zlktree.py: Replace all occurrences of "assert" by calls
to unittest.TestCase methods.
This commit is contained in:
Alexandre Duret-Lutz 2022-03-04 16:59:04 +01:00
parent 7b7e1b254b
commit 530cf7ca47
69 changed files with 1314 additions and 1116 deletions

View file

@ -1,5 +1,5 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2009, 2010, 2012, 2015, 2018, 2021 Laboratoire de
# Copyright (C) 2009, 2010, 2012, 2015, 2018, 2021-2022 Laboratoire de
# Recherche et Développement de l'Epita (LRDE).
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
# département Systemes Répartis Coopératifs (SRC), Université Pierre
@ -22,6 +22,8 @@
import spot
import sys
from unittest import TestCase
tc = TestCase()
# Some of the tests here assume timely destructor calls, as they occur
# in the the reference-counted CPython implementation. Other
@ -35,13 +37,13 @@ b = spot.formula.ap('b')
c = spot.formula.ap('c')
c2 = spot.formula.ap('c')
assert c == c2
tc.assertEqual(c, c2)
op = spot.formula.And([a, b])
op2 = spot.formula.And([op, c])
op3 = spot.formula.And([a, c, b])
assert op2 == op3
tc.assertEqual(op2, op3)
# The symbol for a subformula which hasn't been cloned is better
# suppressed, so we don't attempt to reuse it elsewhere.
@ -52,12 +54,12 @@ sys.stdout.write('op2 = %s\n' % str(op2))
del a, b, c2
sys.stdout.write('op3 = %s\n' % str(op3))
assert op2 == op3
tc.assertEqual(op2, op3)
op4 = spot.formula.Or([op2, op3])
sys.stdout.write('op4 = %s\n' % str(op4))
assert op4 == op2
tc.assertEqual(op4, op2)
del op2, op3, op4
@ -78,10 +80,11 @@ f5 = spot.formula.Xor(F, c)
del a, b, c, T, F, f1, f2, f4, f5
if is_cpython:
assert spot.fnode_instances_check()
tc.assertTrue(spot.fnode_instances_check())
# ----------------------------------------------------------------------
assert str([str(x) for x in spot.formula('a &b & c')]) == "['a', 'b', 'c']"
tc.assertEqual(str([str(x) for x in spot.formula('a &b & c')]),
"['a', 'b', 'c']")
def switch_g_f(x):
@ -93,7 +96,7 @@ def switch_g_f(x):
f = spot.formula('GFa & XFGb & Fc & G(a | b | Fd)')
assert str(switch_g_f(f)) == 'FGa & XGFb & Gc & F(a | b | Gd)'
tc.assertEqual(str(switch_g_f(f)), 'FGa & XGFb & Gc & F(a | b | Gd)')
x = 0
@ -105,7 +108,7 @@ def count_g(f):
f.traverse(count_g)
assert x == 3
tc.assertEqual(x, 3)
# ----------------------------------------------------------------------
@ -121,14 +124,14 @@ LBT for shell: echo {f:lq} | ...
Default for CSV: ...,{f:c},...
Wring, centered: {f:w:~^50}""".format(f=formula)
assert res == """\
tc.assertEqual(res, """\
Default output: a U (b U "$strange[0]=name")
Spin syntax: a U (b U ($strange[0]=name))
(Spin syntax): (a) U ((b) U ($strange[0]=name))
Default for shell: echo 'a U (b U "$strange[0]=name")' | ...
LBT for shell: echo 'U "a" U "b" "$strange[0]=name"' | ...
Default for CSV: ...,"a U (b U ""$strange[0]=name"")",...
Wring, centered: ~~~~~(a=1) U ((b=1) U ("$strange[0]=name"=1))~~~~~"""
Wring, centered: ~~~~~(a=1) U ((b=1) U ("$strange[0]=name"=1))~~~~~""")
opt = spot.tl_simplifier_options(False, True, True,
@ -144,9 +147,8 @@ for (input, output) in [('(a&b)<->b', 'b->(a&b)'),
('b xor (!(a&b))', 'b->(a&b)'),
('!b xor (a&b)', 'b->(a&b)')]:
f = spot.tl_simplifier(opt).simplify(input)
print(input, f, output)
assert(f == output)
assert(spot.are_equivalent(input, output))
tc.assertEqual(f, output)
tc.assertTrue(spot.are_equivalent(input, output))
def myparse(input):
@ -157,7 +159,7 @@ def myparse(input):
# This used to fail, because myparse would return a pointer
# to pf.f inside the destroyed pf.
assert myparse('a U b') == spot.formula('a U b')
tc.assertEqual(myparse('a U b'), spot.formula('a U b'))
assert spot.is_liveness('a <-> GFb')
assert not spot.is_liveness('a & GFb')
tc.assertTrue(spot.is_liveness('a <-> GFb'))
tc.assertFalse(spot.is_liveness('a & GFb'))