[csw-devel] SF.net SVN: gar:[8296] csw/mgar/pkg/cswclassutils/trunk

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Feb 2 10:34:44 CET 2010


Revision: 8296
          http://gar.svn.sourceforge.net/gar/?rev=8296&view=rev
Author:   wahwah
Date:     2010-02-02 09:34:44 +0000 (Tue, 02 Feb 2010)

Log Message:
-----------
cswclassutils: cswmigrateconf, testing code refactoring for better reuse

Modified Paths:
--------------
    csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf
    csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py

Property Changed:
----------------
    csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py

Modified: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf	2010-02-02 08:11:38 UTC (rev 8295)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf	2010-02-02 09:34:44 UTC (rev 8296)
@@ -42,11 +42,18 @@
 else
   DEBUG=0
 fi
+readonly DEBUG
 
+CLASSUTILS_SKIP_WARNING="${CLASSUTILS_SKIP_WARNING:-0}"
+readonly CLASSUTILS_SKIP_WARNING
+
 give_a_chance_to_stop() {
   if [ "${chance_to_stop_given}" -ne 0 ]; then
     return
   fi
+  if [ "${CLASSUTILS_SKIP_WARNING}" != "0" ]; then
+  	return
+  fi
   echo "----8<---- migration configuration start ----8<----"
   cat "${confdst}"
   echo "----8<---- migration configuration end   ----8<----"
@@ -221,9 +228,7 @@
     # moved already.
     if [ -r "${srcpath}" ]
     then
-      if [ "${DEBUG}" -ne 1 ]; then
-        give_a_chance_to_stop
-      fi
+      give_a_chance_to_stop
       place_signpost_for "${srcpath}"
       debug "Moving '${srcpath}' to '${archpath}'"
       mv "${srcpath}" "${archpath}"

Modified: csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py	2010-02-02 08:11:38 UTC (rev 8295)
+++ csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py	2010-02-02 09:34:44 UTC (rev 8296)
@@ -1,4 +1,5 @@
 #!/opt/csw/bin/python2.6
+# $Id$
 
 import os
 import os.path
@@ -9,26 +10,31 @@
 import copy
 import sys
 
-I_SCRIPT_PATH = "../files/CSWcswclassutils.i.cswmigrateconf"
 SHELL = "/bin/sh"
 
-CONFIG_1 = """MIGRATE_FILES="file0 dir0"
+CONFIG_1 = """MIGRATE_FILES="%(migrate_files)s"
 SOURCE_DIR___default__="%(srcdir)s"
 DEST_DIR___default__="%(dstdir)s"
 ARCH_DIR___default__="%(arcdir)s"
 """
 
-class CswmigrateconfUnitTest(unittest.TestCase):
-  """Tests cswmigrateconf."""
+class CswmigrateconfSetupMixin(object):
+  """Sets up stuff for cswmigrateconf testing."""
 
+  SRC_ETC = "src_etc"
+  DST_ETC = "dst_etc"
+  MIGRATION_ARCHIVE = "migration-archive"
+  I_SCRIPT_PATH = "../files/CSWcswclassutils.i.cswmigrateconf"
+  TMP_PREFIX = "csw-classutils-test-"
+  SCRIPT_DEBUG = True
+
   def setUp(self):
-    self.tmpdir = tempfile.mkdtemp(prefix="csw-classutils-test-")
-    self.script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), I_SCRIPT_PATH)
-    print self.tmpdir
-    print self.script_path
-    self.mig_src_dir = os.path.join(self.tmpdir, "src_etc")
-    self.mig_dst_dir = os.path.join(self.tmpdir, "dst_etc")
-    self.mig_arc_dir = os.path.join(self.tmpdir, "migration-archive")
+    self.tmpdir = tempfile.mkdtemp(prefix=self.TMP_PREFIX)
+    self.script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                                    self.I_SCRIPT_PATH)
+    self.mig_src_dir = os.path.join(self.tmpdir, self.SRC_ETC)
+    self.mig_dst_dir = os.path.join(self.tmpdir, self.DST_ETC)
+    self.mig_arc_dir = os.path.join(self.tmpdir, self.MIGRATION_ARCHIVE)
     os.mkdir(self.mig_src_dir)
     os.mkdir(self.mig_dst_dir)
     # os.mkdir(self.mig_arc_dir)
@@ -36,6 +42,7 @@
         "srcdir": self.mig_src_dir,
         "dstdir": self.mig_dst_dir,
         "arcdir": self.mig_arc_dir,
+        "migrate_files": self.MIGRATE_FILES,
     }
     self.migraconf_conf_src_path = os.path.join(self.tmpdir, "cswmigrateconf_src")
     self.migraconf_conf_dst_path = os.path.join(self.tmpdir, "cswmigrateconf_dest")
@@ -44,46 +51,16 @@
     f = open(self.migraconf_conf_src_path, "w")
     f.write(config_content)
     f.close()
-    f = open(os.path.join(self.mig_src_dir, "file0"), "w")
-    f.write("# Test config file.\n")
-    f.close()
-    os.mkdir(os.path.join(self.mig_src_dir, "dir0"))
-    f = open(os.path.join(self.mig_src_dir, "dir0", "file1"), "w")
-    f.write("# Second test config file.\n")
-    f.close()
 
   def tearDown(self):
     shutil.rmtree(self.tmpdir)
   
-  def test_2(self):
-    """Running the thing.
-
-After the migration:
-
-/tmp/csw-classutils-test-8ghrVo
-|-- cswmigrateconf_dest
-|-- cswmigrateconf_src
-|-- dst_etc
-|   |-- dir0
-|   |   `-- file1
-|   `-- file0
-|-- migration-archive
-|   |-- dir0
-|   |   `-- file1
-|   `-- file0
-`-- src_etc
-    |-- dir0.README.migration
-    `-- file0.README.migration
-
-5 directories, 8 files
-    """
-    # srcpath
-    # dstpath
-    # config content
-    subprocess.call(["tree", self.tmpdir])
-    print "trying to run it."
+  def RunActionScript(self):
+    """Running the migration script."""
     classutils_env = copy.copy(os.environ)
-    classutils_env["CLASSUTILS_DEBUG"] = "1"
+    if self.SCRIPT_DEBUG:
+      classutils_env["CLASSUTILS_DEBUG"] = "1"
+    classutils_env["CLASSUTILS_SKIP_WARNING"] = "1"
     args = [SHELL, self.script_path]
     migconf_proc = subprocess.Popen(args,
                                     stdin=subprocess.PIPE,
@@ -91,15 +68,42 @@
                                     stderr=subprocess.PIPE,
                                     cwd="/",
                                     env=classutils_env)
-    print "feeding:", repr(self.stdin_data)
     stdout, stderr = migconf_proc.communicate(self.stdin_data)
     retcode = migconf_proc.wait()
-    print "stdout", repr(stdout)
-    print "stderr", repr(stderr)
     print stdout
-    print os.listdir(self.tmpdir)
-    subprocess.call(["tree", self.tmpdir])
+    if stderr:
+      print "stderr", stderr
     self.assertFalse(retcode, "Running %s has failed" % args)
 
+  def CreateMigrationFiles(self):
+    for d in self.DIRS:
+      os.mkdir(os.path.join(self.mig_src_dir, d))
+    for file_name, file_content in self.FILES:
+      f = open(os.path.join(self.mig_src_dir, file_name), "w")
+      f.write(file_content)
+      f.close()
+
+
+class CswmigrateconfUnitTest(CswmigrateconfSetupMixin, unittest.TestCase):
+
+  MIGRATE_FILES = "file0 dir0"
+  SCRIPT_DEBUG = False
+  DIRS = ["dir0", "dir0/dir1"]
+  FILES = [
+      # ("file name", "content\n")
+      ("file0",           "# Test config file.\n"),
+      ("dir0/file1",      "# Second test config file.\n"),
+      ("dir0/dir1/file2", "# Third test config file.\n"),
+  ]
+
+  def test_1(self):
+    self.CreateMigrationFiles()
+    subprocess.call(["tree", self.tmpdir])
+    self.RunActionScript()
+    subprocess.call(["tree", self.tmpdir])
+    self.RunActionScript()
+    subprocess.call(["tree", self.tmpdir])
+    # Tests go here
+
 if __name__ == '__main__':
 	unittest.main()


Property changes on: csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Id


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list