Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvc: override replace in HTTPURLInfo to include extra_parts #4517

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dvc/path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ def __init__(self, url):
self.query = p.query
self.fragment = p.fragment

def replace(self, path=None):
MetalBlueberry marked this conversation as resolved.
Show resolved Hide resolved
return self.from_parts(
*self._base_parts,
params=self.params,
query=self.query,
fragment=self.fragment,
path=path,
)

@classmethod
def from_parts(
cls,
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]/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