From 7721443a625b2efd0744ad347c62795e5ba6bb91 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 7 Oct 2008 20:41:15 -0600 Subject: Moved ipalib/tests/ into tests/test_ipalib/ --- tests/test_ipalib/test_util.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test_ipalib/test_util.py (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py new file mode 100644 index 00000000..f8ee0bf4 --- /dev/null +++ b/tests/test_ipalib/test_util.py @@ -0,0 +1,49 @@ +# Authors: +# Jason Gerard DeRose +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +Unit tests for `ipalib.util` module. +""" + +from tstutil import raises +from ipalib import util + + +def test_xmlrpc_marshal(): + """ + Test the `util.xmlrpc_marshal` function. + """ + f = util.xmlrpc_marshal + assert f() == ({},) + assert f('one', 'two') == ({}, 'one', 'two') + assert f(one=1, two=2) == (dict(one=1, two=2),) + assert f('one', 'two', three=3, four=4) == \ + (dict(three=3, four=4), 'one', 'two') + + +def test_xmlrpc_unmarshal(): + """ + Test the `util.xmlrpc_unmarshal` function. + """ + f = util.xmlrpc_unmarshal + assert f() == (tuple(), {}) + assert f({}, 'one', 'two') == (('one', 'two'), {}) + assert f(dict(one=1, two=2)) == (tuple(), dict(one=1, two=2)) + assert f(dict(three=3, four=4), 'one', 'two') == \ + (('one', 'two'), dict(three=3, four=4)) -- cgit From af56c71d506c2573f99a1ca8334cfa90dc7f74d7 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 7 Oct 2008 21:25:23 -0600 Subject: Cleaned up package and module level docstrings for everything in tests/ --- tests/test_ipalib/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index f8ee0bf4..0423ad62 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -18,7 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -Unit tests for `ipalib.util` module. +Test the `ipalib.util` module. """ from tstutil import raises -- cgit From f6ac2df6bd7ceddd0f3eb968198cc3ebd1388087 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 7 Oct 2008 21:59:47 -0600 Subject: Moved tstutil.py into base of tests so it can be used by all test subpackages more easily --- tests/test_ipalib/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 0423ad62..5b8b13f7 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,7 +21,7 @@ Test the `ipalib.util` module. """ -from tstutil import raises +from tests.tstutil import raises from ipalib import util -- cgit From deb8e3dfc899cfc7ee31f47c1ba7c4301c58fc51 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 7 Oct 2008 22:30:53 -0600 Subject: Renamed tests/tstutil.py to tests/util.py --- tests/test_ipalib/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 5b8b13f7..04ff23f0 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,7 +21,7 @@ Test the `ipalib.util` module. """ -from tests.tstutil import raises +from tests.util import raises from ipalib import util -- cgit From 8ad5502354a364db606b72455c5514cb56e918ba Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 13 Nov 2008 21:07:47 -0700 Subject: Added util.make_repr() function; added corresponding unit tests --- tests/test_ipalib/test_util.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 04ff23f0..6729fcda 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -27,7 +27,7 @@ from ipalib import util def test_xmlrpc_marshal(): """ - Test the `util.xmlrpc_marshal` function. + Test the `ipalib.util.xmlrpc_marshal` function. """ f = util.xmlrpc_marshal assert f() == ({},) @@ -39,7 +39,7 @@ def test_xmlrpc_marshal(): def test_xmlrpc_unmarshal(): """ - Test the `util.xmlrpc_unmarshal` function. + Test the `ipalib.util.xmlrpc_unmarshal` function. """ f = util.xmlrpc_unmarshal assert f() == (tuple(), {}) @@ -47,3 +47,15 @@ def test_xmlrpc_unmarshal(): assert f(dict(one=1, two=2)) == (tuple(), dict(one=1, two=2)) assert f(dict(three=3, four=4), 'one', 'two') == \ (('one', 'two'), dict(three=3, four=4)) + + +def test_make_repr(): + """ + Test the `ipalib.util.make_repr` function. + """ + f = util.make_repr + assert f('my') == 'my()' + assert f('my', True, u'hello') == "my(True, u'hello')" + assert f('my', one=1, two='two') == "my(one=1, two='two')" + assert f('my', None, 3, dog='animal', apple='fruit') == \ + "my(None, 3, apple='fruit', dog='animal')" -- cgit From cfe4ec2175c42f208ae23401991febb8525bdd9b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 19 Nov 2008 16:11:23 -0700 Subject: Added util.xmlrpc_wrap(), util.xmlrpc_unwrap() functions an corresponding unit tests --- tests/test_ipalib/test_util.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 6729fcda..b75d6dc7 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,6 +21,7 @@ Test the `ipalib.util` module. """ +from xmlrpclib import Binary from tests.util import raises from ipalib import util @@ -49,6 +50,43 @@ def test_xmlrpc_unmarshal(): (('one', 'two'), dict(three=3, four=4)) +def test_xmlrpc_wrap(): + """ + Test the `ipalib.util.xmlrpc_wrap` function. + """ + f = util.xmlrpc_wrap + assert f([]) == tuple() + assert f({}) == dict() + b = f('hello') + assert isinstance(b, Binary) + assert b.data == 'hello' + u = f(u'hello') + assert type(u) is unicode + assert u == u'hello' + value = f([dict(one=False, two=u'hello'), None, 'hello']) + + +def test_xmlrpc_unwrap(): + """ + Test the `ipalib.util.xmlrpc_unwrap` function. + """ + f = util.xmlrpc_unwrap + assert f([]) == tuple() + assert f({}) == dict() + utf8_bytes = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' + unicode_chars = u'\u041f\u0430\u0432\u0435\u043b' + value = f(Binary(utf8_bytes)) + assert type(value) is str + assert value == utf8_bytes + value = f(utf8_bytes) + assert type(value) is unicode + assert value == unicode_chars + value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)]) + assert value == (True, 'hello', dict(one=1, two=unicode_chars, three=None)) + assert type(value[1]) is str + assert type(value[2]['two']) is unicode + + def test_make_repr(): """ Test the `ipalib.util.make_repr` function. -- cgit From 75bdea29be8ea53c8e005e9020f3f2d1c7dcf689 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 20 Nov 2008 12:41:06 -0700 Subject: Added test_util.test_round_trip() test that tests use of xmlrpc_wrap() and xmlrpc_unwrap() with dumps(), loads(); fixed a bug in xmlrpc_unwrap() --- tests/test_ipalib/test_util.py | 114 +++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 28 deletions(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index b75d6dc7..fd7d85f5 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,33 +21,70 @@ Test the `ipalib.util` module. """ -from xmlrpclib import Binary +from xmlrpclib import Binary, dumps, loads +import struct from tests.util import raises from ipalib import util -def test_xmlrpc_marshal(): - """ - Test the `ipalib.util.xmlrpc_marshal` function. - """ - f = util.xmlrpc_marshal - assert f() == ({},) - assert f('one', 'two') == ({}, 'one', 'two') - assert f(one=1, two=2) == (dict(one=1, two=2),) - assert f('one', 'two', three=3, four=4) == \ - (dict(three=3, four=4), 'one', 'two') +# A string that should have bytes 'x\00' through '\xff': +BINARY_BYTES = ''.join(struct.pack('B', d) for d in xrange(256)) +assert '\x00' in BINARY_BYTES and '\xff' in BINARY_BYTES +# A UTF-8 encoded str +UTF8_BYTES = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' -def test_xmlrpc_unmarshal(): +# The same UTF-8 data decoded (a unicode instance) +UNICODE_CHARS = u'\u041f\u0430\u0432\u0435\u043b' +assert UTF8_BYTES.decode('UTF-8') == UNICODE_CHARS +assert UNICODE_CHARS.encode('UTF-8') == UTF8_BYTES +assert UTF8_BYTES != UNICODE_CHARS + + + +def dump_n_load(value): + (param, method) = loads( + dumps((value,)) + ) + return param[0] + + +def round_trip(value): + return util.xmlrpc_unwrap( + dump_n_load(util.xmlrpc_wrap(value)) + ) + + +def test_round_trip(): """ - Test the `ipalib.util.xmlrpc_unmarshal` function. + Test `ipalib.util.xmlrpc_wrap` and `ipalib.util.xmlrpc_unwrap`. + + This tests the two functions together with ``xmlrpclib.dumps`` and + ``xmlrpclib.loads`` in a full encode/decode round trip. """ - f = util.xmlrpc_unmarshal - assert f() == (tuple(), {}) - assert f({}, 'one', 'two') == (('one', 'two'), {}) - assert f(dict(one=1, two=2)) == (tuple(), dict(one=1, two=2)) - assert f(dict(three=3, four=4), 'one', 'two') == \ - (('one', 'two'), dict(three=3, four=4)) + # We first test that our assumptions about xmlrpclib module in the Python + # standard library are correct: + assert dump_n_load(UTF8_BYTES) == UNICODE_CHARS + assert dump_n_load(UNICODE_CHARS) == UNICODE_CHARS + assert dump_n_load(Binary(BINARY_BYTES)).data == BINARY_BYTES + assert isinstance(dump_n_load(Binary(BINARY_BYTES)), Binary) + assert type(dump_n_load('hello')) is str + assert type(dump_n_load(u'hello')) is str + + # Now we test our wrap and unwrap methods in combination with dumps, loads: + # All str should come back str (because they get wrapped in + # xmlrpclib.Binary(). All unicode should come back unicode because str + # explicity get decoded by util.xmlrpc_unwrap() if they weren't already + # decoded by xmlrpclib.loads(). + assert round_trip(UTF8_BYTES) == UTF8_BYTES + assert round_trip(UNICODE_CHARS) == UNICODE_CHARS + assert round_trip(BINARY_BYTES) == BINARY_BYTES + assert type(round_trip('hello')) is str + assert type(round_trip(u'hello')) is unicode + compound = [UTF8_BYTES, UNICODE_CHARS, BINARY_BYTES, + dict(utf8=UTF8_BYTES, chars=UNICODE_CHARS, data=BINARY_BYTES) + ] + assert round_trip(compound) == tuple(compound) def test_xmlrpc_wrap(): @@ -73,20 +110,41 @@ def test_xmlrpc_unwrap(): f = util.xmlrpc_unwrap assert f([]) == tuple() assert f({}) == dict() - utf8_bytes = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' - unicode_chars = u'\u041f\u0430\u0432\u0435\u043b' - value = f(Binary(utf8_bytes)) + value = f(Binary(UTF8_BYTES)) assert type(value) is str - assert value == utf8_bytes - value = f(utf8_bytes) - assert type(value) is unicode - assert value == unicode_chars - value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)]) - assert value == (True, 'hello', dict(one=1, two=unicode_chars, three=None)) + assert value == UTF8_BYTES + assert f(UTF8_BYTES) == UNICODE_CHARS + assert f(UNICODE_CHARS) == UNICODE_CHARS + value = f([True, Binary('hello'), dict(one=1, two=UTF8_BYTES, three=None)]) + assert value == (True, 'hello', dict(one=1, two=UNICODE_CHARS, three=None)) assert type(value[1]) is str assert type(value[2]['two']) is unicode +def test_xmlrpc_marshal(): + """ + Test the `ipalib.util.xmlrpc_marshal` function. + """ + f = util.xmlrpc_marshal + assert f() == ({},) + assert f('one', 'two') == ({}, 'one', 'two') + assert f(one=1, two=2) == (dict(one=1, two=2),) + assert f('one', 'two', three=3, four=4) == \ + (dict(three=3, four=4), 'one', 'two') + + +def test_xmlrpc_unmarshal(): + """ + Test the `ipalib.util.xmlrpc_unmarshal` function. + """ + f = util.xmlrpc_unmarshal + assert f() == (tuple(), {}) + assert f({}, 'one', 'two') == (('one', 'two'), {}) + assert f(dict(one=1, two=2)) == (tuple(), dict(one=1, two=2)) + assert f(dict(three=3, four=4), 'one', 'two') == \ + (('one', 'two'), dict(three=3, four=4)) + + def test_make_repr(): """ Test the `ipalib.util.make_repr` function. -- cgit From c02770129db9b27a718dadbf438459c3404c8a5a Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 21 Nov 2008 15:05:39 -0700 Subject: Small changed to test_round_trip() test --- tests/test_ipalib/test_util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index fd7d85f5..8069d89b 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -30,6 +30,7 @@ from ipalib import util # A string that should have bytes 'x\00' through '\xff': BINARY_BYTES = ''.join(struct.pack('B', d) for d in xrange(256)) assert '\x00' in BINARY_BYTES and '\xff' in BINARY_BYTES +assert type(BINARY_BYTES) is str and len(BINARY_BYTES) == 256 # A UTF-8 encoded str UTF8_BYTES = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' @@ -41,7 +42,6 @@ assert UNICODE_CHARS.encode('UTF-8') == UTF8_BYTES assert UTF8_BYTES != UNICODE_CHARS - def dump_n_load(value): (param, method) = loads( dumps((value,)) @@ -59,8 +59,8 @@ def test_round_trip(): """ Test `ipalib.util.xmlrpc_wrap` and `ipalib.util.xmlrpc_unwrap`. - This tests the two functions together with ``xmlrpclib.dumps`` and - ``xmlrpclib.loads`` in a full encode/decode round trip. + This tests the two functions together with ``xmlrpclib.dumps()`` and + ``xmlrpclib.loads()`` in a full encode/dumps/loads/decode round trip. """ # We first test that our assumptions about xmlrpclib module in the Python # standard library are correct: @@ -81,6 +81,8 @@ def test_round_trip(): assert round_trip(BINARY_BYTES) == BINARY_BYTES assert type(round_trip('hello')) is str assert type(round_trip(u'hello')) is unicode + assert round_trip('') == '' + assert round_trip(u'') == u'' compound = [UTF8_BYTES, UNICODE_CHARS, BINARY_BYTES, dict(utf8=UTF8_BYTES, chars=UNICODE_CHARS, data=BINARY_BYTES) ] -- cgit From 8a2902a2a240108e16561679e01f52b362097b3a Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 8 Dec 2008 12:34:38 -0700 Subject: Re-enable Python2.4 tests and fixed some small things broken under Python2.4 --- tests/test_ipalib/test_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 8069d89b..ef562735 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,6 +21,8 @@ Test the `ipalib.util` module. """ +# FIXME: Most of these tests are depreciated and have moved to test_rpc.py + from xmlrpclib import Binary, dumps, loads import struct from tests.util import raises @@ -39,7 +41,6 @@ UTF8_BYTES = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' UNICODE_CHARS = u'\u041f\u0430\u0432\u0435\u043b' assert UTF8_BYTES.decode('UTF-8') == UNICODE_CHARS assert UNICODE_CHARS.encode('UTF-8') == UTF8_BYTES -assert UTF8_BYTES != UNICODE_CHARS def dump_n_load(value): -- cgit From 4591057203e61a4ab304b8730ffede6560f74d4b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 8 Dec 2008 15:15:50 -0700 Subject: Removed depreciated rpc code from ipalib.util; removed corresponding unit tests in test_util --- tests/test_ipalib/test_util.py | 99 ------------------------------------------ 1 file changed, 99 deletions(-) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index ef562735..6729fcda 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,109 +21,10 @@ Test the `ipalib.util` module. """ -# FIXME: Most of these tests are depreciated and have moved to test_rpc.py - -from xmlrpclib import Binary, dumps, loads -import struct from tests.util import raises from ipalib import util -# A string that should have bytes 'x\00' through '\xff': -BINARY_BYTES = ''.join(struct.pack('B', d) for d in xrange(256)) -assert '\x00' in BINARY_BYTES and '\xff' in BINARY_BYTES -assert type(BINARY_BYTES) is str and len(BINARY_BYTES) == 256 - -# A UTF-8 encoded str -UTF8_BYTES = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' - -# The same UTF-8 data decoded (a unicode instance) -UNICODE_CHARS = u'\u041f\u0430\u0432\u0435\u043b' -assert UTF8_BYTES.decode('UTF-8') == UNICODE_CHARS -assert UNICODE_CHARS.encode('UTF-8') == UTF8_BYTES - - -def dump_n_load(value): - (param, method) = loads( - dumps((value,)) - ) - return param[0] - - -def round_trip(value): - return util.xmlrpc_unwrap( - dump_n_load(util.xmlrpc_wrap(value)) - ) - - -def test_round_trip(): - """ - Test `ipalib.util.xmlrpc_wrap` and `ipalib.util.xmlrpc_unwrap`. - - This tests the two functions together with ``xmlrpclib.dumps()`` and - ``xmlrpclib.loads()`` in a full encode/dumps/loads/decode round trip. - """ - # We first test that our assumptions about xmlrpclib module in the Python - # standard library are correct: - assert dump_n_load(UTF8_BYTES) == UNICODE_CHARS - assert dump_n_load(UNICODE_CHARS) == UNICODE_CHARS - assert dump_n_load(Binary(BINARY_BYTES)).data == BINARY_BYTES - assert isinstance(dump_n_load(Binary(BINARY_BYTES)), Binary) - assert type(dump_n_load('hello')) is str - assert type(dump_n_load(u'hello')) is str - - # Now we test our wrap and unwrap methods in combination with dumps, loads: - # All str should come back str (because they get wrapped in - # xmlrpclib.Binary(). All unicode should come back unicode because str - # explicity get decoded by util.xmlrpc_unwrap() if they weren't already - # decoded by xmlrpclib.loads(). - assert round_trip(UTF8_BYTES) == UTF8_BYTES - assert round_trip(UNICODE_CHARS) == UNICODE_CHARS - assert round_trip(BINARY_BYTES) == BINARY_BYTES - assert type(round_trip('hello')) is str - assert type(round_trip(u'hello')) is unicode - assert round_trip('') == '' - assert round_trip(u'') == u'' - compound = [UTF8_BYTES, UNICODE_CHARS, BINARY_BYTES, - dict(utf8=UTF8_BYTES, chars=UNICODE_CHARS, data=BINARY_BYTES) - ] - assert round_trip(compound) == tuple(compound) - - -def test_xmlrpc_wrap(): - """ - Test the `ipalib.util.xmlrpc_wrap` function. - """ - f = util.xmlrpc_wrap - assert f([]) == tuple() - assert f({}) == dict() - b = f('hello') - assert isinstance(b, Binary) - assert b.data == 'hello' - u = f(u'hello') - assert type(u) is unicode - assert u == u'hello' - value = f([dict(one=False, two=u'hello'), None, 'hello']) - - -def test_xmlrpc_unwrap(): - """ - Test the `ipalib.util.xmlrpc_unwrap` function. - """ - f = util.xmlrpc_unwrap - assert f([]) == tuple() - assert f({}) == dict() - value = f(Binary(UTF8_BYTES)) - assert type(value) is str - assert value == UTF8_BYTES - assert f(UTF8_BYTES) == UNICODE_CHARS - assert f(UNICODE_CHARS) == UNICODE_CHARS - value = f([True, Binary('hello'), dict(one=1, two=UTF8_BYTES, three=None)]) - assert value == (True, 'hello', dict(one=1, two=UNICODE_CHARS, three=None)) - assert type(value[1]) is str - assert type(value[2]['two']) is unicode - - def test_xmlrpc_marshal(): """ Test the `ipalib.util.xmlrpc_marshal` function. -- cgit