[diffoscope] 02/05: tests: Actually compare the output of text/ReST/markdown formats to fixtures.

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 636ccbe036261cc4a2ad804da5d6934b8700e09c
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Jan 21 15:59:15 2017 +1100

    tests: Actually compare the output of text/ReST/markdown formats to fixtures.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 tests/data/output.md     | 38 +++++++++++++++++++++++++++++++++++
 tests/data/output.rst    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/data/output.txt    | 34 +++++++++++++++++++++++++++++++
 tests/test_presenters.py | 32 ++++++++++++++++++-----------
 4 files changed, 144 insertions(+), 12 deletions(-)

diff --git a/tests/data/output.md b/tests/data/output.md
new file mode 100644
index 0000000..a147d58
--- /dev/null
+++ b/tests/data/output.md
@@ -0,0 +1,38 @@
+# Comparing test1.tar & test2.tar
+
+## file list
+
+    @@ -1,4 +1,4 @@
+    -drwxr-xr-x   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:09.000000 dir/
+    --rw-r--r--   0 lunar     (1000) lunar     (1000)      446 2015-06-29 15:49:09.000000 dir/text
+    -crw-r--r--   0 root         (0) root         (0)    1,  3 2015-06-29 15:49:09.000000 dir/null
+    -lrwxrwxrwx   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:09.000000 dir/link -> broken
+    +drwxr-xr-x   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:41.000000 dir/
+    +-rw-r--r--   0 lunar     (1000) lunar     (1000)      671 2015-06-29 15:49:41.000000 dir/text
+    +crw-r--r--   0 root         (0) root         (0)    1,  3 2015-06-29 15:49:41.000000 dir/null
+    +lrwxrwxrwx   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:41.000000 dir/link -> really-broken
+
+## dir/text
+
+    @@ -1,6 +1,12 @@
+    +A common form of lorem ipsum reads:
+    +
+     Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+     incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
+     nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+     Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+     fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+     culpa qui officia deserunt mollit anim id est laborum.
+    +
+    +"Lorem ipsum" text is derived from sections 1.10.32--3 of Cicero's De finibus
+    +bonorum et malorum (On the Ends of Goods and Evils, or alternatively [About]
+    +The Purposes of Good and Evil).
+
+## dir/link
+
+symlink
+
+    @@ -1 +1 @@
+    -destination: broken
+    +destination: really-broken
+
diff --git a/tests/data/output.rst b/tests/data/output.rst
new file mode 100644
index 0000000..08e60e3
--- /dev/null
+++ b/tests/data/output.rst
@@ -0,0 +1,52 @@
+===============================
+Comparing test1.tar & test2.tar
+===============================
+
+---------
+file list
+---------
+
+::
+
+    @@ -1,4 +1,4 @@
+    -drwxr-xr-x   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:09.000000 dir/
+    --rw-r--r--   0 lunar     (1000) lunar     (1000)      446 2015-06-29 15:49:09.000000 dir/text
+    -crw-r--r--   0 root         (0) root         (0)    1,  3 2015-06-29 15:49:09.000000 dir/null
+    -lrwxrwxrwx   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:09.000000 dir/link -> broken
+    +drwxr-xr-x   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:41.000000 dir/
+    +-rw-r--r--   0 lunar     (1000) lunar     (1000)      671 2015-06-29 15:49:41.000000 dir/text
+    +crw-r--r--   0 root         (0) root         (0)    1,  3 2015-06-29 15:49:41.000000 dir/null
+    +lrwxrwxrwx   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:41.000000 dir/link -> really-broken
+
+--------
+dir/text
+--------
+
+::
+
+    @@ -1,6 +1,12 @@
+    +A common form of lorem ipsum reads:
+    +
+     Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+     incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
+     nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+     Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+     fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+     culpa qui officia deserunt mollit anim id est laborum.
+    +
+    +"Lorem ipsum" text is derived from sections 1.10.32--3 of Cicero's De finibus
+    +bonorum et malorum (On the Ends of Goods and Evils, or alternatively [About]
+    +The Purposes of Good and Evil).
+
+--------
+dir/link
+--------
+
+
+symlink
+::
+
+    @@ -1 +1 @@
+    -destination: broken
+    +destination: really-broken
+
diff --git a/tests/data/output.txt b/tests/data/output.txt
new file mode 100644
index 0000000..b515c2c
--- /dev/null
+++ b/tests/data/output.txt
@@ -0,0 +1,34 @@
+--- test1.tar
++++ test2.tar
+├── file list
+│ @@ -1,4 +1,4 @@
+│ -drwxr-xr-x   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:09.000000 dir/
+│ --rw-r--r--   0 lunar     (1000) lunar     (1000)      446 2015-06-29 15:49:09.000000 dir/text
+│ -crw-r--r--   0 root         (0) root         (0)    1,  3 2015-06-29 15:49:09.000000 dir/null
+│ -lrwxrwxrwx   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:09.000000 dir/link -> broken
+│ +drwxr-xr-x   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:41.000000 dir/
+│ +-rw-r--r--   0 lunar     (1000) lunar     (1000)      671 2015-06-29 15:49:41.000000 dir/text
+│ +crw-r--r--   0 root         (0) root         (0)    1,  3 2015-06-29 15:49:41.000000 dir/null
+│ +lrwxrwxrwx   0 lunar     (1000) lunar     (1000)        0 2015-06-29 15:49:41.000000 dir/link -> really-broken
+│ 
+├── dir/text
+│ @@ -1,6 +1,12 @@
+│ +A common form of lorem ipsum reads:
+│ +
+│  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+│  incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
+│  nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+│  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+│  fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+│  culpa qui officia deserunt mollit anim id est laborum.
+│ +
+│ +"Lorem ipsum" text is derived from sections 1.10.32--3 of Cicero's De finibus
+│ +bonorum et malorum (On the Ends of Goods and Evils, or alternatively [About]
+│ +The Purposes of Good and Evil).
+│ 
+├── dir/link
+│┄ symlink
+│ @@ -1 +1 @@
+│ -destination: broken
+│ +destination: really-broken
+│ 
diff --git a/tests/test_presenters.py b/tests/test_presenters.py
index a601ed8..8d30756 100644
--- a/tests/test_presenters.py
+++ b/tests/test_presenters.py
@@ -22,14 +22,18 @@ import pytest
 
 from diffoscope.main import main
 
