Skip to content

Commit 25fe830

Browse files
committed
TST fix test loading
glob was not working when tests are run in tox, because current path was not the same
1 parent b8e5f55 commit 25fe830

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

tests/test_html_text.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# -*- coding: utf-8 -*-
22
import pytest
33
import glob
4+
import os
45

56
from html_text import (extract_text, parse_html, cleaned_selector,
67
selector_to_text, NEWLINE_TAGS, DOUBLE_NEWLINE_TAGS)
78

89

10+
ROOT = os.path.dirname(os.path.abspath(__file__))
11+
12+
913
@pytest.fixture(params=[
1014
{'guess_punct_space': True, 'guess_layout': False},
1115
{'guess_punct_space': False, 'guess_layout': False},
@@ -149,12 +153,16 @@ def test_personalize_newlines_sets():
149153
assert text == 'text\n\nmore\n\nand more text\n\nand some more'
150154

151155

152-
def test_webpages():
153-
webpages = sorted(glob.glob('./test_webpages/*.html'))
154-
extracted = sorted(glob.glob('./test_webpages/*.txt'))
155-
for page, extr in zip(webpages, extracted):
156-
with open(page, 'r', encoding='utf8') as f_in:
157-
html = f_in.read()
158-
with open(extr, 'r', encoding='utf8') as f_in:
159-
expected = f_in.read()
160-
assert extract_text(html) == expected
156+
def _load_examples():
157+
webpages = sorted(glob.glob(os.path.join(ROOT, 'test_webpages', '*.html')))
158+
extracted = sorted(glob.glob(os.path.join(ROOT, 'test_webpages','*.txt')))
159+
return list(zip(webpages, extracted))
160+
161+
162+
@pytest.mark.parametrize(['page', 'extracted'], _load_examples())
163+
def test_foo(page, extracted):
164+
with open(page, 'r', encoding='utf8') as f_in:
165+
html = f_in.read()
166+
with open(extracted, 'r', encoding='utf8') as f_in:
167+
expected = f_in.read()
168+
assert extract_text(html) == expected

0 commit comments

Comments
 (0)