def relPaths(self, vals): for val in vals: if self.isFileBasedBackend(val["dbtype"]): db = val["database"] if os.path.exists(db): val["database"] = utils.relativePath(db, self.Application.HomeDirectory) return vals
def test_Pathing(self): prfx = utils.getPathAttributePrefix() pth = "a/b/file2" self.assertEqual(utils.resolvePath(pth), "a/b/file2") pth2 = "../../file2" self.assertEqual(utils.resolvePath(pth2, "a1/b1"), "../../file2") self.assertEqual(utils.relativePath(pth), "a/b/file2") self.assertEqual(utils.relativePath(pth2), "../../file2") self.assertEqual(utils.relativePath(pth,pth2), "../tmp/relpath_tests_dir/a/b/file2") self.assertEqual(utils.relativePathList(pth,pth2), ["..", "tmp", "relpath_tests_dir", "a", "b", "file2"]) atts = {"Foo": "Bar", "ThePath": "%s../some/file.txt" % prfx} utils.resolveAttributePathing(atts, os.getcwd()) self.assertEqual(atts, {"Foo": "Bar", "ThePath": "../some/file.txt"}) atts = {"Foo": "Bar", "ThePath": "%sa/b/file2" % prfx} utils.resolveAttributePathing(atts, os.getcwd()) self.assertEqual(atts, {"Foo": "Bar", "ThePath": "a/b/file2"}) atts = {"Foo": "Bar", "ThePath": "%s../a/b/file2" % prfx} utils.resolveAttributePathing(atts, "a1/") self.assertEqual(atts, {"Foo": "Bar", "ThePath": "../a/b/file2"})
def test_Pathing(self): prfx = utils.getPathAttributePrefix() pth = "a/b/file2" self.assertEqual(utils.resolvePath(pth), "a/b/file2") pth2 = "../../file2" self.assertEqual(utils.resolvePath(pth2, "a1/b1"), "../../file2") self.assertEqual(utils.relativePath(pth), "a/b/file2") self.assertEqual(utils.relativePath(pth2), "../../file2") self.assertEqual(utils.relativePath(pth, pth2), "../tmp/relpath_tests_dir/a/b/file2") self.assertEqual(utils.relativePathList(pth, pth2), ["..", "tmp", "relpath_tests_dir", "a", "b", "file2"]) atts = {"Foo": "Bar", "ThePath": "%s../some/file.txt" % prfx} utils.resolveAttributePathing(atts, os.getcwd()) self.assertEqual(atts, {"Foo": "Bar", "ThePath": "../some/file.txt"}) atts = {"Foo": "Bar", "ThePath": "%sa/b/file2" % prfx} utils.resolveAttributePathing(atts, os.getcwd()) self.assertEqual(atts, {"Foo": "Bar", "ThePath": "a/b/file2"}) atts = {"Foo": "Bar", "ThePath": "%s../a/b/file2" % prfx} utils.resolveAttributePathing(atts, "a1/") self.assertEqual(atts, {"Foo": "Bar", "ThePath": "../a/b/file2"})