feat: read file paths from stdin and print plain paths from piped ls
This commit is contained in:
parent
9743103faf
commit
98044782e5
4 changed files with 119 additions and 20 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import io
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
|
@ -64,3 +65,55 @@ def test_scan_replace(otag, tmp_path):
|
|||
(tmp_path / orvani.CONTEXT_FILE).write_text('a.py --- #one #gone\n')
|
||||
otag('s', '--replace')
|
||||
assert (tmp_path / orvani.CONTEXT_FILE).read_text() == 'a.py --- #one\n'
|
||||
|
||||
|
||||
def test_add_reads_piped_paths(otag, tmp_path, monkeypatch):
|
||||
for name in ['a.mp3', 'b c.mp3']:
|
||||
(tmp_path / name).touch()
|
||||
monkeypatch.setattr(sys, 'stdin', io.StringIO('a.mp3\n\nb c.mp3\n'))
|
||||
otag('a', '-', '#lofi')
|
||||
assert (tmp_path / orvani.CONTEXT_FILE).read_text() == 'a.mp3 --- #lofi\nb c.mp3 --- #lofi\n'
|
||||
|
||||
|
||||
def test_piped_failures_do_not_stop_the_rest(otag, tmp_path, monkeypatch, capsys):
|
||||
(tmp_path / 'b.mp3').touch()
|
||||
monkeypatch.setattr(sys, 'stdin', io.StringIO('missing.mp3\nb.mp3\n'))
|
||||
monkeypatch.setattr(sys, 'argv', ['otag', 'a', '-', '#lofi'])
|
||||
with pytest.raises(SystemExit) as exit:
|
||||
main()
|
||||
assert exit.value.code == 1
|
||||
assert "File missing.mp3 doesn't exist." in capsys.readouterr().out
|
||||
assert (tmp_path / orvani.CONTEXT_FILE).read_text() == 'b.mp3 --- #lofi\n'
|
||||
|
||||
|
||||
def test_remove_and_write_read_piped_paths(otag, tmp_path, monkeypatch):
|
||||
for name in ['a.py', 'b.py']:
|
||||
(tmp_path / name).write_text('x = 1\n')
|
||||
otag('a', name, '#one')
|
||||
monkeypatch.setattr(sys, 'stdin', io.StringIO('a.py\nb.py\n'))
|
||||
otag('w', 'comment', '-')
|
||||
assert (tmp_path / 'a.py').read_text().startswith('# otag: #one')
|
||||
assert (tmp_path / 'b.py').read_text().startswith('# otag: #one')
|
||||
|
||||
monkeypatch.setattr(sys, 'stdin', io.StringIO('a.py\nb.py\n'))
|
||||
otag('rm', '-')
|
||||
assert not (tmp_path / orvani.CONTEXT_FILE).exists()
|
||||
|
||||
|
||||
def test_export_dash_is_a_file_name(otag, tmp_path, monkeypatch):
|
||||
(tmp_path / 'a.mp3').touch()
|
||||
otag('a', 'a.mp3', '#lofi')
|
||||
monkeypatch.setattr(sys, 'stdin', io.StringIO('a.mp3\n'))
|
||||
otag('e', '-')
|
||||
assert (tmp_path / '-').read_text() == 'a.mp3 --- #lofi\n'
|
||||
|
||||
|
||||
def test_piped_list_prints_bare_paths(otag, tmp_path):
|
||||
(tmp_path / 'sub').mkdir()
|
||||
(tmp_path / 'sub' / 'a long name that a table would wrap.mp3').touch()
|
||||
otag('a', 'sub', '#lofi')
|
||||
otag('a', 'sub/a long name that a table would wrap.mp3', '#lofi', 'a note')
|
||||
assert otag('ls', '#lofi') == 'sub\nsub/a long name that a table would wrap.mp3\n'
|
||||
assert otag('ls', '--files') == 'sub/a long name that a table would wrap.mp3\n'
|
||||
assert otag('ls', '-d') == 'sub\n'
|
||||
assert otag('ls', '#none') == ''
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ def test_cmd_user_errors_exit_with_1(cwd, monkeypatch, capsys):
|
|||
def test_cmd_list_shows_square_brackets(cwd, monkeypatch, capsys):
|
||||
(cwd / 'a [demo].mp3').touch()
|
||||
OrvaniTag().add('a [demo].mp3', '#lofi', 'note', '[with]', 'brackets')
|
||||
monkeypatch.setattr(sys.stdout, 'isatty', lambda: True) # the table, not piped output
|
||||
monkeypatch.setattr(sys, 'argv', ['otag', 'ls', '#lofi'])
|
||||
main()
|
||||
out = capsys.readouterr().out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue