2023-10-26 01:30:02 +00:00
|
|
|
import pytest
|
|
|
|
from langchain_cli.utils.git import parse_dependency_string, DependencySource
|
|
|
|
from langchain_cli.constants import (
|
|
|
|
DEFAULT_GIT_REPO,
|
|
|
|
DEFAULT_GIT_SUBDIRECTORY,
|
|
|
|
DEFAULT_GIT_REF,
|
|
|
|
)
|
2023-10-25 18:06:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_dependency_string() -> None:
|
2023-10-26 01:30:02 +00:00
|
|
|
assert parse_dependency_string(
|
2023-10-25 18:06:58 +00:00
|
|
|
"git+ssh://git@github.com/efriis/myrepo.git"
|
|
|
|
) == DependencySource(
|
|
|
|
git="ssh://git@github.com/efriis/myrepo.git",
|
|
|
|
ref=None,
|
|
|
|
subdirectory=None,
|
|
|
|
)
|
|
|
|
|
2023-10-26 01:30:02 +00:00
|
|
|
assert parse_dependency_string(
|
2023-10-25 18:06:58 +00:00
|
|
|
"git+https://github.com/efriis/myrepo.git#subdirectory=src"
|
|
|
|
) == DependencySource(
|
|
|
|
git="https://github.com/efriis/myrepo.git",
|
|
|
|
subdirectory="src",
|
|
|
|
ref=None,
|
|
|
|
)
|
|
|
|
|
2023-10-26 01:30:02 +00:00
|
|
|
assert parse_dependency_string(
|
2023-10-25 18:06:58 +00:00
|
|
|
"git+ssh://git@github.com:efriis/myrepo.git#develop"
|
|
|
|
) == DependencySource(
|
|
|
|
git="ssh://git@github.com:efriis/myrepo.git", ref="develop", subdirectory=None
|
|
|
|
)
|
|
|
|
|
2023-10-26 01:30:02 +00:00
|
|
|
# also support a slash in ssh
|
|
|
|
assert parse_dependency_string(
|
|
|
|
"git+ssh://git@github.com/efriis/myrepo.git#develop"
|
|
|
|
) == DependencySource(
|
|
|
|
git="ssh://git@github.com/efriis/myrepo.git", ref="develop", subdirectory=None
|
|
|
|
)
|
|
|
|
|
|
|
|
# looks like poetry supports both an @ and a #
|
|
|
|
assert parse_dependency_string(
|
|
|
|
"git+ssh://git@github.com:efriis/myrepo.git@develop"
|
|
|
|
) == DependencySource(
|
|
|
|
git="ssh://git@github.com:efriis/myrepo.git", ref="develop", subdirectory=None
|
|
|
|
)
|
|
|
|
|
|
|
|
assert parse_dependency_string("simple-pirate") == DependencySource(
|
2023-10-25 18:06:58 +00:00
|
|
|
git=DEFAULT_GIT_REPO,
|
|
|
|
subdirectory=f"{DEFAULT_GIT_SUBDIRECTORY}/simple-pirate",
|
2023-10-26 01:30:02 +00:00
|
|
|
ref=DEFAULT_GIT_REF,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_dependency_string_both() -> None:
|
|
|
|
assert parse_dependency_string(
|
|
|
|
"git+https://github.com/efriis/myrepo.git@branch#subdirectory=src"
|
|
|
|
) == DependencySource(
|
|
|
|
git="https://github.com/efriis/myrepo.git",
|
|
|
|
subdirectory="src",
|
|
|
|
ref="branch",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_dependency_string_invalids() -> None:
|
|
|
|
# expect error for wrong order
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
parse_dependency_string(
|
|
|
|
"git+https://github.com/efriis/myrepo.git#subdirectory=src@branch"
|
|
|
|
)
|
|
|
|
# expect error for @subdirectory
|
|
|
|
|
|
|
|
|
|
|
|
def test_dependency_string_edge_case() -> None:
|
|
|
|
# weird unsolvable edge case of
|
|
|
|
# git+ssh://a@b
|
|
|
|
# this could be a ssh dep with user=a, and default ref
|
|
|
|
# or a ssh dep at a with ref=b.
|
|
|
|
# in this case, assume the first case (be greedy with the '@')
|
|
|
|
assert parse_dependency_string("git+ssh://a@b") == DependencySource(
|
|
|
|
git="ssh://a@b",
|
|
|
|
subdirectory=None,
|
2023-10-25 18:06:58 +00:00
|
|
|
ref=None,
|
|
|
|
)
|
2023-10-26 01:30:02 +00:00
|
|
|
|
|
|
|
# weird one that is actually valid
|
|
|
|
assert parse_dependency_string(
|
|
|
|
"git+https://github.com/efriis/myrepo.git@subdirectory=src"
|
|
|
|
) == DependencySource(
|
|
|
|
git="https://github.com/efriis/myrepo.git",
|
|
|
|
subdirectory=None,
|
|
|
|
ref="subdirectory=src",
|
|
|
|
)
|