コード例 #1
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_no_report_option(capsys):
    args = [TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out.startswith('--- ')
コード例 #2
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_non_existing_right_with_new_file(capsys):
    args = ['--new-file', __file__, '/nonexisting2']
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert ('--- %s' % __file__) in out
    assert '+++ /nonexisting2' in out
コード例 #3
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_text_option_with_stdiout(capsys):
    args = ['--text', '-', TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out.startswith('--- ')
コード例 #4
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_non_existing_files(capsys):
    args = '/nonexisting1 /nonexisting2'
    with pytest.raises(SystemExit) as excinfo:
        main(args.split())
    assert excinfo.value.code == 2
    out, err = capsys.readouterr()
    assert '/nonexisting1: No such file or directory' in err
    assert '/nonexisting2: No such file or directory' in err
コード例 #5
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_non_existing_files(capsys):
    args = '/nonexisting1 /nonexisting2'
    with pytest.raises(SystemExit) as excinfo:
        main(args.split())
    assert excinfo.value.code == 2
    out, err = capsys.readouterr()
    assert '/nonexisting1: No such file or directory' in err
    assert '/nonexisting2: No such file or directory' in err
コード例 #6
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_non_existing_right_with_new_file(capsys):
    args = ['--new-file', __file__, '/nonexisting2']
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert ('--- %s' % __file__) in out
    assert '+++ /nonexisting2' in out
コード例 #7
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_no_differences(capsys):
    args = [TEST_TAR1_PATH, TEST_TAR1_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 0
    out, err = capsys.readouterr()
    assert err == ''
    assert out == ''
コード例 #8
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_html_option_with_stdout(capsys):
    args = ['--html', '-', TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert 'meta name="generator" content="diffoscope"' in out
コード例 #9
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_no_differences(capsys):
    args = [TEST_TAR1_PATH, TEST_TAR1_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 0
    out, err = capsys.readouterr()
    assert err == ''
    assert out == ''
コード例 #10
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_no_report_option(capsys):
    args = [TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out.startswith('--- ')
コード例 #11
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_html_option_with_stdout(capsys):
    args = ['--html', '-', TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert 'meta name="generator" content="diffoscope"' in out
コード例 #12
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_text_option_with_stdiout(capsys):
    args = ['--text', '-', TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out.startswith('--- ')
コード例 #13
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_non_existing_files_with_new_file(capsys):
    args = ['--new-file', '/nonexisting1', '/nonexisting2']
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert '--- /nonexisting1' in out
    assert '+++ /nonexisting2' in out
    assert 'Trying to compare two non-existing files.' in out
コード例 #14
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_list_tools(capsys):
    args = ['--list-tools']
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 0
    out, err = capsys.readouterr()
    assert err == ''
    assert 'External tools required:' in out
    assert 'xxd,' in out
コード例 #15
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_list_tools(capsys):
    args = ['--list-tools']
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 0
    out, err = capsys.readouterr()
    assert err == ''
    assert 'External tools required:' in out
    assert 'xxd,' in out
コード例 #16
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_non_existing_files_with_new_file(capsys):
    args = ['--new-file', '/nonexisting1', '/nonexisting2']
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert '--- /nonexisting1' in out
    assert '+++ /nonexisting2' in out
    assert 'Trying to compare two non-existing files.' in out
コード例 #17
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_html_option_with_file(tmpdir, capsys):
    report_path = str(tmpdir.join('report.html'))
    args = ['--html', report_path, TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out == ''
    with open(report_path, 'r', encoding='utf-8') as f:
        assert 'meta name="generator" content="diffoscope"' in f.read()
コード例 #18
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_html_option_with_file(tmpdir, capsys):
    report_path = str(tmpdir.join('report.html'))
    args = ['--html', report_path, TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out == ''
    with open(report_path, 'r', encoding='utf-8') as f:
        assert 'meta name="generator" content="diffoscope"' in f.read()
コード例 #19
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_text_option_with_file(tmpdir, capsys):
    report_path = str(tmpdir.join('report.txt'))
    args = ['--text', report_path, TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out == ''
    with open(report_path, 'r', encoding='utf-8') as f:
        assert f.read().startswith('--- ')
コード例 #20
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_text_option_with_file(tmpdir, capsys):
    report_path = str(tmpdir.join('report.txt'))
    args = ['--text', report_path, TEST_TAR1_PATH, TEST_TAR2_PATH]
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    assert excinfo.value.code == 1
    out, err = capsys.readouterr()
    assert err == ''
    assert out == ''
    with open(report_path, 'r', encoding='utf-8') as f:
        assert f.read().startswith('--- ')
コード例 #21
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_ctrl_c_handling(tmpdir, monkeypatch, capsys):
    args = [TEST_TAR1_PATH, TEST_TAR2_PATH]
    monkeypatch.setattr('tempfile.tempdir', str(tmpdir))
    def interrupt(*args):
        raise KeyboardInterrupt
    monkeypatch.setattr('diffoscope.comparators.text.TextFile.compare', interrupt)
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    out, err = capsys.readouterr()
    assert '' in err
    assert excinfo.value.code == 2
    assert os.listdir(str(tmpdir)) == []
コード例 #22
0
ファイル: test_main.py プロジェクト: satyamz/diffoscope
def test_remove_temp_files_on_sigterm(tmpdir, monkeypatch):
    args = [TEST_TAR1_PATH, TEST_TAR2_PATH]
    pid = os.fork()
    if pid == 0:
        def suicide(*args):
            os.kill(os.getpid(), signal.SIGTERM)
        monkeypatch.setattr('diffoscope.comparators.text.TextFile.compare', suicide)
        tempfile.tempdir = str(tmpdir)
        with pytest.raises(SystemExit) as excinfo:
            main(args)
        os._exit(excinfo.value.code)
    else:
        _, ret = os.waitpid(pid, 0)
        assert (ret >> 8) == 2 # having received SIGTERM is trouble
        assert os.listdir(str(tmpdir)) == []
コード例 #23
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_ctrl_c_handling(tmpdir, monkeypatch, capsys):
    args = [TEST_TAR1_PATH, TEST_TAR2_PATH]
    monkeypatch.setattr('tempfile.tempdir', str(tmpdir))

    def interrupt(*args):
        raise KeyboardInterrupt

    monkeypatch.setattr('diffoscope.comparators.text.TextFile.compare',
                        interrupt)
    with pytest.raises(SystemExit) as excinfo:
        main(args)
    out, err = capsys.readouterr()
    assert '' in err
    assert excinfo.value.code == 2
    assert os.listdir(str(tmpdir)) == []
コード例 #24
0
ファイル: test_main.py プロジェクト: edolstra/diffoscope
def test_remove_temp_files_on_sigterm(tmpdir, monkeypatch):
    args = [TEST_TAR1_PATH, TEST_TAR2_PATH]
    pid = os.fork()
    if pid == 0:

        def suicide(*args):
            os.kill(os.getpid(), signal.SIGTERM)

        monkeypatch.setattr('diffoscope.comparators.text.TextFile.compare',
                            suicide)
        tempfile.tempdir = str(tmpdir)
        with pytest.raises(SystemExit) as excinfo:
            main(args)
        os._exit(excinfo.value.code)
    else:
        _, ret = os.waitpid(pid, 0)
        assert (ret >> 8) == 2  # having received SIGTERM is trouble
        assert os.listdir(str(tmpdir)) == []