/[thuban]/branches/WIP-pyshapelib-bramz/test/support.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/support.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 292 by bh, Fri Aug 30 09:44:12 2002 UTC revision 324 by bh, Fri Sep 20 13:55:42 2002 UTC
# Line 83  class FileTestMixin: Line 83  class FileTestMixin:
83      def temp_dir(self):      def temp_dir(self):
84          """Return the name of the directory for the temporary files"""          """Return the name of the directory for the temporary files"""
85          return create_temp_dir()          return create_temp_dir()
86    
87    
88    class FloatComparisonMixin:
89    
90        """
91        Mixin class for tests comparing floating point numbers.
92    
93        This class provides a few methods for testing floating point
94        operations.
95        """
96    
97        fp_epsilon = 1e-6
98        
99        def assertFloatEqual(self, test, value):
100            """Assert equality of test and value with some tolerance.
101    
102            Assert that the absolute difference between test and value is
103            less than self.fp_epsilon.
104            """
105            return self.assert_(self.fp_epsilon > abs(test - value))
106    
107        def assertFloatSeqEqual(self, test, value, epsilon = None):
108            """Assert equality of the sequences test and value with some tolerance.
109    
110            Assert that the absolute difference between each corresponding
111            value in test and value is less than the optional parameter
112            epsilon. If epsilon is not given use self.fp_epsilon.
113            """
114            if epsilon is None:
115                epsilon = self.fp_epsilon
116            for i in range(len(test)):
117                return self.assert_(epsilon > abs(test[i] - value[i]))
118    
119    
120    class SubscriberMixin:
121    
122        """Mixin class for tests for messages sent through the Connector
123    
124        The SubscriberMixin has some methods that can be used as subscribers
125        of events that when called append information about the message into
126        a list of messages received.
127    
128        A derived class should call the clear_messages() method in both its
129        setUp and tearDown methods to clear the list of messages received.
130        """
131    
132        def clear_messages(self):
133            """Clear the list of received messages.
134    
135            Call this at least in the tests setUp and tearDown methods. It's
136            important to do it in tearDown too because otherwise there may
137            be cyclic references.
138            """
139            self.received_messages = []
140    
141        def subscribe_no_params(self):
142            """Method for subscriptions without parameters.
143    
144            Add an empty tuple to the list of received messages.
145            """
146            self.received_messages.append(())
147    
148        def subscribe_with_params(self, *args):
149            """Method for subscriptions with parameters.
150    
151            Append the tuple will all arguments to this function (except for
152            the self argument) to the list of received messages.
153            """
154            self.received_messages.append(args)
155    
156        def check_messages(self, messages):
157            """Check whether the messages received match the list messages"""
158            self.assertEquals(messages, self.received_messages)

Legend:
Removed from v.292  
changed lines
  Added in v.324

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26