Skip to content

Commit

Permalink
Add missing tests - vol. 10
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Jun 22, 2023
1 parent 1e5b98a commit 532ae1e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
File renamed without changes.
5 changes: 2 additions & 3 deletions tests/mockers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ def mock_input_returning_y(msg: str) -> str:
def mock_input_returning(*answers: str) -> Callable[[str], str]:
class Wrapper(object):
def __init__(self) -> None:
self.index = -1
self.gen = (ans for ans in answers)

def __call__(self, msg: str) -> str:
print(msg)
self.index += 1
return answers[self.index]
return next(self.gen)

return Wrapper()
49 changes: 48 additions & 1 deletion tests/test_traverse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from tempfile import mkdtemp

from pytest_mock import MockerFixture

Expand Down Expand Up @@ -935,11 +936,57 @@ def test_reset_to_remote_after_rebase(self) -> None:
"""
)

def test_quit_on_pushing_untracked(self, mocker: MockerFixture) -> None:
def test_traverse_quit_on_pushing_untracked(self, mocker: MockerFixture) -> None:
self.repo_sandbox.new_branch("master").commit()
rewrite_definition_file("master")
self.patch_symbol(mocker, 'builtins.input', mock_input_returning("q"))
assert_success(
["traverse"],
"Push untracked branch master to origin? (y, N, q, yq) \n"
)

def test_traverse_multiple_remotes(self, mocker: MockerFixture) -> None:
origin_1_remote_path = mkdtemp()
origin_2_remote_path = mkdtemp()
(
self.repo_sandbox
.remove_remote("origin")
.new_repo(origin_1_remote_path, bare=True, switch_dir_to_new_repo=False)
.add_remote("origin_1", origin_1_remote_path)
.new_repo(origin_2_remote_path, bare=True, switch_dir_to_new_repo=False)
.add_remote("origin_2", origin_2_remote_path)
)

self.repo_sandbox.new_branch("master").commit()
rewrite_definition_file("master")

self.patch_symbol(mocker, 'builtins.input', mock_input_returning("xd"))
assert_success(
["traverse"],
"""
Branch master is untracked and there's no origin repository.
[1] origin_1
[2] origin_2
Select number 1..2 to specify the destination remote repository, or 'n' to skip this branch, or 'q' to quit the traverse:
master * (untracked)
Reached branch master which has no successor; nothing left to update
"""
)

self.patch_symbol(mocker, 'builtins.input', mock_input_returning("1", "o", "2", "yq"))
assert_success(
["traverse"],
"""
Branch master is untracked and there's no origin repository.
[1] origin_1
[2] origin_2
Select number 1..2 to specify the destination remote repository, or 'n' to skip this branch, or 'q' to quit the traverse:
Push untracked branch master to origin_1? (y, N, q, yq, o[ther-remote])
[1] origin_1
[2] origin_2
Select number 1..2 to specify the destination remote repository, or 'n' to skip this branch, or 'q' to quit the traverse:
Push untracked branch master to origin_2? (y, N, q, yq, o[ther-remote])
"""
)
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ commands = {posargs}
[testenv:coverage-py36]
description = "Check the test coverage of the code"
deps =
-r{toxinidir}/requirements.coverage-py36.txt
-r{toxinidir}/requirements.coverage.py36-txt
passenv = PYTHON_VERSION
allowlist_externals = cp
commands =
Expand All @@ -85,7 +85,7 @@ commands =
# Prints a report to console
coverage report
# Saves a report to htmlcov/
coverage html
coverage html --show-contexts
cp .coverage .coverage.{env:PYTHON_VERSION:bin}

[testenv:coverage-{py37,py38,py39,py310,py311}]
Expand All @@ -98,6 +98,7 @@ commands =
{[testenv:coverage-py36]commands}

[coverage:run]
dynamic_context = test_function
relative_files = True

[coverage:report]
Expand Down

0 comments on commit 532ae1e

Please sign in to comment.