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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Feb 1 01:13:32 CET 2010


Revision: 8286
          http://gar.svn.sourceforge.net/gar/?rev=8286&view=rev
Author:   wahwah
Date:     2010-02-01 00:13:32 +0000 (Mon, 01 Feb 2010)

Log Message:
-----------
cswclassutils: Added some preliminary testing code.

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

Added Paths:
-----------
    csw/mgar/pkg/cswclassutils/trunk/tests/
    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-01 00:12:43 UTC (rev 8285)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf	2010-02-01 00:13:32 UTC (rev 8286)
@@ -36,7 +36,8 @@
 readonly deprecated_file_ext
 
 # Create /etc/opt/csw/cswclassutils.DEBUG to enable debugging of this script
-if [ -r ${PKG_INSTALL_ROOT}/etc/opt/csw/cswclassutils.DEBUG ]; then
+debug_hint="${PKG_INSTALL_ROOT}/etc/opt/csw/cswclassutils.DEBUG"
+if [ -r "${debug_hint}" -o -n "${CLASSUTILS_DEBUG:-}" ]; then
   DEBUG=1
 else
   DEBUG=0
@@ -75,7 +76,7 @@
 }
 
 sanitize() {
-  echo "$1" | sed -e 's/[^a-zA-Z0-9]/_/g'
+  echo "$1" | LC_ALL=C sed -e 's/[^a-zA-Z0-9]/_/g'
 }
 
 expand_modifiers() {
@@ -220,7 +221,9 @@
     # moved already.
     if [ -r "${srcpath}" ]
     then
-      give_a_chance_to_stop
+      if [ "${DEBUG}" -ne 1 ]; then
+        give_a_chance_to_stop
+      fi
       place_signpost_for "${srcpath}"
       debug "Moving '${srcpath}' to '${archpath}'"
       mv "${srcpath}" "${archpath}"

Added: csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py	                        (rev 0)
+++ csw/mgar/pkg/cswclassutils/trunk/tests/migrateconf_test.py	2010-02-01 00:13:32 UTC (rev 8286)
@@ -0,0 +1,105 @@
+#!/opt/csw/bin/python2.6
+
+import os
+import os.path
+import shutil
+import unittest
+import tempfile
+import subprocess
+import copy
+import sys
+
+I_SCRIPT_PATH = "../files/CSWcswclassutils.i.cswmigrateconf"
+SHELL = "/bin/sh"
+
+CONFIG_1 = """MIGRATE_FILES="file0 dir0"
+SOURCE_DIR___default__="%(srcdir)s"
+DEST_DIR___default__="%(dstdir)s"
+ARCH_DIR___default__="%(arcdir)s"
+"""
+
+class CswmigrateconfUnitTest(unittest.TestCase):
+  """Tests cswmigrateconf."""
+
+  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")
+    os.mkdir(self.mig_src_dir)
+    os.mkdir(self.mig_dst_dir)
+    # os.mkdir(self.mig_arc_dir)
+    config_content = CONFIG_1 % {
+        "srcdir": self.mig_src_dir,
+        "dstdir": self.mig_dst_dir,
+        "arcdir": self.mig_arc_dir,
+    }
+    self.migraconf_conf_src_path = os.path.join(self.tmpdir, "cswmigrateconf_src")
+    self.migraconf_conf_dst_path = os.path.join(self.tmpdir, "cswmigrateconf_dest")
+    self.stdin_data = """%s %s\n""" % (self.migraconf_conf_src_path,
+                                       self.migraconf_conf_dst_path)
+    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."
+    classutils_env = copy.copy(os.environ)
+    classutils_env["CLASSUTILS_DEBUG"] = "1"
+    args = [SHELL, self.script_path]
+    migconf_proc = subprocess.Popen(args,
+                                    stdin=subprocess.PIPE,
+                                    stdout=subprocess.PIPE,
+                                    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])
+    self.assertFalse(retcode, "Running %s has failed" % args)
+
+if __name__ == '__main__':
+	unittest.main()


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