Further improve reliability of make_tree_from.
authorDiane Trout <diane@ghic.org>
Tue, 18 Jun 2013 18:59:13 +0000 (11:59 -0700)
committerDiane Trout <diane@ghic.org>
Tue, 18 Jun 2013 18:59:13 +0000 (11:59 -0700)
The previous update assumed that it was going to be running
in the target directory. which wasn't true in the test cases.

I also updated the test case to handle both a base filename and
an absolute pathname for the result map.

htsworkflow/submission/results.py
htsworkflow/submission/test/test_results.py

index 4f815ad43f716775803f0e3c593cba787e6ca9bc..36c2c78e7b2b0aac0613217ec2171f84a3c727ba 100644 (file)
@@ -51,9 +51,14 @@ class ResultMap(MutableMapping):
         if destpath is None:
             destpath = os.getcwd()
 
+        LOGGER.debug("Source_path: %s", source_path)
+        LOGGER.debug("Dest_path: %s", destpath)
         for lib_id in self.results_order:
-            abs_lib_path = os.path.abspath(self.results[lib_id])
-            lib_path = os.path.relpath(abs_lib_path, destpath)
+            lib_path = self.results[lib_id]
+            LOGGER.debug("lib_path: %s", lib_path)
+            if os.path.isabs(lib_path):
+                lib_path = os.path.relpath(lib_path, destpath)
+
             LOGGER.debug('lib_path: %s', lib_path)
             lib_destination = os.path.join(destpath, lib_path)
             if not os.path.exists(lib_destination):
index 3487b69d7e410f1734887f6afd0969013f0466ff..b7d6accd73af229fe12ac43dd3db07785a5c8740 100644 (file)
@@ -74,13 +74,32 @@ class TestResultMap(TestCase):
         self.assertFalse(u'77777' in results)
         self.assertFalse('77777' in results)
 
-    def test_make_from(self):
+    def test_make_from_absolute(self):
+        """Test that make from works if ResultMap has absolute paths
+        """
+        results = ResultMap()
+        sample1_dir = os.path.join(self.resultdir, S1_NAME)
+        sample2_dir = os.path.join(self.resultdir, S2_NAME)
+        results['1000'] =  sample1_dir
+        results['2000'] =  sample2_dir
+
+        results.make_tree_from(self.sourcedir, self.resultdir)
+        self.failUnless(os.path.isdir(sample1_dir))
+        self.failUnless(os.path.isdir(sample2_dir))
+
+        for f in S1_FILES + S2_FILES:
+            self.failUnless(
+                os.path.islink(
+                    os.path.join(self.resultdir, f)))
+
+    def test_make_from_filename(self):
+        """Test that make from works if ResultMap has no path
+        """
         results = ResultMap()
         results['1000'] =  S1_NAME
         results['2000'] =  S2_NAME
 
         results.make_tree_from(self.sourcedir, self.resultdir)
-
         sample1_dir = os.path.join(self.resultdir, S1_NAME)
         sample2_dir = os.path.join(self.resultdir, S2_NAME)
         self.failUnless(os.path.isdir(sample1_dir))
@@ -97,5 +116,7 @@ def suite():
     return suite
 
 if __name__ == "__main__":
+    import logging
+    logging.basicConfig(level=logging.DEBUG)
     from unittest2 import main
     main(defaultTest='suite')