-def run(capsys, *args):
-    args = list(args) + [
-        os.path.join(os.path.dirname(__file__), 'data', x)
-        for x in ('test1.tar', 'test2.tar')
-    ]
+DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
+
 
+def run(capsys, *args):
     with pytest.raises(SystemExit) as exc:
-        main(args)
+        prev = os.getcwd()
+        os.chdir(DATA_DIR)
+
+        try:
+            main(args + ('test1.tar', 'test2.tar'))
+        finally:
+            os.chdir(prev)
 
     out, err = capsys.readouterr()
 
@@ -38,35 +42,39 @@ def run(capsys, *args):
 
     return out
 
+def data(filename):
+    with open(os.path.join(DATA_DIR, filename)) as f:
+        return f.read()
+
 def test_text_option_with_file(tmpdir, capsys):
     report_path = str(tmpdir.join('report.txt'))
 
     out = run(capsys, '--text', report_path)
 
     assert out == ''
+
     with open(report_path, 'r', encoding='utf-8') as f:
-        assert f.read().startswith('--- ')
+        assert f.read() == data('output.txt')
 
 def test_text_option_with_stdiout(capsys):
     out = run(capsys, '--text', '-')
 
-    assert out.startswith('--- ')
+    assert out == data('output.txt')
 
 def test_markdown(capsys):
     out = run(capsys, '--markdown', '-')
 
-    assert out.startswith('# Comparing')
+    assert out == data('output.md')
 
 def test_restructuredtext(capsys):
     out = run(capsys, '--restructured-text', '-')
 
-    assert out.startswith('=====')
-    assert "Comparing" in out
+    assert out == data('output.rst')
 
 def test_no_report_option(capsys):
     out = run(capsys)
 
-    assert out.startswith('--- ')
+    assert out == data('output.txt')
 
 def test_html_option_with_file(tmpdir, capsys):
     report_path = str(tmpdir.join('report.html'))

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


More information about the diffoscope mailing list