[Zope-Checkins] CVS: ZODB3/zdaemon/tests - testzdoptions.py:1.10

Fred L. Drake, Jr. fred@zope.com
Thu, 20 Feb 2003 10:02:08 -0500


Update of /cvs-repository/ZODB3/zdaemon/tests
In directory cvs.zope.org:/tmp/cvs-serv3601

Modified Files:
	testzdoptions.py 
Log Message:
More refactoring:
- move check_exit_code() to a lower-level base class
- cache the parsed schema used for EnvironmentOptions.OptionsClass;
  this will be used more


=== ZODB3/zdaemon/tests/testzdoptions.py 1.9 => 1.10 ===
--- ZODB3/zdaemon/tests/testzdoptions.py:1.9	Thu Feb 20 09:41:43 2003
+++ ZODB3/zdaemon/tests/testzdoptions.py	Thu Feb 20 10:02:07 2003
@@ -38,6 +38,19 @@
         sys.stdout = self.save_stdout
         sys.stderr = self.save_stderr
 
+    def check_exit_code(self, options, args):
+        save_sys_stderr = sys.stderr
+        try:
+            sys.stderr = StringIO()
+            try:
+                options.realize(args)
+            except SystemExit, err:
+                self.assertEqual(err.code, 2)
+            else:
+                self.fail("SystemExit expected")
+        finally:
+            sys.stderr = save_sys_stderr
+
 
 class TestZDOptions(ZDOptionsTestBase):
 
@@ -83,19 +96,6 @@
         # Check that we get an error for an unrecognized option
         self.check_exit_code(self.OptionsClass(), ["-/"])
 
-    def check_exit_code(self, options, args):
-        save_sys_stderr = sys.stderr
-        try:
-            sys.stderr = StringIO()
-            try:
-                options.realize(args)
-            except SystemExit, err:
-                self.assertEqual(err.code, 2)
-            else:
-                self.fail("SystemExit expected")
-        finally:
-            sys.stderr = save_sys_stderr
-
 
 class TestBasicFunctionality(TestZDOptions):
 
@@ -155,6 +155,8 @@
 
 class EnvironmentOptions(ZDOptionsTestBase):
 
+    saved_schema = None
+
     class OptionsClass(ZDOptions):
         def __init__(self):
             ZDOptions.__init__(self)
@@ -164,11 +166,14 @@
         def load_schema(self):
             # Doing this here avoids needing a separate file for the schema:
             if self.schema is None:
-                self.schema = ZConfig.loadSchemaFile(StringIO("""\
-                   <schema>
-                     <key name='opt' datatype='integer' default='12'/>
-                   </schema>
-                   """))
+                if EnvironmentOptions.saved_schema is None:
+                    schema = ZConfig.loadSchemaFile(StringIO("""\
+                        <schema>
+                          <key name='opt' datatype='integer' default='12'/>
+                        </schema>
+                        """))
+                    EnvironmentOptions.saved_schema = schema
+                self.schema = EnvironmentOptions.saved_schema
 
         def load_configfile(self):
             if getattr(self, "configtext", None):