From 79e8e4edafb8a4745200f0a62f49c29ef074bdea Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 3 Sep 2020 14:47:18 +0200 Subject: [PATCH] dvc: override replace in HTTPURLInfo to include extra_parts (#4517) * dvc: override replace in HTTPURLInfo to include extra_parts The objective is to passtrough any parameter configured in http remotes. fixes #4508 * add unit test for #4508 * Use HTTPURLInfo directly instead of decorator --- dvc/path_info.py | 9 +++++++++ tests/unit/test_path_info.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/dvc/path_info.py b/dvc/path_info.py index 62b02e0046..18ffaf04ae 100644 --- a/dvc/path_info.py +++ b/dvc/path_info.py @@ -253,6 +253,15 @@ def __init__(self, url): self.query = p.query self.fragment = p.fragment + def replace(self, path=None): + return self.from_parts( + *self._base_parts, + params=self.params, + query=self.query, + fragment=self.fragment, + path=path, + ) + @classmethod def from_parts( cls, diff --git a/tests/unit/test_path_info.py b/tests/unit/test_path_info.py index 688cf1fb2c..9f4ba3e1bc 100644 --- a/tests/unit/test_path_info.py +++ b/tests/unit/test_path_info.py @@ -85,3 +85,20 @@ def test_https_url_info_str(): def test_path_info_as_posix(mocker, path, as_posix, osname): mocker.patch("os.name", osname) assert PathInfo(path).as_posix() == as_posix + + +def test_url_replace_path(): + url = "https://user@test.com/original/path;p=par?q=quer#frag" + + u = HTTPURLInfo(url) + new_u = u.replace("/new/path") + + assert u.path == "/original/path" + assert new_u.path == "/new/path" + + assert u.scheme == new_u.scheme + assert u.host == new_u.host + assert u.user == new_u.user + assert u.params == new_u.params + assert u.query == new_u.query + assert u.fragment == new_u.fragment