summaryrefslogtreecommitdiffstats
path: root/tests/test_util.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-12-09 09:09:53 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-12-10 08:29:15 -0700
commitb6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7 (patch)
tree7e5329a51af169ce34a7d275a1bbd63c1e31c026 /tests/test_util.py
parentd08b8858ddc3bf6265f6ea8acae6661b9fff5112 (diff)
downloadfreeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.gz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.xz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.zip
Take 2: Extensible return values and validation; steps toward a single output_for_cli(); enable more webUI stuff
Diffstat (limited to 'tests/test_util.py')
-rw-r--r--tests/test_util.py131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/test_util.py b/tests/test_util.py
index 7d7038c1a..b2a53101a 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -22,6 +22,7 @@ Test the `tests.util` module.
"""
import util
+from util import raises, TYPE, VALUE, LEN, KEYS
class Prop(object):
@@ -47,6 +48,136 @@ class Prop(object):
prop = property(__get_prop, __set_prop, __del_prop)
+def test_assert_deepequal():
+ f = util.assert_deepequal
+
+ # Test with good scalar values:
+ f(u'hello', u'hello', 'foo')
+ f(18, 18, 'foo')
+
+ # Test with bad scalar values:
+ e = raises(AssertionError, f, u'hello', u'world', 'foo')
+ assert str(e) == VALUE % (
+ 'foo', u'hello', u'world', tuple()
+ )
+
+ e = raises(AssertionError, f, 'hello', u'hello', 'foo')
+ assert str(e) == TYPE % (
+ 'foo', str, unicode, 'hello', u'hello', tuple()
+ )
+
+ e = raises(AssertionError, f, 18, 18.0, 'foo')
+ assert str(e) == TYPE % (
+ 'foo', int, float, 18, 18.0, tuple()
+ )
+
+ # Test with good compound values:
+ a = [
+ u'hello',
+ dict(naughty=u'nurse'),
+ 18,
+ ]
+ b = [
+ u'hello',
+ dict(naughty=u'nurse'),
+ 18,
+ ]
+ f(a, b)
+
+ # Test with bad compound values:
+ b = [
+ 'hello',
+ dict(naughty=u'nurse'),
+ 18,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == TYPE % (
+ 'foo', unicode, str, u'hello', 'hello', (0,)
+ )
+
+ b = [
+ u'hello',
+ dict(naughty='nurse'),
+ 18,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == TYPE % (
+ 'foo', unicode, str, u'nurse', 'nurse', (1, 'naughty')
+ )
+
+ b = [
+ u'hello',
+ dict(naughty=u'nurse'),
+ 18.0,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == TYPE % (
+ 'foo', int, float, 18, 18.0, (2,)
+ )
+
+ # List length mismatch
+ b = [
+ u'hello',
+ dict(naughty=u'nurse'),
+ 18,
+ 19
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == LEN % (
+ 'foo', 3, 4, a, b, tuple()
+ )
+
+ b = [
+ dict(naughty=u'nurse'),
+ 18,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == LEN % (
+ 'foo', 3, 2, a, b, tuple()
+ )
+
+ # Dict keys mismatch:
+
+ # Missing
+ b = [
+ u'hello',
+ dict(),
+ 18,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == KEYS % ('foo',
+ ['naughty'], [],
+ dict(naughty=u'nurse'), dict(),
+ (1,)
+ )
+
+ # Extra
+ b = [
+ u'hello',
+ dict(naughty=u'nurse', barely=u'legal'),
+ 18,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == KEYS % ('foo',
+ [], ['barely'],
+ dict(naughty=u'nurse'), dict(naughty=u'nurse', barely=u'legal'),
+ (1,)
+ )
+
+ # Missing + Extra
+ b = [
+ u'hello',
+ dict(barely=u'legal'),
+ 18,
+ ]
+ e = raises(AssertionError, f, a, b, 'foo')
+ assert str(e) == KEYS % ('foo',
+ ['naughty'], ['barely'],
+ dict(naughty=u'nurse'), dict(barely=u'legal'),
+ (1,)
+ )
+
+
def test_yes_raised():
f = util.raises