# Path: chemdataextractor/scrape/clean.py
# class Cleaner(object):
#     def __init__(self, **kwargs):
#     def __call__(self, doc):
#     def clean_html(self, html):
#     def clean_markup(self, markup, parser=None):


import logging
import unittest
from lxml.etree import tostring
from lxml import html
from chemdataextractor.scrape.clean import Cleaner, clean, strip, strip_markup, strip_html
# Results from stripping HTML and leaving whitespace to match input
STRIPWS1 = '<html>\n  \n    \n    Heading\n    Link\n    Nested\n  \n</html>'
STRIPWS2 = '<html>titleStart bodyThis iss a test.Test link</html>'
STRIPWS3 = '<div>FirstSecondThirdFourthFifthSixth</div>'
STRIPWS4 = '<p>Here is a text para with some inline markup, like this. Also a link</p>'

# Results of cleaning HTML
CLEAN1 = '<html>\n<body>\n<div>\n<h1>Heading</h1>\n</div>\n<div><a href="page">Link</a></div>\n<div>\n<div>Nested</div>\n</div>\n</body>\n</html>'
CLEAN2 = '<html>\n<head>\n<title>title</title>\n</head>\n<body>Start body\n<p>This i<span>s</span>s a <strong>test</strong>.Test <a href="link">link</a></p>\n</body>\n</html>'
CLEAN3 = '<div>\n<p>First</p>\n<p>Second</p>\n<p>Third</p>\n<p>Fourth</p>\n<p>Fifth</p>\n<p>Sixth</p>\n</div>'
CLEAN4 = '<p>Here is a text para with some <em>inline</em> markup, like <strong>this</strong>. Also a <a href="#thing">link</a></p>'

# Results of stripping HTML and killing strong tags
STRIPKS1 = '<html>\nHeading\nLink\nNested\n</html>'
STRIPKS2 = '<html>\ntitle\nStart body\nThis iss a .Test link\n</html>'
STRIPKS3 = '<div>\nFirst\nSecond\nThird\nFourth\nFifth\nSixth\n</div>'
STRIPKS4 = '<p>Here is a text para with some inline markup, like . Also a link</p>'


class TestCleaner(unittest.TestCase):

    def test_strip1(self):
        """Test applying the default strip to HTML document."""
        tree = html.fromstring(HTML1)
        strip(tree)
        self.assertEqual(STRIP1, tostring(tree).decode())

    def test_strip2(self):
        """Test applying the default strip to HTML document."""
        tree = html.fromstring(HTML2)

# Path: chemdataextractor/scrape/clean.py
# class Cleaner(object):
#     def __init__(self, **kwargs):
#     def __call__(self, doc):
#     def clean_html(self, html):
#     def clean_markup(self, markup, parser=None):


# Path: tests/test_scrape_clean.py
import logging
import unittest
from lxml.etree import tostring
from lxml import html
from chemdataextractor.scrape.clean import Cleaner, clean, strip, strip_markup, strip_html

# Results from stripping HTML and leaving whitespace to match input
STRIPWS1 = '<html>\n  \n    \n    Heading\n    Link\n    Nested\n  \n</html>'
STRIPWS2 = '<html>titleStart bodyThis iss a test.Test link</html>'
STRIPWS3 = '<div>FirstSecondThirdFourthFifthSixth</div>'
STRIPWS4 = '<p>Here is a text para with some inline markup, like this. Also a link</p>'

# Results of cleaning HTML
CLEAN1 = '<html>\n<body>\n<div>\n<h1>Heading</h1>\n</div>\n<div><a href="page">Link</a></div>\n<div>\n<div>Nested</div>\n</div>\n</body>\n</html>'
CLEAN2 = '<html>\n<head>\n<title>title</title>\n</head>\n<body>Start body\n<p>This i<span>s</span>s a <strong>test</strong>.Test <a href="link">link</a></p>\n</body>\n</html>'
CLEAN3 = '<div>\n<p>First</p>\n<p>Second</p>\n<p>Third</p>\n<p>Fourth</p>\n<p>Fifth</p>\n<p>Sixth</p>\n</div>'
CLEAN4 = '<p>Here is a text para with some <em>inline</em> markup, like <strong>this</strong>. Also a <a href="#thing">link</a></p>'

# Results of stripping HTML and killing strong tags
STRIPKS1 = '<html>\nHeading\nLink\nNested\n</html>'
STRIPKS2 = '<html>\ntitle\nStart body\nThis iss a .Test link\n</html>'
STRIPKS3 = '<div>\nFirst\nSecond\nThird\nFourth\nFifth\nSixth\n</div>'
STRIPKS4 = '<p>Here is a text para with some inline markup, like . Also a link</p>'


class TestCleaner(unittest.TestCase):

    def test_strip1(self):
        """Test applying the default strip to HTML document."""
        tree = html.fromstring(HTML1)
        strip(tree)
        self.assertEqual(STRIP1, tostring(tree).decode())

    def test_strip2(self):
        """Test applying the default strip to HTML document."""
        tree = html.fromstring(HTML2)

        strip(tree)