def absolutePathAllTypes(self, user_vars=None): """Get the absolute paths for all_types. If the file has other file types in all_types (e.g. .shp, shx, .dbf) this will return the absolute paths for all of them. Args: user_vars(dict): a dict containing variable placeholder values as keys and the actual values as values. See TuflowPart.resolvePlaceholder() method for more information. """ rel_roots = self.getRelativeRoots([]) paths = [] if self.all_types: all_types = self.all_types else: all_types = [self.extension] for a in all_types: f = self.filename + '.' + a if self.has_own_root: fpath = PathHolder.absolutePath(self, filename=f) else: fpath = PathHolder.absolutePath(self, filename=f, relative_roots=rel_roots) # Replace any variable placeholders if given if user_vars: fpath = TuflowPart.resolvePlaceholder(fpath, user_vars) paths.append(fpath) return paths
def test_absolutePath(self): '''Test that the absolute path is returned correctly. ''' ph = PathHolder(self.fake_abs_path) abs_path = ph.absolutePath() self.assertEqual(self.fake_abs_path, abs_path, 'absolutePath() fail') ph = PathHolder(self.fake_relative_path) self.assertFalse(ph.absolutePath(), 'absolutePath() with relative root does not return False') ph = PathHolder(self.fake_relative_path, self.fake_root) q = ph.absolutePath() self.assertEqual('c:\\some\\fake\\root\\TuflowFile.txt', ph.absolutePath(), 'absolutePath() with root and relative root fail')
def test_absolutePath(self): '''Test that the absolute path is returned correctly. ''' ph = PathHolder(self.fake_abs_path) abs_path = ph.absolutePath() self.assertEqual(self.fake_abs_path, abs_path, 'absolutePath() fail') ph = PathHolder(self.fake_relative_path) self.assertFalse( ph.absolutePath(), 'absolutePath() with relative root does not return False') ph = PathHolder(self.fake_relative_path, self.fake_root) q = ph.absolutePath() self.assertEqual('c:\\some\\fake\\root\\TuflowFile.txt', ph.absolutePath(), 'absolutePath() with root and relative root fail')
def test_absolutePath(self): '''Test that the absolute path is returned correctly. ''' ph = PathHolder(self.fake_abs_path) abs_path = ph.absolutePath() self.assertEqual(self.fake_abs_path, abs_path, 'absolutePath() fail') ph = PathHolder(self.fake_relative_path) self.assertFalse( ph.absolutePath(), 'absolutePath() with relative root does not return False') ph = PathHolder(self.fake_relative_path, self.fake_root) q = ph.absolutePath() pth = os.path.join(self.prefix, 'some', 'fake', 'root', 'TuflowFile.txt') self.assertEqual(pth, ph.absolutePath(), 'absolutePath() with root and relative root fail')
def absolutePath(self, user_vars=None): """Get the absolute path of this object. Args: user_vars(dict): a dict containing variable placeholder values as keys and the actual values as values. See TuflowPart.resolvePlaceholder() method for more information. """ if self.has_own_root: abs_path = PathHolder.absolutePath(self) else: rel_roots = self.getRelativeRoots([]) abs_path = PathHolder.absolutePath(self, relative_roots=rel_roots) # Replace any variable placeholders if given if user_vars: abs_path = TuflowPart.resolvePlaceholder(abs_path, user_vars) return abs_path