-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a separate test file for show cmd tests
- Loading branch information
Showing
3 changed files
with
100 additions
and
87 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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from pyzet import constants as C | ||
from pyzet.main import main | ||
|
||
TEST_CFG = ('--config', f'testing/{C.CONFIG_FILE}') | ||
|
||
|
||
@pytest.fixture | ||
def pyzet_init(tmp_path): | ||
init_dir = tmp_path.as_posix() | ||
main([*TEST_CFG, 'init', init_dir]) | ||
yield init_dir |
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 |
---|---|---|
|
@@ -16,13 +16,6 @@ def set_info_lvl(caplog): | |
caplog.set_level(logging.INFO) | ||
|
||
|
||
@pytest.fixture | ||
def pyzet_init(tmp_path): | ||
init_dir = tmp_path.as_posix() | ||
main([*TEST_CFG, 'init', init_dir]) | ||
yield init_dir | ||
|
||
|
||
def test_no_argv(capsys): | ||
# It should just print the usage help | ||
main([]) | ||
|
@@ -146,86 +139,6 @@ def test_edit_error_missing_repo_in_yaml(): | |
) | ||
|
||
|
||
def test_show(capsys): | ||
main([*TEST_CFG, 'show', 'text', '20211016205158']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out.endswith( | ||
'# Zet test entry\n\nHello there!\n\nTags:\n\n' | ||
' #test-tag #another-tag #tag-after-two-spaces\n' | ||
) | ||
assert err == '' | ||
|
||
|
||
def test_show_default(capsys): | ||
# by default, the command shows a zettel with the highest ID (the newest) | ||
main([*TEST_CFG, 'show', 'text']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out.endswith('# Zettel with UTF-8\n\nZażółć gęślą jaźń.\n') | ||
assert err == '' | ||
|
||
|
||
def test_show_utf8(capsys): | ||
main([*TEST_CFG, 'show', 'text', '20220101220852']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out.endswith('# Zettel with UTF-8\n\nZażółć gęślą jaźń.\n') | ||
assert err == '' | ||
|
||
|
||
def test_show_mdlink(capsys): | ||
main([*TEST_CFG, 'show', 'mdlink', '20211016205158']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == '* [20211016205158](../20211016205158) Zet test entry\n' | ||
assert err == '' | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('raw', 'expected'), | ||
( | ||
( | ||
'https://github.com/tpwo/pyzet', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'https://github.com/tpwo/pyzet.git', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:tpwo/pyzet', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:tpwo/pyzet.git', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:user/repo.git', | ||
'https://gitlab.com/user/repo/-/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:user/repo.git', | ||
'https://bitbucket.org/user/repo/src/main/zettels/20211016205159', | ||
), | ||
), | ||
) | ||
def test_show_url(raw, expected, pyzet_init, capsys): | ||
subprocess.run(('git', '-C', pyzet_init, 'remote', 'add', 'origin', raw)) | ||
id_ = '20211016205159' | ||
test_zettel = Path(pyzet_init, C.ZETDIR, id_) | ||
test_zettel.mkdir(parents=True) | ||
with open(Path(test_zettel, C.ZETTEL_FILENAME), 'w') as file: | ||
file.write('# Test') | ||
|
||
main([*TEST_CFG, '--repo', pyzet_init, 'show', 'url', id_]) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == expected + '\n' | ||
assert err == '' | ||
|
||
|
||
def test_list(capsys): | ||
main([*TEST_CFG, 'list']) | ||
|
||
|
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,90 @@ | ||
from __future__ import annotations | ||
|
||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from pyzet import constants as C | ||
from pyzet.main import main | ||
from tests.conftest import TEST_CFG | ||
|
||
|
||
def test_show(capsys): | ||
main([*TEST_CFG, 'show', 'text', '20211016205158']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out.endswith( | ||
'# Zet test entry\n\nHello there!\n\nTags:\n\n' | ||
' #test-tag #another-tag #tag-after-two-spaces\n' | ||
) | ||
assert err == '' | ||
|
||
|
||
def test_show_default(capsys): | ||
# by default, the command shows a zettel with the highest ID (the newest) | ||
main([*TEST_CFG, 'show', 'text']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out.endswith('# Zettel with UTF-8\n\nZażółć gęślą jaźń.\n') | ||
assert err == '' | ||
|
||
|
||
def test_show_utf8(capsys): | ||
main([*TEST_CFG, 'show', 'text', '20220101220852']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out.endswith('# Zettel with UTF-8\n\nZażółć gęślą jaźń.\n') | ||
assert err == '' | ||
|
||
|
||
def test_show_mdlink(capsys): | ||
main([*TEST_CFG, 'show', 'mdlink', '20211016205158']) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == '* [20211016205158](../20211016205158) Zet test entry\n' | ||
assert err == '' | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('raw', 'expected'), | ||
( | ||
( | ||
'https://github.com/tpwo/pyzet', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'https://github.com/tpwo/pyzet.git', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:tpwo/pyzet', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:tpwo/pyzet.git', | ||
'https://github.com/tpwo/pyzet/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:user/repo.git', | ||
'https://gitlab.com/user/repo/-/tree/main/zettels/20211016205159', | ||
), | ||
( | ||
'[email protected]:user/repo.git', | ||
'https://bitbucket.org/user/repo/src/main/zettels/20211016205159', | ||
), | ||
), | ||
) | ||
def test_show_url(raw, expected, pyzet_init, capsys): | ||
subprocess.run(('git', '-C', pyzet_init, 'remote', 'add', 'origin', raw)) | ||
id_ = '20211016205159' | ||
test_zettel = Path(pyzet_init, C.ZETDIR, id_) | ||
test_zettel.mkdir(parents=True) | ||
with open(Path(test_zettel, C.ZETTEL_FILENAME), 'w') as file: | ||
file.write('# Test') | ||
|
||
main([*TEST_CFG, '--repo', pyzet_init, 'show', 'url', id_]) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == expected + '\n' | ||
assert err == '' |