-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added test for files * added test for git * added function alias * added tests for console * added tests for containers * added tests for internal
- Loading branch information
Showing
6 changed files
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
|
||
from cookieplone.utils import console | ||
|
||
|
||
@patch("cookieplone.utils.console.print") | ||
def test_print_plone_banner(mock_print): | ||
console.print_plone_banner() | ||
mock_print.assert_called_once_with(console.BANNER, "bold", "blue") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func,msg,style,color", | ||
[ | ||
[console.info, "foo", "bold", "white"], | ||
[console.success, "foo", "bold", "green"], | ||
[console.error, "foo", "bold", "red"], | ||
[console.warning, "foo", "bold", "yellow"], | ||
], | ||
) | ||
@patch("cookieplone.utils.console.print") | ||
def test_prints(mock_print, func, msg, style, color): | ||
func(msg) | ||
mock_print.assert_called_once_with(msg, style, color) |
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,16 @@ | ||
import pytest | ||
|
||
from cookieplone.utils import containers | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"registry,expected", | ||
[ | ||
["docker_hub", ""], | ||
["github", "ghcr.io/"], | ||
["gitlab", "registry.gitlab.com/"], | ||
["bitbucket", ""], | ||
], | ||
) | ||
def test_image_prefix(registry, expected): | ||
assert containers.image_prefix(registry) == expected |
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,44 @@ | ||
import pytest | ||
|
||
from cookieplone.utils import files | ||
|
||
|
||
@pytest.fixture | ||
def tmp_files(tmp_path): | ||
folder1 = tmp_path / "test" / ".github" | ||
folder1.mkdir(parents=True) | ||
|
||
file1 = tmp_path / "test" / "test_file.txt" | ||
file1.touch() | ||
|
||
return file1 | ||
|
||
|
||
def test_remove_files(tmp_path, tmp_files): | ||
files_to_remove = tmp_files | ||
folders_to_remove = tmp_files.parent | ||
func = files.remove_files | ||
|
||
assert files_to_remove.exists() | ||
func(tmp_path, [files_to_remove]) | ||
assert not files_to_remove.exists() | ||
|
||
assert folders_to_remove.exists() | ||
func(tmp_path, [folders_to_remove]) | ||
assert not folders_to_remove.exists() | ||
|
||
|
||
def test_remove_files_nonexistent_file(tmp_path): | ||
files_to_remove = ["nonexistent_file.txt"] | ||
base_path = tmp_path | ||
assert files.remove_files(base_path, files_to_remove) == None | ||
|
||
|
||
def test_remove_gha(tmp_files): | ||
func = files.remove_gha | ||
base_path = tmp_files.parent | ||
|
||
gha = base_path / ".github" | ||
assert gha.exists() | ||
func(base_path) | ||
assert not gha.exists() |
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,47 @@ | ||
import pytest | ||
|
||
from git import Repo, Commit | ||
|
||
from cookieplone.utils import git | ||
|
||
|
||
@pytest.fixture | ||
def tmp_repo(tmp_path): | ||
repo = Repo.init(tmp_path) | ||
repo.index.add(tmp_path) | ||
repo.index.commit("test commit") | ||
|
||
return tmp_path | ||
|
||
|
||
def test_repo_from_path(tmp_repo): | ||
repo = git.repo_from_path(tmp_repo) | ||
assert repo == Repo(tmp_repo) | ||
|
||
|
||
def test_repo_from_path_invalid(tmp_path): | ||
repo = git.repo_from_path(tmp_path) | ||
assert repo is None | ||
|
||
|
||
def test_check_path_is_repository(tmp_repo): | ||
assert git.check_path_is_repository(tmp_repo) | ||
|
||
|
||
def test_check_path_is_repository_invalid(tmp_path): | ||
assert not git.check_path_is_repository(tmp_path) | ||
|
||
|
||
def test_initialize_repository(tmp_path): | ||
repo = git.initialize_repository(tmp_path) | ||
assert isinstance(repo, Repo) | ||
|
||
|
||
def test_get_last_commit(tmp_repo): | ||
commit = git.get_last_commit(tmp_repo) | ||
assert isinstance(commit, Commit) | ||
assert commit.summary == "test commit" | ||
|
||
|
||
def test_get_last_commit_invalid(tmp_path): | ||
assert git.get_last_commit(tmp_path) is None |
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,19 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from cookiecutter import __version__ as __cookiecutter_version__ | ||
from cookieplone import __version__ | ||
from cookieplone.utils import internal | ||
|
||
|
||
def test_version_info(): | ||
result = internal.version_info() | ||
location = Path(__file__).parent.parent.parent / "cookieplone" | ||
expected = ( | ||
f"Cookieplone {__version__} from {location} " | ||
f"(Cookiecutter {__cookiecutter_version__}, " | ||
f"Python {sys.version})" | ||
) | ||
assert result == expected |