-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add test for gto.api.check_ref * make error msg about incorrect name more precise * allow to specify tagger * rename GIT_COMMITTER to author * more efficient git ref lookup * use funcy * use tagger instead of GIT_COMMITTER
- Loading branch information
Showing
8 changed files
with
161 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"semver==3.0.0-dev.3", | ||
"entrypoints", | ||
"tabulate==0.8.9", | ||
"funcy", | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
"""TODO: add more tests for API""" | ||
import os | ||
from contextlib import contextmanager | ||
from typing import Callable, Tuple | ||
|
||
import git | ||
|
@@ -82,10 +84,21 @@ def test_register(repo_with_artifact): | |
) | ||
repo.index.commit("Irrelevant action to create a git commit") | ||
message = "Some message" | ||
gto.api.register(repo.working_dir, name, "HEAD", message=message) | ||
author = "GTO" | ||
author_email = "[email protected]" | ||
gto.api.register( | ||
repo.working_dir, | ||
name, | ||
"HEAD", | ||
message=message, | ||
author=author, | ||
author_email=author_email, | ||
) | ||
latest = gto.api.find_latest_version(repo.working_dir, name) | ||
assert latest.name == vname2 | ||
assert latest.message == message | ||
assert latest.author == author | ||
assert latest.author_email == author_email | ||
|
||
|
||
def test_promote(repo_with_artifact: Tuple[git.Repo, str]): | ||
|
@@ -94,17 +107,19 @@ def test_promote(repo_with_artifact: Tuple[git.Repo, str]): | |
repo.create_tag("v1.0.0") | ||
repo.create_tag("wrong-tag-unrelated") | ||
message = "some msg" | ||
author = "GTO" | ||
author_email = "[email protected]" | ||
gto.api.promote( | ||
repo.working_dir, | ||
name, | ||
stage, | ||
promote_ref="HEAD", | ||
name_version="v0.0.1", | ||
message=message, | ||
author=author, | ||
author_email=author_email, | ||
) | ||
promotion = gto.api.find_versions_in_stage(repo.working_dir, name, stage) | ||
author = repo.commit().author.name | ||
author_email = repo.commit().author.email | ||
_check_obj( | ||
promotion, | ||
dict( | ||
|
@@ -137,3 +152,51 @@ def test_promote_skip_registration(repo_with_artifact): | |
) | ||
promotion = gto.api.find_versions_in_stage(repo.working_dir, name, stage) | ||
assert not SemVer.is_valid(promotion.version) | ||
|
||
|
||
@contextmanager | ||
def environ(**overrides): | ||
old = {name: os.environ[name] for name in overrides if name in os.environ} | ||
to_del = set(overrides) - set(old) | ||
try: | ||
os.environ.update(overrides) | ||
yield | ||
finally: | ||
os.environ.update(old) | ||
for name in to_del: | ||
os.environ.pop(name, None) | ||
|
||
|
||
def test_check_ref(repo_with_artifact: Tuple[git.Repo, Callable]): | ||
repo, name = repo_with_artifact # pylint: disable=unused-variable | ||
|
||
NAME = "model" | ||
VERSION = "v1.2.3" | ||
GIT_AUTHOR_NAME = "Alexander Guschin" | ||
GIT_AUTHOR_EMAIL = "[email protected]" | ||
GIT_COMMITTER_NAME = "Oliwav" | ||
GIT_COMMITTER_EMAIL = "[email protected]" | ||
|
||
with environ( | ||
GIT_AUTHOR_NAME=GIT_AUTHOR_NAME, | ||
GIT_AUTHOR_EMAIL=GIT_AUTHOR_EMAIL, | ||
GIT_COMMITTER_NAME=GIT_COMMITTER_NAME, | ||
GIT_COMMITTER_EMAIL=GIT_COMMITTER_EMAIL, | ||
): | ||
gto.api.register(repo, name=NAME, ref="HEAD", version=VERSION) | ||
|
||
info = gto.api.check_ref(repo, f"{NAME}@{VERSION}")["version"][NAME] | ||
_check_obj( | ||
info, | ||
{ | ||
"artifact": NAME, | ||
"name": VERSION, | ||
"author": GIT_COMMITTER_NAME, | ||
"author_email": GIT_COMMITTER_EMAIL, | ||
"discovered": False, | ||
"tag": f"{NAME}@{VERSION}", | ||
"promotions": [], | ||
"enrichments": [], | ||
}, | ||
skip_keys={"commit_hexsha", "created_at", "message"}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
from typing import Any, Dict, Sequence, Set, Union | ||
|
||
from funcy import omit | ||
from pydantic import BaseModel | ||
|
||
# def _equals(a, b): | ||
# # separate function is helpful for debug | ||
# # cause you see dicts without skip_keys | ||
# assert a == b | ||
|
||
def _assert_equals(a, b): | ||
# separate function is helpful for debug | ||
# cause you see dicts without skip_keys | ||
assert a == b, f"\n{a} \n!=\n {b}" | ||
|
||
|
||
def _check_obj( | ||
obj: BaseModel, values: Dict[str, Any], skip_keys: Union[Set[str], Sequence[str]] | ||
): | ||
obj_values = obj.dict(exclude=set(skip_keys)) | ||
assert obj_values == values | ||
_assert_equals(obj_values, values) | ||
# assert obj_values == values | ||
|
||
|
||
def _check_dict( | ||
obj: Dict[str, Any], | ||
values: Dict[str, Any], | ||
skip_keys: Union[Set[str], Sequence[str]], | ||
): | ||
obj_values = {k: v for k, v in obj.items() if k not in skip_keys} | ||
values = {k: v for k, v in values.items() if k not in skip_keys} | ||
assert obj_values == values | ||
obj_values = omit(obj, skip_keys) | ||
values = omit(values, skip_keys) | ||
_assert_equals(obj_values, values) | ||
# assert obj_values == values |