[Zope-CVS] CVS: Packages/FunctionalTests/tests - test_ConfigParserExt.py:1.2 test_Result.py:1.3

Tres Seaver tseaver@zope.com
Tue, 19 Mar 2002 22:06:05 -0500


Update of /cvs-repository/Packages/FunctionalTests/tests
In directory cvs.zope.org:/tmp/cvs-serv29780/tests

Modified Files:
	test_ConfigParserExt.py test_Result.py 
Log Message:
 - Refactor tests for cleanliness.

=== Packages/FunctionalTests/tests/test_ConfigParserExt.py 1.1 => 1.2 ===
 import unittest
 
-import FunctionalTests
-from FunctionalTests.ConfigParserExt import *
-
-from Globals import package_home
-import os, string
 
 class CPETests( unittest.TestCase ):
 
-    def setUp( self ):
-        pass
-
-    def tearDown( self ):
-        pass
+    def _makeOne( self, *args, **kw ):
+        from FunctionalTests.ConfigParserExt import ConfigParserExt
+        return ConfigParserExt( *args, **kw )
 
     def test_empty( self ):
 
-        empty = ConfigParserExt()
+        empty = self._makeOne()
+
+        self.assertEquals( empty.listSpecialSections(), ( 'DEFAULT', ) )
+        self.failIf( empty.listOtherSections() )
 
-        assert empty.listSpecialSections() == ( 'DEFAULT', )
-        assert not empty.listOtherSections()
+    def _getTestPath( self, *args ):
+        import os
+        import FunctionalTests
+        package_path = os.path.abspath( FunctionalTests.__path__[0] )
+        return os.path.join( package_path, *args )
 
     def test_withFile( self ):
 
-        cpe = ConfigParserExt( ( 'Header', 'DEFAULT' ) )
+        cpe = self._makeOne( ( 'Header', 'DEFAULT' ) )
 
-        assert len( cpe.listSpecialSections() ) == 2
-        assert 'Header' in cpe.listSpecialSections()
-        assert 'DEFAULT' in cpe.listSpecialSections()
-        assert not cpe.listOtherSections()
+        self.assertEquals( len( cpe.listSpecialSections() ), 2 )
+        self.failUnless( 'Header' in cpe.listSpecialSections() )
+        self.failUnless( 'DEFAULT' in cpe.listSpecialSections() )
+        self.failIf( cpe.listOtherSections() )
 
-        FT_path = package_home( FunctionalTests.functest_globals )
-        filename = os.path.join( FT_path, 'tests', 'config.ini' )
+        filename =  self._getTestPath( 'tests', 'config.ini' )
         cpe.read( filename )
 
-        assert len( cpe.listOtherSections() ) == 5
+        self.assertEquals( len( cpe.listOtherSections() ), 5 )
 
         for i in range( 6 )[1:]:
             section = 'Section_%d' % i
-            assert section in cpe.listOtherSections()
-            self.assertEquals( cpe.get( section, 'key' )
-                             , string.lower( section ) )
-
-    #
-    #   2.4 unittest has these.
-    #
-    if not hasattr( unittest.TestCase, 'assertEquals' ):
-        def assertEquals( self, lhs, rhs ):
-            assert lhs == rhs, '%s == %s' % (lhs, rhs )
+            self.failUnless( section in cpe.listOtherSections() )
+            self.assertEquals( cpe.get( section, 'key' ), section.lower() )
+
 
 def test_suite():
     return unittest.makeSuite( CPETests )
 
-def run():
-    unittest.TextTestRunner().run(test_suite())
-
 if __name__ == '__main__':
-    run()
+    unittest.main()


=== Packages/FunctionalTests/tests/test_Result.py 1.2 => 1.3 ===
 import unittest
 
-import FunctionalTests
-from FunctionalTests.Framework import *
 
-from Globals import package_home
-import os, string
 
 class FauxInvocation:
 
@@ -39,58 +34,56 @@
 MARKER2 = []
 class ResultTests( unittest.TestCase ):
 
