From 8a964d02b5a7c0c8a002f05597f0d1c1aabf569c Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 1 Aug 2008 03:15:50 +0000 Subject: 35: Renamed unit_common.py to tstutil.py --- ipalib/tests/test_plugable.py | 12 ++++----- ipalib/tests/tstutil.py | 63 +++++++++++++++++++++++++++++++++++++++++++ ipalib/tests/unit_common.py | 63 ------------------------------------------- 3 files changed, 69 insertions(+), 69 deletions(-) create mode 100644 ipalib/tests/tstutil.py delete mode 100644 ipalib/tests/unit_common.py (limited to 'ipalib/tests') diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index e69060b3..8c0b4b42 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -21,7 +21,7 @@ Unit tests for `ipalib.plugable` module. """ -import unit_common as uc +import tstutil from ipalib import plugable, errors @@ -57,17 +57,17 @@ def test_ReadOnly(): obj = plugable.ReadOnly() names = ['not_an_attribute', 'an_attribute'] for name in names: - uc.no_set(obj, name) - uc.no_del(obj, name) + tstutil.no_set(obj, name) + tstutil.no_del(obj, name) class some_ro_class(plugable.ReadOnly): def __init__(self): object.__setattr__(self, 'an_attribute', 'Hello world!') obj = some_ro_class() for name in names: - uc.no_set(obj, name) - uc.no_del(obj, name) - assert uc.read_only(obj, 'an_attribute') == 'Hello world!' + tstutil.no_set(obj, name) + tstutil.no_del(obj, name) + assert tstutil.read_only(obj, 'an_attribute') == 'Hello world!' def test_Proxy(): diff --git a/ipalib/tests/tstutil.py b/ipalib/tests/tstutil.py new file mode 100644 index 00000000..1c93f138 --- /dev/null +++ b/ipalib/tests/tstutil.py @@ -0,0 +1,63 @@ +# 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 + +""" +Utility functions for the unit tests. +""" + + +def no_set(obj, name): + """ + Tests that attribute cannot be set. + """ + raised = False + try: + setattr(obj, name, 'some_new_obj') + except AttributeError: + raised = True + assert raised + + +def no_del(obj, name): + """ + Tests that attribute cannot be deleted. + """ + raised = False + try: + delattr(obj, name) + except AttributeError: + raised = True + assert raised + + +def read_only(obj, name): + """ + Tests that attribute is read-only. Returns attribute. + """ + assert isinstance(obj, object) + assert hasattr(obj, name) + + # Test that it cannot be set: + no_set(obj, name) + + # Test that it cannot be deleted: + no_del(obj, name) + + # Return the attribute + return getattr(obj, name) diff --git a/ipalib/tests/unit_common.py b/ipalib/tests/unit_common.py deleted file mode 100644 index f5c7f0f9..00000000 --- a/ipalib/tests/unit_common.py +++ /dev/null @@ -1,63 +0,0 @@ -# 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 - -""" -Utility functions for unit tests. -""" - - -def no_set(obj, name): - """ - Tests that attribute cannot be set. - """ - raised = False - try: - setattr(obj, name, 'some_new_obj') - except AttributeError: - raised = True - assert raised - - -def no_del(obj, name): - """ - Tests that attribute cannot be deleted. - """ - raised = False - try: - delattr(obj, name) - except AttributeError: - raised = True - assert raised - - -def read_only(obj, name): - """ - Tests that attribute is read-only. Returns attribute. - """ - assert isinstance(obj, object) - assert hasattr(obj, name) - - # Test that it cannot be set: - no_set(obj, name) - - # Test that it cannot be deleted: - no_del(obj, name) - - # Return the attribute - return getattr(obj, name) -- cgit