def test_PipeContainer_repr(self): """Test the PipeContainer.__repr__() method.""" # Add a few objects. self.data_pipe.x = 10 self.data_pipe.chi2 = PipeContainer() # Test that __repr__() returns a string. self.assert_(type(self.data_pipe.__repr__()), str)
def add(self, pipe_name, pipe_type, bundle=None, switch=True): """Method for adding a new data pipe container to the dictionary. This method should be used rather than importing the PipeContainer class and using the statement 'D[pipe] = PipeContainer()', where D is the relax data storage object and pipe is the name of the data pipe. @param pipe_name: The name of the new data pipe. @type pipe_name: str @param pipe_type: The data pipe type. @type pipe_type: str @keyword bundle: The optional data pipe bundle to associate the data pipe with. @type bundle: str or None @keyword switch: A flag which if True will cause the new data pipe to be set to the current data pipe. @type switch: bool """ # Test if the pipe already exists. if pipe_name in self.instance: raise RelaxPipeError(pipe_name) # Create a new container. self[pipe_name] = PipeContainer() # Add the data pipe type string to the container. self[pipe_name].pipe_type = pipe_type # The pipe bundle. if bundle: # A new bundle. if bundle not in self.pipe_bundles: self.pipe_bundles[bundle] = [] # Add the pipe to the bundle. self.pipe_bundles[bundle].append(pipe_name) # Change the current data pipe. if switch: # Set the current data pipe. self.instance.current_pipe = pipe_name builtins.cdp = self[pipe_name] # Signal the switch. status.observers.pipe_alteration.notify()
class Test_pipe_container(TestCase): """Unit tests for the data.pipe_container relax module.""" def setUp(self): """Create a data pipe structure for testing all the object methods.""" # The initial empty structure. self.data_pipe = PipeContainer() def tearDown(self): """Delete the data pipe.""" del self.data_pipe def test_PipeContainer_repr(self): """Test the PipeContainer.__repr__() method.""" # Add a few objects. self.data_pipe.x = 10 self.data_pipe.chi2 = PipeContainer() # Test that __repr__() returns a string. self.assert_(type(self.data_pipe.__repr__()), str) def test_PipeContainer_repr_empty_pipe(self): """Test the PipeContainer.__repr__() method for an empty data pipe.""" # Test that __repr__() returns a string. self.assert_(type(self.data_pipe.__repr__()), str) def test_PipeContainer_is_empty(self): """Tests for the PipeContainer.is_empty() method.""" # The newly initialised data pipe should be empty. self.assert_(self.data_pipe.is_empty()) # Add an object. self.data_pipe.x = 1 self.assert_(not self.data_pipe.is_empty()) # Reset the data pipe, and modify an object. self.setUp() self.data_pipe.mol[0].name = 'Ap4Aase' self.assert_(not self.data_pipe.is_empty()) # The pipe type can be set in the empty data pipe. self.setUp() self.data_pipe.pipe_type = 'mf' self.assert_(self.data_pipe.is_empty())
def setUp(self): """Create a data pipe structure for testing all the object methods.""" # The initial empty structure. self.data_pipe = PipeContainer()