-    def setUp( self ):
-        pass
-
-    def tearDown( self ):
-        pass
+    def _makeOne( self, *args, **kw ):
+        from FunctionalTests.Framework import Result
+        return Result( *args, **kw )
 
     def test_empty( self ):
 
-        empty = Result( test=MARKER )
+        empty = self._makeOne( test=MARKER )
 
-        assert empty.getTest() is MARKER
-        assert empty.timeRequests()
-        assert empty.checkResponses()
-        assert empty.checkElapsedTimes()
-        assert not empty.listInvocations()
-        assert not empty.listErrors()
-        assert not empty.listErrors( fatal_only=1 )
-        assert not empty.listChildren()
+        self.failUnless( empty.getTest() is MARKER )
+        self.failUnless( empty.timeRequests() )
+        self.failUnless( empty.checkResponses() )
+        self.failUnless( empty.checkElapsedTimes() )
+        self.failIf( empty.listInvocations() )
+        self.failIf( empty.listErrors() )
+        self.failIf( empty.listErrors( fatal_only=1 ) )
+        self.failIf( empty.listChildren() )
 
     def test_apathy( self ):
 
-        apathy = Result( test=MARKER
-                       , time_requests=0
-                       , check_responses=0
-                       , check_elapsed_times=0
-                       )
-
-        assert apathy.getTest() is MARKER
-        assert not apathy.timeRequests()
-        assert not apathy.checkResponses()
-        assert not apathy.checkElapsedTimes()
+        apathy = self._makeOne( test=MARKER
+                              , time_requests=0
+                              , check_responses=0
+                              , check_elapsed_times=0
+                              )
+
+        self.failUnless( apathy.getTest() is MARKER )
+        self.failIf( apathy.timeRequests() )
+        self.failIf( apathy.checkResponses() )
+        self.failIf( apathy.checkElapsedTimes() )
 
         apathy.addInvocation( FauxInvocation( 500, 3600.0 )
                             , FauxRequest( 'foo', 200, 1.0 )
                             )
         self.assertEquals( len( apathy.listInvocations() ), 1 )
-        assert not apathy.listErrors()
-        assert not apathy.listErrors( fatal_only=1 )
-        assert not apathy.listChildren()
+        self.failIf( apathy.listErrors() )
+        self.failIf( apathy.listErrors( fatal_only=1 ) )
+        self.failIf( apathy.listChildren() )
 
     def test_responseOnly( self ):
 
