@pytest.mark.skipif('not HAS_BEAUTIFUL_SOUP')
def test_htmlinputter():
 f = 't/html.html'
 with open(f) as fd:
  table = fd.read()
 inputter = html.HTMLInputter()
 inputter.html = {}
 expected = ['<tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>', '<tr><td>1</td><td>a</td><td>1.05</td></tr>', '<tr><td>2</td><td>b</td><td>2.75</td></tr>', '<tr><td>3</td><td>c</td><td>-1.25</td></tr>']
 assert ([str(x) for x in inputter.get_lines(table)] == expected)
 inputter.html = {'table_id': 4}
 with pytest.raises(core.InconsistentTableError):
  inputter.get_lines(table)
 inputter.html['table_id'] = 'second'
 expected = ['<tr><th>Column A</th><th>Column B</th><th>Column C</th></tr>', '<tr><td>4</td><td>d</td><td>10.5</td></tr>', '<tr><td>5</td><td>e</td><td>27.5</td></tr>', '<tr><td>6</td><td>f</td><td>-12.5</td></tr>']
 assert ([str(x) for x in inputter.get_lines(table)] == expected)
 inputter.html['table_id'] = 3
 expected = ['<tr><th>C1</th><th>C2</th><th>C3</th></tr>', '<tr><td>7</td><td>g</td><td>105.0</td></tr>', '<tr><td>8</td><td>h</td><td>275.0</td></tr>', '<tr><td>9</td><td>i</td><td>-125.0</td></tr>']
 assert ([str(x) for x in inputter.get_lines(table)] == expected)

@ pytest . mark . skipif ( 'not HAS_BEAUTIFUL_SOUP' ) def test_htmlinputter ( ) : f = 't/html.html' with open ( f ) as fd : table = fd . read ( ) inputter = html . HTMLInputter ( ) inputter . html = { } expected = [ '<tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>' , '<tr><td>1</td><td>a</td><td>1.05</td></tr>' , '<tr><td>2</td><td>b</td><td>2.75</td></tr>' , '<tr><td>3</td><td>c</td><td>-1.25</td></tr>' ] assert ( [ str ( x ) for x in inputter . get_lines ( table ) ] == expected ) inputter . html = { 'table_id' : 4 } with pytest . raises ( core . InconsistentTableError ) : inputter . get_lines ( table ) inputter . html [ 'table_id' ] = 'second' expected = [ '<tr><th>Column A</th><th>Column B</th><th>Column C</th></tr>' , '<tr><td>4</td><td>d</td><td>10.5</td></tr>' , '<tr><td>5</td><td>e</td><td>27.5</td></tr>' , '<tr><td>6</td><td>f</td><td>-12.5</td></tr>' ] assert ( [ str ( x ) for x in inputter . get_lines ( table ) ] == expected ) inputter . html [ 'table_id' ] = 3 expected = [ '<tr><th>C1</th><th>C2</th><th>C3</th></tr>' , '<tr><td>7</td><td>g</td><td>105.0</td></tr>' , '<tr><td>8</td><td>h</td><td>275.0</td></tr>' , '<tr><td>9</td><td>i</td><td>-125.0</td></tr>' ] assert ( [ str ( x ) for x in inputter . get_lines ( table ) ] == expected )
test to ensure that htmlinputter correctly converts input into a list of soupstrings representing table elements .