-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Improve e2e test performance
I don't need to download and clone an entire respository (though it's a nice test). Using a locally created repository instead makes the test easier to review and faster to execute.
- Loading branch information
Showing
10 changed files
with
104 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
# Generated Project Files | ||
repo | ||
tmp | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
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
Empty file.
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 +1 @@ | ||
Joseph Hale <[email protected]>,MPL-2.0 | ||
Alice <[email protected]>,MPL-2.0 |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from pathlib import Path | ||
from typing import List | ||
from typing import Tuple | ||
from typing import Union | ||
|
||
from git import Actor | ||
from git import Repo | ||
|
||
Message = str | ||
AuthorName = str | ||
AuthorEmail = str | ||
|
||
CommitMessage = Tuple[Message, AuthorName, AuthorEmail] | ||
|
||
FilePath = str | ||
FileContent = Union[List[str], str] | ||
Change = Tuple[FilePath, FileContent] | ||
|
||
|
||
class TemporaryRepository: | ||
def __init__(self, directory: str): | ||
self._repo = Repo.init(directory) | ||
self._index = self._repo.index | ||
|
||
@property | ||
def dir(self): | ||
return self._repo.working_dir | ||
|
||
@property | ||
def branch(self) -> str: | ||
return self._repo.active_branch.name | ||
|
||
def set_file(self, path: str, content: Union[str, List[str]]): | ||
""" | ||
Updates a file in the repository to the given content, creating it if necessary. | ||
""" | ||
if isinstance(content, list): | ||
content = "\n".join(content) | ||
|
||
with open(Path(self.dir) / path, "w") as f: | ||
f.write(content) | ||
|
||
self._index.add(path) | ||
|
||
def append_file(self, path: str, content: Union[str, List[str]]): | ||
if isinstance(content, list): | ||
content = "\n".join(content) | ||
|
||
with open(Path(self.dir) / path, "a") as f: | ||
f.write(content) | ||
|
||
self._index.add(path) | ||
|
||
def commit(self, message: str, author_name: str, author_email: str): | ||
author = Actor(author_name, author_email) | ||
self._index.commit(message, author=author) |
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
test/snapshots/test_e2e/test_full_workflow_with_author_licenses/authorship.csv
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
path,author,lines,license | ||
.,Alice <[email protected]>,1, | ||
.,Bob <[email protected]>,1, | ||
greeting.txt,Alice <[email protected]>,1, | ||
greeting.txt,Bob <[email protected]>,1, |
5 changes: 5 additions & 0 deletions
5
test/snapshots/test_e2e/test_workflow_with_author_licenses/authorship.csv
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
path,author,lines,license | ||
.,Alice <[email protected]>,1,MPL-2.0 | ||
.,Bob <[email protected]>,1, | ||
greeting.txt,Alice <[email protected]>,1,MPL-2.0 | ||
greeting.txt,Bob <[email protected]>,1, |
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,32 +1,41 @@ | ||
from git_authorship.cli import Args | ||
from tempfile import TemporaryDirectory | ||
from test.fixtures.tmp_repo import TemporaryRepository | ||
|
||
import pytest | ||
|
||
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", | ||
author_licenses_path=None, | ||
use_cache=False, | ||
) | ||
) | ||
@pytest.fixture | ||
def repo(): | ||
with TemporaryDirectory() as d: | ||
repo = TemporaryRepository(d) | ||
|
||
repo.set_file("greeting.txt", "Hello, world!\n") | ||
repo.commit("Initial commit", "Alice", "[email protected]") | ||
|
||
repo.append_file("greeting.txt", "Excited to be here!\n") | ||
repo.commit("Second commit", "Bob", "[email protected]") | ||
|
||
yield repo | ||
|
||
|
||
def test_typical_workflow(snapshot, repo: TemporaryRepository): | ||
run([repo.dir, "--clone-to", "./tmp", "--no-cache"]) | ||
|
||
with open("build/authorship.csv", "r") as f: | ||
snapshot.assert_match(f.read(), "authorship.csv") | ||
|
||
|
||
def test_full_workflow_with_author_licenses(snapshot): | ||
run( | ||
Args( | ||
location="https://github.com/thehale/git-authorship", | ||
clone_to="./build/test/e2e", | ||
branch="b655cc6c634a52660d3d2e87f9978343c92aa998", | ||
author_licenses_path="./test/fixtures/licensing.csv", | ||
use_cache=False, | ||
) | ||
) | ||
def test_workflow_with_author_licenses(snapshot, repo: TemporaryRepository): | ||
# fmt: off | ||
run([ | ||
repo.dir, | ||
"--author-licenses", "./test/fixtures/licensing.csv", | ||
"--clone-to", "./tmp", | ||
"--no-cache", | ||
]) | ||
# fmt: on | ||
|
||
with open("build/authorship.csv", "r") as f: | ||
snapshot.assert_match(f.read(), "authorship.csv") |