[Reproducible-commits] [debbindiff] 01/01: Begin writing a test suite
Jérémy Bobbio
lunar at moszumanska.debian.org
Tue Jun 23 10:12:40 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit 2e8ee43b70087400d967c90d068188d58948fe7d
Author: Jérémy Bobbio <lunar at debian.org>
Date: Tue Jun 23 10:10:20 2015 +0000
Begin writing a test suite
We are using PyTest: http://pytest.org/
For a start, the text comparator now has 100% code coverage.
---
.gitignore | 2 ++
debian/README.source | 14 ++++++++
debian/control | 1 +
setup.py | 21 +++++++++++
tests/comparators/test_text.py | 62 +++++++++++++++++++++++++++++++++
tests/data/.coverage | 1 +
tests/data/text_ascii1 | 6 ++++
tests/data/text_ascii2 | 12 +++++++
tests/data/text_ascii_expected_diff | 13 +++++++
tests/data/text_iso8859 | 12 +++++++
tests/data/text_iso8859_expected_diff | 14 ++++++++
tests/data/text_unicode1 | 12 +++++++
tests/data/text_unicode2 | 12 +++++++
tests/data/text_unicode_binary_fallback | 33 ++++++++++++++++++
tests/data/text_unicode_expected_diff | 12 +++++++
15 files changed, 227 insertions(+)
diff --git a/.gitignore b/.gitignore
index 0bdc09b..ef67893 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
*.pyc
/debbindiff.egg-info/
/dist/
+/.coverage
+/htmlcov/
diff --git a/debian/README.source b/debian/README.source
new file mode 100644
index 0000000..27d263e
--- /dev/null
+++ b/debian/README.source
@@ -0,0 +1,14 @@
+debbindiff: hacking tips
+========================
+
+Running the test suite
+----------------------
+
+Tests are meant to be run with PyTest. The easiest way is simple to run
+the tests are then:
+
+ $ py.test
+
+To get code coverage:
+
+ $ py.test --cov debbindiff --cov-report html
diff --git a/debian/control b/debian/control
index b1e0752..4109b95 100644
--- a/debian/control
+++ b/debian/control
@@ -8,6 +8,7 @@ Build-Depends: debhelper (>= 9),
python-debian,
python-docutils,
python-magic,
+ python-pytest,
python-rpm,
python-setuptools,
rpm-common
diff --git a/setup.py b/setup.py
index 59f2faa..e62d0c2 100644
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,27 @@
#!/usr/bin/env python2
from setuptools import setup, find_packages
+from setuptools.command.test import test as TestCommand
import debbindiff
+class PyTest(TestCommand):
+ user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
+
+ def initialize_options(self):
+ TestCommand.initialize_options(self)
+ self.pytest_args = []
+
+ def finalize_options(self):
+ TestCommand.finalize_options(self)
+ self.test_args = []
+ self.test_suite = True
+
+ def run_tests(self):
+ #import here, cause outside the eggs aren't loaded
+ import pytest
+ errno = pytest.main(self.pytest_args)
+ sys.exit(errno)
+
setup(name='debbindiff',
version=debbindiff.VERSION,
description='display differences between files',
@@ -11,6 +30,8 @@ setup(name='debbindiff',
author_email='lunar at debian.org',
url='https://wiki.debian.org/ReproducibleBuilds',
packages=find_packages(),
+ tests_require=['pytest'],
+ cmdclass = {'test', PyTest},
scripts=['debbindiff.py'],
install_requires=[
'python-debian',
diff --git a/tests/comparators/test_text.py b/tests/comparators/test_text.py
new file mode 100644
index 0000000..ef8059a
--- /dev/null
+++ b/tests/comparators/test_text.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+#
+# debbindiff is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# debbindiff is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
+
+import codecs
+import os.path
+import pytest
+from debbindiff.comparators.text import compare_text_files
+
+def test_no_differences():
+ text1 = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
+ text2 = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
+ differences = compare_text_files(text1, text2)
+ assert len(differences) == 0
+
+def test_difference_in_ascii():
+ text1 = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
+ text2 = os.path.join(os.path.dirname(__file__), '../data/text_ascii2')
+ differences = compare_text_files(text1, text2)
+ assert len(differences) == 1
+ expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ assert differences[0].unified_diff == expected_diff
+ assert differences[0].comment is None
+ assert len(differences[0].details) == 0
+
+def test_difference_in_unicode():
+ text1 = os.path.join(os.path.dirname(__file__), '../data/text_unicode1')
+ text2 = os.path.join(os.path.dirname(__file__), '../data/text_unicode2')
+ differences = compare_text_files(text1, text2)
+ expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_unicode_expected_diff'), encoding='utf-8').read()
+ assert differences[0].unified_diff == expected_diff
+
+def test_fallback_to_binary():
+ text1 = os.path.join(os.path.dirname(__file__), '../data/text_unicode1')
+ text2 = os.path.join(os.path.dirname(__file__), '../data/text_unicode2')
+ differences = compare_text_files(text1, text2, encoding='ascii')
+ expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_unicode_binary_fallback')).read()
+ assert differences[0].unified_diff == expected_diff
+
+ at pytest.mark.xfail
+def test_difference_between_iso88591_and_unicode():
+ text1 = os.path.join(os.path.dirname(__file__), '../data/text_unicode1')
+ text2 = os.path.join(os.path.dirname(__file__), '../data/text_iso8859')
+ differences = compare_text_files(text1, text2)
+ expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859_expected_diff'), encoding='utf-8').read()
+ assert differences[0].unified_diff == expected_diff
diff --git a/tests/data/.coverage b/tests/data/.coverage
new file mode 100644
index 0000000..7549fcc
--- /dev/null
+++ b/tests/data/.coverage
@@ -0,0 +1 @@
+�}q(U collectorqUcoverage v3.7.1qUlinesq}u.
\ No newline at end of file
diff --git a/tests/data/text_ascii1 b/tests/data/text_ascii1
new file mode 100644
index 0000000..7b95d6b
--- /dev/null
+++ b/tests/data/text_ascii1
@@ -0,0 +1,6 @@
+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.
diff --git a/tests/data/text_ascii2 b/tests/data/text_ascii2
new file mode 100644
index 0000000..32c36c3
--- /dev/null
+++ b/tests/data/text_ascii2
@@ -0,0 +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).
diff --git a/tests/data/text_ascii_expected_diff b/tests/data/text_ascii_expected_diff
new file mode 100644
index 0000000..f20be12
--- /dev/null
+++ b/tests/data/text_ascii_expected_diff
@@ -0,0 +1,13 @@
+@@ -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).
diff --git a/tests/data/text_iso8859 b/tests/data/text_iso8859
new file mode 100644
index 0000000..d5f3c5e
--- /dev/null
+++ b/tests/data/text_iso8859
@@ -0,0 +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).
diff --git a/tests/data/text_iso8859_expected_diff b/tests/data/text_iso8859_expected_diff
new file mode 100644
index 0000000..a1e5f8a
--- /dev/null
+++ b/tests/data/text_iso8859_expected_diff
@@ -0,0 +1,14 @@
+--- /dev/fd/63 2015-06-23 10:04:13.051750060 +0000
++++ tests/data/text_unicode1 2015-06-23 09:46:16.425827486 +0000
+@@ -3,10 +3,10 @@
+ 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
++"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).
diff --git a/tests/data/text_unicode1 b/tests/data/text_unicode1
new file mode 100644
index 0000000..6efcbf3
--- /dev/null
+++ b/tests/data/text_unicode1
@@ -0,0 +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).
diff --git a/tests/data/text_unicode2 b/tests/data/text_unicode2
new file mode 100644
index 0000000..9c7526d
--- /dev/null
+++ b/tests/data/text_unicode2
@@ -0,0 +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).
diff --git a/tests/data/text_unicode_binary_fallback b/tests/data/text_unicode_binary_fallback
new file mode 100644
index 0000000..39afa9d
--- /dev/null
+++ b/tests/data/text_unicode_binary_fallback
@@ -0,0 +1,33 @@
+@@ -24,19 +24,20 @@
+ 00000170: 7572 2e20 4578 6365 7074 6575 7220 7369 ur. Excepteur si
+ 00000180: 6e74 206f 6363 6165 6361 7420 6375 7069 nt occaecat cupi
+ 00000190: 6461 7461 7420 6e6f 6e20 7072 6f69 6465 datat non proide
+ 000001a0: 6e74 2c20 7375 6e74 2069 6e0a 6375 6c70 nt, sunt in.culp
+ 000001b0: 6120 7175 6920 6f66 6669 6369 6120 6465 a qui officia de
+ 000001c0: 7365 7275 6e74 206d 6f6c 6c69 7420 616e serunt mollit an
+ 000001d0: 696d 2069 6420 6573 7420 6c61 626f 7275 im id est laboru
+-000001e0: 6d2e 0a0a 224c 6f72 656d 2069 7073 756d m..."Lorem ipsum
+-000001f0: 2220 7465 7874 2069 7320 6465 7269 7665 " text is derive
+-00000200: 6420 6672 6f6d 2073 6563 7469 6f6e 7320 d from sections
+-00000210: 312e 3130 2e33 32e2 8093 3320 6f66 2043 1.10.32...3 of C
+-00000220: 6963 6572 6f27 7320 4465 2066 696e 6962 icero's De finib
+-00000230: 7573 0a62 6f6e 6f72 756d 2065 7420 6d61 us.bonorum et ma
+-00000240: 6c6f 7275 6d20 284f 6e20 7468 6520 456e lorum (On the En
+-00000250: 6473 206f 6620 476f 6f64 7320 616e 6420 ds of Goods and
+-00000260: 4576 696c 732c 206f 7220 616c 7465 726e Evils, or altern
+-00000270: 6174 6976 656c 7920 5b41 626f 7574 5d0a atively [About].
+-00000280: 5468 6520 5075 7270 6f73 6573 206f 6620 The Purposes of
+-00000290: 476f 6f64 2061 6e64 2045 7669 6c29 2e0a Good and Evil)..
++000001e0: 6d2e 0a0a e280 9c4c 6f72 656d 2069 7073 m......Lorem ips
++000001f0: 756d e280 9d20 7465 7874 2069 7320 6465 um... text is de
++00000200: 7269 7665 6420 6672 6f6d 2073 6563 7469 rived from secti
++00000210: 6f6e 7320 312e 3130 2e33 32e2 8093 3320 ons 1.10.32...3
++00000220: 6f66 2043 6963 6572 6fe2 8099 7320 4465 of Cicero...s De
++00000230: 2066 696e 6962 7573 0a62 6f6e 6f72 756d finibus.bonorum
++00000240: 2065 7420 6d61 6c6f 7275 6d20 284f 6e20 et malorum (On
++00000250: 7468 6520 456e 6473 206f 6620 476f 6f64 the Ends of Good
++00000260: 7320 616e 6420 4576 696c 732c 206f 7220 s and Evils, or
++00000270: 616c 7465 726e 6174 6976 656c 7920 5b41 alternatively [A
++00000280: 626f 7574 5d0a 5468 6520 5075 7270 6f73 bout].The Purpos
++00000290: 6573 206f 6620 476f 6f64 2061 6e64 2045 es of Good and E
++000002a0: 7669 6c29 2e0a vil)..
diff --git a/tests/data/text_unicode_expected_diff b/tests/data/text_unicode_expected_diff
new file mode 100644
index 0000000..ab2be5c
--- /dev/null
+++ b/tests/data/text_unicode_expected_diff
@@ -0,0 +1,12 @@
+@@ -3,10 +3,10 @@
+ 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
++“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).
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list