From d4f592d5c162b136cdf38a5626cea97b9e7844df Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 18 Jun 2013 11:59:13 -0700 Subject: [PATCH] Further improve reliability of make_tree_from. 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 | 9 ++++++-- htsworkflow/submission/test/test_results.py | 25 +++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/htsworkflow/submission/results.py b/htsworkflow/submission/results.py index 4f815ad..36c2c78 100644 --- a/htsworkflow/submission/results.py +++ b/htsworkflow/submission/results.py @@ -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): diff --git a/htsworkflow/submission/test/test_results.py b/htsworkflow/submission/test/test_results.py index 3487b69..b7d6acc 100644 --- a/htsworkflow/submission/test/test_results.py +++ b/htsworkflow/submission/test/test_results.py @@ -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') -- 2.30.2