Skip to content

Commit

Permalink
Add some example HTML for unit tests and test htmltreediff.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Oct 12, 2017
1 parent 81cd46f commit 1ace639
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,3 +1,4 @@
include versioneer.py
include web_monitoring/_version.py
include web_monitoring/tests/cassettes/*
include web_monitoring/example_data/*
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -2,6 +2,7 @@ beautifulsoup4
python-dateutil
diff_match_patch_python
docopt
git+https://github.com/danielballan/htmltreediff@py3-compat
lxml
pandas
requests
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -22,6 +22,7 @@ def read(fname):
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
packages=['web_monitoring'],
package_data={'web_monitoring': ['example_data/*']},
scripts=glob.glob('scripts/*'),
install_requires=read('requirements.txt').splitlines(),
package_data={'web_monitoring': ['web_monitoring/tests/cassettes/*']},
Expand Down
8 changes: 8 additions & 0 deletions web_monitoring/example_data/add-paragraph.after
@@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>
<p>One</p>
<p>Two</p>
</body>
<html>
7 changes: 7 additions & 0 deletions web_monitoring/example_data/add-paragraph.before
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<p>One</p>
</body>
<html>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-href.after
@@ -0,0 +1 @@
<a href="/elsewhere">Link Text</a>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-href.before
@@ -0,0 +1 @@
<a href="/somewhere">Link Text</a>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-link-text.after
@@ -0,0 +1 @@
<a href="/somewhere">After</a>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-link-text.before
@@ -0,0 +1 @@
<a href="/somewhere">Before</a>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-tag.after
@@ -0,0 +1 @@
<h2>whatever</h2>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-tag.before
@@ -0,0 +1 @@
<h1>whatever</h1>
1 change: 1 addition & 0 deletions web_monitoring/example_data/change-word-in-paragraph.after
@@ -0,0 +1 @@
<p>Beware the Jabberwock my son, the jaws that byte, the claws that catch.</p>
@@ -0,0 +1 @@
<p>Beware the Jabberwock my son, the jaws that bite, the claws that catch.</p>
1 change: 1 addition & 0 deletions web_monitoring/example_data/ins-in-source.after
@@ -0,0 +1 @@
<ins>after</ins>
1 change: 1 addition & 0 deletions web_monitoring/example_data/ins-in-source.before
@@ -0,0 +1 @@
<ins>before</ins>
8 changes: 8 additions & 0 deletions web_monitoring/example_data/two-paragraphs.after
@@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>
<p>After 1</p>
<p>After 2</p>
</body>
<html>
8 changes: 8 additions & 0 deletions web_monitoring/example_data/two-paragraphs.before
@@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>
<p>Before 1</p>
<p>Before 2</p>
</body>
<html>
39 changes: 39 additions & 0 deletions web_monitoring/tests/test_html_diff.py
@@ -0,0 +1,39 @@
from pkg_resources import resource_filename
import pytest
import htmltreediff


def lookup_pair(fn):
"""Read example data named {fn}.before and {fn}.after"""
fn1 = 'example_data/{}.before'.format(fn)
fn2 = 'example_data/{}.after'.format(fn)
with open(resource_filename('web_monitoring', fn1)) as f:
before = f.read()
with open(resource_filename('web_monitoring', fn2)) as f:
after = f.read()
return before, after


@pytest.mark.parametrize('fn',
['change-tag',
'change-href',
'change-link-text',
'ins-in-source',
'two-paragraphs',
'add-paragraph',
'change-word-in-paragraph',
])
def test_change(fn):
# For now it's unclear what the 'expected' result should be, so this
# test will never FAIL (but it can still ERROR). Run pytest with the -s
# flag to see these outputs.
before, after = lookup_pair(fn)
d = htmltreediff.diff(before, after)
print("""
BEFORE:
{}
AFTER:
{}
DIFF:
{}
""".format(before, after, d))

0 comments on commit 1ace639

Please sign in to comment.