Пример #1
0
def test_process_no_files_regex(monkeypatch, capsys):
    monkeypatch.setattr(
        'sys.stdin',
        io.StringIO('needles kjkj need g\nnedned ghjf\nneedle aaa\n'))
    grep.process(sys.stdin, ' ', False, 'needle', True, False, False, False,
                 False, False, False)
    out, err = capsys.readouterr()
    assert err == ''
    assert out == 'needles kjkj need g\nneedle aaa\n'
Пример #2
0
def test_process_one_file_count(tmp_path, monkeypatch, capsys):
    (tmp_path / 'a.txt').write_text('pref needle\nneedle suf\n')
    monkeypatch.chdir(tmp_path)
    with open('a.txt') as new:
        grep.process(new, 'a.txt', False, 'needle', False, True, False, False,
                     False, False, False)
    out, err = capsys.readouterr()
    assert err == ''
    assert out == '2\n'
Пример #3
0
def test_process_various_files_regex(tmp_path, monkeypatch, capsys):
    (tmp_path /
     'a.txt').write_text('pref needles\n afhfk suf\nneedle needle bbb\n')
    (tmp_path / 'b.txt').write_text('the needling\npref needle suf')
    monkeypatch.chdir(tmp_path)
    with open('a.txt') as new:
        grep.process(new, 'a.txt', True, 'needle', True, False, False, False,
                     False, False, False)
    out, err = capsys.readouterr()
    assert err == ''
    assert out == 'a.txt:pref needles\na.txt:needle needle bbb\n'