Skip to content

TST/CI/BUG: fix borked call to read_html testing code #5151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions pandas/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ def test_bs4_version_fails():


class TestReadHtml(unittest.TestCase):
@classmethod
def setUpClass(cls):
_skip_if_none_of(('bs4', 'html5lib'))

def read_html(self, *args, **kwargs):
kwargs['flavor'] = kwargs.get('flavor', self.flavor)
return read_html(*args, **kwargs)

def try_skip(self):
_skip_if_none_of(('bs4', 'html5lib'))

def setup_data(self):
self.spam_data = os.path.join(DATA_PATH, 'spam.html')
self.banklist_data = os.path.join(DATA_PATH, 'banklist.html')
Expand All @@ -101,7 +102,6 @@ def setup_flavor(self):
self.flavor = 'bs4'

def setUp(self):
self.try_skip()
self.setup_data()
self.setup_flavor()

Expand Down Expand Up @@ -569,32 +569,29 @@ def test_different_number_of_rows(self):
def test_parse_dates_list(self):
df = DataFrame({'date': date_range('1/1/2001', periods=10)})
expected = df.to_html()
res = read_html(expected, parse_dates=[0], index_col=0)
res = self.read_html(expected, parse_dates=[0], index_col=0)
tm.assert_frame_equal(df, res[0])

def test_parse_dates_combine(self):
raw_dates = Series(date_range('1/1/2001', periods=10))
df = DataFrame({'date': raw_dates.map(lambda x: str(x.date())),
'time': raw_dates.map(lambda x: str(x.time()))})
res = read_html(df.to_html(), parse_dates={'datetime': [1, 2]},
index_col=1)
res = self.read_html(df.to_html(), parse_dates={'datetime': [1, 2]},
index_col=1)
newdf = DataFrame({'datetime': raw_dates})
tm.assert_frame_equal(newdf, res[0])


class TestReadHtmlLxml(unittest.TestCase):
def setUp(self):
self.try_skip()
@classmethod
def setUpClass(cls):
_skip_if_no('lxml')

def read_html(self, *args, **kwargs):
self.flavor = ['lxml']
self.try_skip()
kwargs['flavor'] = kwargs.get('flavor', self.flavor)
return read_html(*args, **kwargs)

def try_skip(self):
_skip_if_no('lxml')

def test_data_fail(self):
from lxml.etree import XMLSyntaxError
spam_data = os.path.join(DATA_PATH, 'spam.html')
Expand All @@ -616,8 +613,22 @@ def test_works_on_valid_markup(self):
def test_fallback_success(self):
_skip_if_none_of(('bs4', 'html5lib'))
banklist_data = os.path.join(DATA_PATH, 'banklist.html')
self.read_html(banklist_data, '.*Water.*', flavor=['lxml',
'html5lib'])
self.read_html(banklist_data, '.*Water.*', flavor=['lxml', 'html5lib'])

def test_parse_dates_list(self):
df = DataFrame({'date': date_range('1/1/2001', periods=10)})
expected = df.to_html()
res = self.read_html(expected, parse_dates=[0], index_col=0)
tm.assert_frame_equal(df, res[0])

def test_parse_dates_combine(self):
raw_dates = Series(date_range('1/1/2001', periods=10))
df = DataFrame({'date': raw_dates.map(lambda x: str(x.date())),
'time': raw_dates.map(lambda x: str(x.time()))})
res = self.read_html(df.to_html(), parse_dates={'datetime': [1, 2]},
index_col=1)
newdf = DataFrame({'datetime': raw_dates})
tm.assert_frame_equal(newdf, res[0])


def test_invalid_flavor():
Expand Down