Skip to content

Commit

Permalink
feat: Add E2E Test
Browse files Browse the repository at this point in the history
A brief snapshot test to keep everything in line as changes occur in the future.
  • Loading branch information
thehale committed Nov 10, 2024
1 parent 2a44258 commit 009a23f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
25 changes: 15 additions & 10 deletions git_authorship/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@ def parse_args(argv=None) -> Args:
return Args(args.location, args.clone_to, args.branch)


def ensure_cloned_and_pulled(location: str, clone_to: str):
log.info(f"Cloning {location} to {clone_to}")
if not Path(clone_to).exists():
Repo.clone_from(location, clone_to)
else:
Repo(clone_to).git.pull()
def clone_and_checkout(args: Args):
log.info(f"Cloning {args.location} @ {args.branch} to {args.clone_to}")

return Repo(clone_to)
if not Path(args.clone_to).exists():
Repo.clone_from(args.location, args.clone_to)

repo = Repo(args.clone_to)

def main(argv=None):
args = parse_args(argv)
repo = ensure_cloned_and_pulled(args.location, args.clone_to)
if args.branch:
repo.git.checkout(args.branch)

return repo


def run(args: Args):
repo = clone_and_checkout(args)
repo_authorship = authorship.for_repo(repo)
export.as_treemap(repo_authorship)
export.as_json(repo_authorship)


def main(argv=None):
run(parse_args(argv))
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mypy = "^1.13"
pre-commit = "^3.5.0"
pytest = "^8.3.3"
liccheck = "^0.9.2"
pytest-snapshot = "^0.9.0"

[tool.liccheck]
authorized_licenses = [
Expand Down
1 change: 1 addition & 0 deletions test/snapshots/test_e2e/test_full_workflow/authorship.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{".": {"Joseph Hale <[email protected]>": 241532, "Joseph Hale <[email protected]>": 74, "dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>": 116}, "git_authorship": {"Joseph Hale <[email protected]>": 171}, "git_authorship/__main__.py": {"Joseph Hale <[email protected]>": 166}, "git_authorship/__init__.py": {"Joseph Hale <[email protected]>": 5}, ".gitignore": {"Joseph Hale <[email protected]>": 169}, "LICENSE": {"Joseph Hale <[email protected]>": 373}, "README.md": {"Joseph Hale <[email protected]>": 139, "Joseph Hale <[email protected]>": 5}, ".devcontainer": {"Joseph Hale <[email protected]>": 41}, ".devcontainer/devcontainer.json": {"Joseph Hale <[email protected]>": 32}, ".devcontainer/Dockerfile": {"Joseph Hale <[email protected]>": 9}, "pyproject.toml": {"Joseph Hale <[email protected]>": 45, "dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>": 7}, "docs": {"Joseph Hale <[email protected]>": 240056}, "docs/git-authorship-demo-cubingjs.gif": {"Joseph Hale <[email protected]>": 238279}, "docs/git-authorship-social-preview.svg": {"Joseph Hale <[email protected]>": 1111}, "docs/git-authorship-social-preview.png": {"Joseph Hale <[email protected]>": 666}, "config": {"Joseph Hale <[email protected]>": 12}, "config/.gitignore": {"Joseph Hale <[email protected]>": 8}, "config/pseudonyms.txt.dist": {"Joseph Hale <[email protected]>": 2}, "config/author-licenses.txt.dist": {"Joseph Hale <[email protected]>": 2}, "poetry.lock": {"dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>": 109, "Joseph Hale <[email protected]>": 433}, ".github": {"Joseph Hale <[email protected]>": 69, "Joseph Hale <[email protected]>": 13}, ".github/dependabot.yml": {"Joseph Hale <[email protected]>": 22}, ".github/workflows": {"Joseph Hale <[email protected]>": 47, "Joseph Hale <[email protected]>": 13}, ".github/workflows/auto-merge-dependabot.yml": {"Joseph Hale <[email protected]>": 23}, ".github/workflows/precommit.yml": {"Joseph Hale <[email protected]>": 24, "Joseph Hale <[email protected]>": 13}, "test": {"Joseph Hale <[email protected]>": 9}, "test/test_authorship_analyzer.py": {"Joseph Hale <[email protected]>": 9}, ".vscode": {"Joseph Hale <[email protected]>": 16}, ".vscode/launch.json": {"Joseph Hale <[email protected]>": 16}, "Makefile": {"Joseph Hale <[email protected]>": 13}, ".pre-commit-config.yaml": {"Joseph Hale <[email protected]>": 42}}
15 changes: 15 additions & 0 deletions test/test_e2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from git_authorship.cli import Args
from git_authorship.cli import run


def test_full_workflow(snapshot):
run(
Args(
location="https://github.com/thehale/git-authorship",
clone_to="./build/test/e2e",
branch="b655cc6c634a52660d3d2e87f9978343c92aa998",
)
)

with open("build/authorship.json", "r") as f:
snapshot.assert_match(f.read(), "authorship.json")

0 comments on commit 009a23f

Please sign in to comment.