-        driven = Result( test=MARKER
-                       , time_requests=0
-                       , check_responses=1
-                       , check_elapsed_times=0
-                       )
-
-        assert driven.getTest() is MARKER
-        assert not driven.timeRequests()
-        assert driven.checkResponses()
-        assert not driven.checkElapsedTimes()
+        driven = self._makeOne( test=MARKER
+                              , time_requests=0
+                              , check_responses=1
+                              , check_elapsed_times=0
+                              )
+
+        self.failUnless( driven.getTest() is MARKER )
+        self.failIf( driven.timeRequests() )
+        self.failUnless( driven.checkResponses() )
+        self.failIf( driven.checkElapsedTimes() )
 
         driven.addInvocation( FauxInvocation( 500, 3600.0 )
                             , FauxRequest( 'foo', 200, 1.0 )
@@ -98,49 +91,57 @@
         self.assertEquals( len( driven.listInvocations() ), 1 )
         self.assertEquals( len( driven.listErrors() ), 1 )
         self.assertEquals( len( driven.listErrors( fatal_only=1 ) ), 1 )
-        assert not driven.listChildren()
+        self.failIf( driven.listChildren() )
 
     def test_timeOnly( self ):
 
-        consistent = Result( test=MARKER
-                           , time_requests=0
-                           , check_responses=0
-                           , check_elapsed_times=1
-                           )
-
-        assert consistent.timeRequests()
-
-        impatiens = Result( test=MARKER
-                          , time_requests=1
-                          , check_responses=0
-                          , check_elapsed_times=1
-                          )
-
-        assert impatiens.getTest() is MARKER
-        assert consistent.timeRequests()
-        assert not impatiens.checkResponses()
-        assert impatiens.checkElapsedTimes()
+        consistent = self._makeOne( test=MARKER
+                                  , time_requests=0
+                                  , check_responses=0
+                                  , check_elapsed_times=1
+                                  )
+
+        self.failIf( consistent.timeRequests() )
+
+        really = self._makeOne( test=MARKER
+                              , time_requests=1
+                              , check_responses=0
+                              , check_elapsed_times=1
+                              )
+
+        self.failUnless( really.timeRequests() )
+
+        impatiens = self._makeOne( test=MARKER
+                                 , time_requests=1
+                                 , check_responses=0
+                                 , check_elapsed_times=1
+                                 )
+
+        self.failUnless( impatiens.getTest() is MARKER )
+        self.failUnless( impatiens.timeRequests() )
+        self.failIf( impatiens.checkResponses() )
+        self.failUnless( impatiens.checkElapsedTimes() )
 
         impatiens.addInvocation( FauxInvocation( 500, 3600.0 )
                             , FauxRequest( 'foo', 200, 1.0 )
                             )
         self.assertEquals( len( impatiens.listInvocations() ), 1 )
         self.assertEquals( len( impatiens.listErrors() ), 1 )
-        assert not impatiens.listErrors( fatal_only=1 )
-        assert not impatiens.listChildren()
+        self.failIf( impatiens.listErrors( fatal_only=1 ) )
+        self.failIf( impatiens.listChildren() )
 
     def test_composite( self ):
 
-        top = Result( test=MARKER )
+        top = self._makeOne( test=MARKER )
 
-        assert top.getTest() is MARKER
-        assert top.timeRequests()
-        assert top.checkResponses()
-        assert top.checkElapsedTimes()
+        self.failUnless( top.getTest() is MARKER )
+        self.failUnless( top.timeRequests() )
+        self.failUnless( top.checkResponses() )
+        self.failUnless( top.checkElapsedTimes() )
 
         child = top.newChild( test=MARKER2 )
 
-        assert child.getTest() is MARKER2
+        self.failUnless( child.getTest() is MARKER2 )
         self.assertEquals( child.timeRequests(), top.timeRequests() )
         self.assertEquals( child.checkResponses(), top.checkResponses() )
         self.assertEquals( child.checkElapsedTimes(), top.checkElapsedTimes() )
@@ -160,32 +161,23 @@
         self.assertEquals( len( top.listErrors( fatal_only=1, roll_up=0 ) ), 0 )
         self.assertEquals( len( top.listChildren() ), 1 )
 
-        top = Result( test=MARKER
-                    , application=[]
-                    , defaults={ 'foo':0 }
-                    , time_requests=0
-                    , check_responses=0
-                    , check_elapsed_times=0
-                    )
+        top = self._makeOne( test=MARKER
+                           , application=[]
+                           , defaults={ 'foo':0 }
+                           , time_requests=0
+                           , check_responses=0
+                           , check_elapsed_times=0
+                           )
         child = top.newChild( test=MARKER2 )
-        assert child.getApplication() is top.getApplication()
+        self.failUnless( child.getApplication() is top.getApplication() )
         self.assertEquals( child.getDefaults(), top.getDefaults() )
         self.assertEquals( child.timeRequests(), top.timeRequests() )
         self.assertEquals( child.checkResponses(), top.checkResponses() )
         self.assertEquals( child.checkElapsedTimes(), top.checkElapsedTimes() )
 
-    #
-    #   2.4 unittest has these.
-    #
-    if not hasattr( unittest.TestCase, 'assertEquals' ):
-        def assertEquals( self, lhs, rhs ):
-            assert lhs == rhs, '%s == %s' % (lhs, rhs )
 
 def test_suite():
     return unittest.makeSuite( ResultTests )
 
-def run():
-    unittest.TextTestRunner().run(test_suite())
-
 if __name__ == '__main__':
-    run()
+    unittest.main()