[Checkins] SVN: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/ Break the coupling of Selenese to the TestCase, so we can instantiate in in the layer

Wolfgang Schnerring wosc at wosc.de
Sat Dec 4 04:49:19 EST 2010


Log message for revision 118701:
  Break the coupling of Selenese to the TestCase, so we can instantiate in in the layer
  
  Getting the failure exception from the TestCase doesn't really provide encapsulation against the underlying testing framework, so we might as well simplify our structure. If a client needs to customize this, they still can do so by changing Selenese.failureException
  
  

Changed:
  U   gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/base.py
  U   gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/grok/__init__.py
  U   gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/selenese.py
  U   gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py
  U   gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/ztk/tests/test_selenese.py

-=-
Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/base.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/base.py	2010-12-04 09:29:00 UTC (rev 118700)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/base.py	2010-12-04 09:49:18 UTC (rev 118701)
@@ -39,21 +39,34 @@
             self.__name__ = self.__class__.__name__
 
     def setUp(self):
-        self.selenium = selenium.selenium(
+        self.seleniumrc = selenium.selenium(
             self._server, self._port, self._browser,
             'http://%s:%s/' % (self.host, self.port))
-        self.selenium.start()
+        self.seleniumrc.start()
         speed = os.environ.get('GOCEPT_SELENIUM_SPEED')
         if speed is not None:
-            self.selenium.set_speed(speed)
+            self.seleniumrc.set_speed(speed)
 
     def tearDown(self):
-        self.selenium.stop()
+        self.seleniumrc.stop()
 
+    def testSetUp(self):
+        # instantiate a fresh one per test run, so any configuration
+        # (e.g. timeout) is reset
+        self.selenium = gocept.selenium.selenese.Selenese(
+            self.seleniumrc, self.host, self.port)
 
+
 class TestCase(object):
+    # the various flavours (ztk, zope2, grok, etc.) are supposed to provide
+    # their own TestCase as needed, and mix this class in to have
+    # 'self.selenium' available on the TestCase itself for convenience.
+    #
+    # Example:
+    # some.flavour.TestCase(gocept.selenium.base.TestCase,
+    #                       the.actual.base.TestCase):
+    #     pass
 
     def setUp(self):
         super(TestCase, self).setUp()
-        self.selenium = gocept.selenium.selenese.Selenese(
-            self.layer.selenium, self)
+        self.selenium = self.layer.selenium

Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/grok/__init__.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/grok/__init__.py	2010-12-04 09:29:00 UTC (rev 118700)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/grok/__init__.py	2010-12-04 09:49:18 UTC (rev 118701)
@@ -22,6 +22,10 @@
 
 class Layer(ZODBLayer, gocept.selenium.wsgi.Layer):
 
+     # we can't use super, since the base class zope.component.testlayer is not
+     # built for multiple inheritance; the wsgi.Layer-part of the family would
+     # never be reached
+
     def __init__(self, *args):
         # since the request factory class is only a parameter default of
         # WSGIPublisherApplication and not easily accessible otherwise, we fake
@@ -41,16 +45,15 @@
         ZODBLayer.tearDown(self)
 
     def testSetUp(self):
-        # A fresh database is created in the setup of the ZODBLayer:
+        gocept.selenium.wsgi.Layer.testSetUp(self)
         ZODBLayer.testSetUp(self)
-        # We tell the publisher to use this new database:
+        # tell the publisher to use ZODBLayer's current database
         factory = type(self.application.requestFactory)
         self.application.requestFactory = factory(self.db)
 
 
-class TestCase(unittest.TestCase):
+class TestCase(gocept.selenium.base.TestCase, unittest.TestCase):
 
     def setUp(self):
-        self.selenium = gocept.selenium.selenese.Selenese(
-            self.layer.selenium, self)
+        super(TestCase, self).setUp()
         self.getRootFolder = self.layer.getRootFolder

Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/selenese.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/selenese.py	2010-12-04 09:29:00 UTC (rev 118700)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/selenese.py	2010-12-04 09:49:18 UTC (rev 118701)
@@ -44,17 +44,18 @@
 
 class Selenese(object):
 
-    def __init__(self, selenium, testcase):
+    failureException = AssertionError
+
+    def __init__(self, selenium, app_host, app_port):
         self.selenium = selenium
-        self.failureException = testcase.failureException
-        self.testcase = testcase
+        self.host = app_host
+        self.port = app_port
         self.timeout = 30
         self.variables = {}
 
     @property
     def server(self):
-        # we expect the testcase to have a gocept.selenium.layer.SeleniumLayer
-        return '%s:%s' % (self.testcase.layer.host, self.testcase.layer.port)
+        return '%s:%s' % (self.host, self.port)
 
     # Actions
 

Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py	2010-12-04 09:29:00 UTC (rev 118700)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py	2010-12-04 09:49:18 UTC (rev 118701)
@@ -56,8 +56,5 @@
         super(Layer, self).tearDown()
 
 
-class TestCase(unittest.TestCase):
-
-    def setUp(self):
-        self.selenium = gocept.selenium.selenese.Selenese(
-            self.layer.selenium, self)
+class TestCase(gocept.selenium.base.TestCase, unittest.TestCase):
+    pass

Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/ztk/tests/test_selenese.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/ztk/tests/test_selenese.py	2010-12-04 09:29:00 UTC (rev 118700)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/ztk/tests/test_selenese.py	2010-12-04 09:49:18 UTC (rev 118701)
@@ -73,7 +73,7 @@
             def get_with_wrong_assert_type(self):
                 pass
 
-        self.selenese = Selenese(None, TestCase())
+        self.selenese = Selenese(None, None, None)
 
     def assertError(self, error, name, expected_msg):
         try:



More information about the checkins mailing list