[diffoscope] 01/05: tests: Avoid DRY violations in presenter tests.

Chris Lamb chris at chris-lamb.co.uk
Sat Jan 21 12:16:21 CET 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 58c95cd002999637a67735a96181a6ac49c72da5
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Jan 21 15:45:23 2017 +1100

    tests: Avoid DRY violations in presenter tests.
    
    Gbp-Dch: Ignore
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 tests/test_presenters.py | 53 ++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/tests/test_presenters.py b/tests/test_presenters.py
index 3d50cfb..a601ed8 100644
--- a/tests/test_presenters.py
+++ b/tests/test_presenters.py
@@ -22,65 +22,57 @@ import pytest
 
 from diffoscope.main import main
 
-TEST_TAR1_PATH = os.path.join(os.path.dirname(__file__), 'data/test1.tar')
-TEST_TAR2_PATH = os.path.join(os.path.dirname(__file__), 'data/test2.tar')
-
-
 def run(capsys, *args):
+    args = list(args) + [
+        os.path.join(os.path.dirname(__file__), 'data', x)
+        for x in ('test1.tar', 'test2.tar')
+    ]
+
     with pytest.raises(SystemExit) as exc:
-        main(args + (TEST_TAR1_PATH, TEST_TAR2_PATH))
+        main(args)
 
     out, err = capsys.readouterr()
 
-    return exc.value.code, out, err
+    assert err == ''
+    assert exc.value.code == 1
+
+    return out
 
 def test_text_option_with_file(tmpdir, capsys):
     report_path = str(tmpdir.join('report.txt'))
 
-    ret, out, err = run(capsys, '--text', report_path)
+    out = run(capsys, '--text', report_path)
 
-    assert ret == 1
-    assert err == ''
     assert out == ''
     with open(report_path, 'r', encoding='utf-8') as f:
         assert f.read().startswith('--- ')
 
 def test_text_option_with_stdiout(capsys):
-    ret, out, err = run(capsys, '--text', '-')
+    out = run(capsys, '--text', '-')
 
-    assert ret == 1
-    assert err == ''
     assert out.startswith('--- ')
 
 def test_markdown(capsys):
-    ret, out, err = run(capsys, '--markdown', '-')
+    out = run(capsys, '--markdown', '-')
 
-    assert ret == 1
-    assert err == ''
     assert out.startswith('# Comparing')
 
 def test_restructuredtext(capsys):
-    ret, out, err = run(capsys, '--restructured-text', '-')
+    out = run(capsys, '--restructured-text', '-')
 
-    assert ret == 1
-    assert err == ''
     assert out.startswith('=====')
     assert "Comparing" in out
 
 def test_no_report_option(capsys):
-    ret, out, err = run(capsys)
+    out = run(capsys)
 
-    assert ret == 1
-    assert err == ''
     assert out.startswith('--- ')
 
 def test_html_option_with_file(tmpdir, capsys):
     report_path = str(tmpdir.join('report.html'))
 
-    ret, out, err = run(capsys, '--html', report_path)
+    out = run(capsys, '--html', report_path)
 
-    assert ret == 1
-    assert err == ''
     assert out == ''
     with open(report_path, 'r', encoding='utf-8') as f:
         assert 'meta name="generator" content="diffoscope"' in f.read()
@@ -88,23 +80,14 @@ def test_html_option_with_file(tmpdir, capsys):
 def test_htmldir_option(tmpdir, capsys):
     html_dir = os.path.join(str(tmpdir), 'target')
 
-    ret, out, err = run(
-        capsys,
-        '--html-dir', html_dir,
-        '--jquery', 'disable',
-    )
+    out = run(capsys, '--html-dir', html_dir, '--jquery', 'disable')
 
-    assert ret == 1
-    assert err == ''
     assert out == ''
     assert os.path.isdir(html_dir)
-
     with open(os.path.join(html_dir, 'index.html'), 'r', encoding='utf-8') as f:
         assert 'meta name="generator" content="diffoscope"' in f.read()
 
 def test_html_option_with_stdout(capsys):
-    ret, out, err = run(capsys, '--html', '-')
+    out = run(capsys, '--html', '-')
 
-    assert ret == 1
-    assert err == ''
     assert 'meta name="generator" content="diffoscope"' in out

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list