Added compatibility file with unittest2 import

pull/21/head
Mišo Belica 11 years ago
parent 26fe24789c
commit 0178cfff5c

@ -35,43 +35,42 @@ TEST_PATH = join(
"test_articles"
)
TEST_TEMPLATE = """
import os
TEST_TEMPLATE = '''# -*- coding: utf8 -*-
try:
# Python < 2.7
import unittest2 as unittest
except ImportError:
import unittest
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
import os
from readability.readable import Article
from ...compat import unittest
class TestArticle(unittest.TestCase):
'''Test the scoring and parsing of the Article'''
"""Test the scoring and parsing of the Article"""
def setUp(self):
'''Load up the article for us'''
article_path = os.path.join(os.path.dirname(__file__), 'article.html')
"""Load up the article for us"""
article_path = os.path.join(os.path.dirname(__file__), "article.html")
self.article = open(article_path).read()
def tearDown(self):
'''Drop the article'''
"""Drop the article"""
self.article = None
def test_parses(self):
'''Verify we can parse the document.'''
"""Verify we can parse the document."""
doc = Article(self.article)
self.assertTrue('id="readabilityBody"' in doc.readable)
def test_content_exists(self):
'''Verify that some content exists.'''
"""Verify that some content exists."""
raise NotImplementedError()
def test_content_does_not_exist(self):
'''Verify we cleaned out some content that shouldn't exist.'''
"""Verify we cleaned out some content that shouldn't exist."""
raise NotImplementedError()
"""
'''
def parse_args():
@ -99,7 +98,7 @@ def make_test_files(directory_path):
def fetch_article(directory_path, url):
"""Get the content of the url and make it the article.html"""
opener = urllib.build_opener()
opener.addheaders = [('Accept-Charset', 'utf-8')]
opener.addheaders = [("Accept-Charset", "utf-8")]
response = opener.open(url)
html = response.read().decode("utf-8")
@ -119,5 +118,5 @@ def main():
fetch_article(directory, args["<url>"])
if __name__ == '__main__':
if __name__ == "__main__":
main()

@ -0,0 +1,9 @@
# -*- coding: utf8 -*-
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
try:
import unittest2 as unittest
except ImportError:
import unittest

@ -1,11 +1,12 @@
# -*- coding: utf8 -*-
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
import os
try:
# Python < 2.7
import unittest2 as unittest
except ImportError:
import unittest
from readability.readable import Article
from ...compat import unittest
class TestAntipopeBlog(unittest.TestCase):

@ -1,15 +1,15 @@
import os
from operator import attrgetter
try:
# Python < 2.7
import unittest2 as unittest
except ImportError:
import unittest
# -*- coding: utf8 -*-
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
import os
from operator import attrgetter
from readability.readable import Article
from readability.readable import check_siblings
from readability.readable import prep_article
from ...compat import unittest
class TestArticle(unittest.TestCase):

@ -1,16 +1,12 @@
# -*- coding: utf8 -*-
from __future__ import absolute_import
try:
# Python < 2.7
import unittest2 as unittest
except ImportError:
import unittest
from __future__ import division, print_function, unicode_literals
from collections import defaultdict
from readability._py3k import to_unicode, to_bytes
from readability.document import OriginalDocument, determine_encoding
from .compat import unittest
from .utils import load_snippet

@ -1,15 +1,11 @@
# -*- coding: utf8 -*-
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
from lxml.etree import tounicode
from lxml.html import document_fromstring
from lxml.html import fragment_fromstring
try:
# Python < 2.7
import unittest2 as unittest
except ImportError:
import unittest
from readability._py3k import to_unicode
from readability.readable import Article
from readability.readable import get_class_weight
@ -18,6 +14,7 @@ from readability.readable import is_bad_link
from readability.readable import score_candidates
from readability.readable import leaf_div_elements_into_paragraphs
from readability.scoring import ScoredNode
from .compat import unittest
from .utils import load_snippet, load_article

@ -1,18 +1,13 @@
# -*- coding: utf8 -*-
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
import re
from operator import attrgetter
from lxml.html import document_fromstring
from lxml.html import fragment_fromstring
from operator import attrgetter
try:
# Python < 2.7
import unittest2 as unittest
except ImportError:
import unittest
from readability._py3k import to_unicode
from readability.readable import Article
from readability.scoring import check_node_attributes
@ -22,6 +17,7 @@ from readability.scoring import score_candidates
from readability.scoring import generate_hash_id
from readability.readable import get_link_density
from readability.readable import is_unlikely_node
from .compat import unittest
from .utils import load_snippet

Loading…
Cancel
Save