Author: bugman Date: Tue Mar 13 04:34:49 2007 New Revision: 3156 URL: http://svn.gna.org/viewcvs/relax?rev=3156&view=rev Log: Added unit tests for the relax data storage singleton class Data from the 'data' module. Modified: 1.3/test_suite/unit_tests/data/__init__.py Modified: 1.3/test_suite/unit_tests/data/__init__.py URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/data/__init__.py?rev=3156&r1=3155&r2=3156&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/data/__init__.py (original) +++ 1.3/test_suite/unit_tests/data/__init__.py Tue Mar 13 04:34:49 2007 @@ -20,6 +20,106 @@ # # ############################################################################### +# Python module imports. +from unittest import TestCase + +# relax module imports. +from data import Data + __all__ = ['test_diff_tensor'] + + +class NewStore(Data): + """Subclass the relax data storage object for the isolation and creation of a new singleton.""" + + +class Empty_container: + """An empty data container.""" + + +class Test_Data(TestCase): + """Unit tests for the data.Data class.""" + + def setUp(self): + """Set up a complex relax data store.""" + + # Create a new relax data store singleton. + self.data_store = NewStore() + + # Add an empty data container as a new pipe. + self.data_store['empty'] = Empty_container() + + # Add an object to the empty data container. + self.data_store['empty'].x = 1 + + # Add an object to the data store object. + self.data_store.test = 1 + + # Create a new reference. + self.new_ref = NewStore() + + + def tearDown(self): + """Destroy the subclassed data store.""" + + # Delete all references (which should decrement the singleton's ref counter to 0, hence destroying it). + del self.new_ref + del self.data_store + + + def test_add(self): + """Unit test for testing the addition of a new data pipe by the 'add()' method.""" + + # Add a new data pipe. + self.data_store.add('new') + + # Test that the new data pipe exists. + self.assert_(self.data_store.has_key('new')) + + + def test_repr(self): + """Unit test for the validity of the __repr__() method.""" + + # Test that __repr__() returns a string. + self.assert_(type(self.data_store.__repr__()), str) + + + def test_reset(self): + """Unit test for the __reset__() class method.""" + + # Execute the reset method. + self.data_store.__reset__() + + # Test that there are no keys. + self.assertEqual(self.data_store.keys(), []) + + # Test that the object self.data_store.test is deleted. + self.assert_(not hasattr(self.data_store, 'test')) + + # Test that the object methods still exist. + self.assert_(hasattr(self.data_store, '__new__')) + self.assert_(hasattr(self.data_store, '__repr__')) + self.assert_(hasattr(self.data_store, '__reset__')) + self.assert_(hasattr(self.data_store, 'add')) + + # Test that the object's initial objects still exist. + self.assert_(hasattr(self.data_store, 'current_pipe')) + + + def test_singleton(self): + """Test that the relax data storage object is functioning as a singleton.""" + + # Test that the new reference to NewStore is the singleton instance reference. + self.assertEqual(self.data_store, self.new_ref) + + # Delete all references (which should decrement the singleton's ref counter to 0, hence destroying it). + del self.new_ref + del self.data_store + + # Create a new singleton. + new = NewStore() + + # Test that the object 'test' from the original singleton does not exist. + self.assert_(not hasattr(new, 'test'))