Commit 2e8ee43b authored by Jérémy Bobbio's avatar Jérémy Bobbio

Begin writing a test suite

We are using PyTest: http://pytest.org/

For a start, the text comparator now has 100% code coverage.
parent 5aa9b857
......@@ -2,3 +2,5 @@
*.pyc
/debbindiff.egg-info/
/dist/
/.coverage
/htmlcov/
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
......@@ -8,6 +8,7 @@ Build-Depends: debhelper (>= 9),
python-debian,
python-docutils,
python-magic,
python-pytest,
python-rpm,
python-setuptools,
rpm-common
......
#!/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@debian.org',
url='https://wiki.debian.org/ReproducibleBuilds',
packages=find_packages(),
tests_require=['pytest'],
cmdclass = {'test', PyTest},
scripts=['debbindiff.py'],
install_requires=[
'python-debian',
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# debbindiff: highlight differences between two builds of Debian packages
#
# Copyright © 2015 Jérémy Bobbio <lunar@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
@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
}q(U collectorqUcoverage v3.7.1qUlinesq}u.
\ No newline at end of file
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.
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).
@@ -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).
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).
--- /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).
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).
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).
@@ -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)..
@@ -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).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment