def tearDown(self): # tear down tests self.s.terminate() del self.s swat.reset_option()
def tearDown(self): self.s.endsession() del self.s swat.reset_option()
def tearDown(self): # tear down tests self.s.endsession() del self.s swat.reset_option()
def test_html(self): out = self.table.fetch()['Fetch'] # No html rendering pd.set_option('display.notebook.repr_html', False) html = out._repr_html_() self.assertTrue(html is None) # Default rendering pd.set_option('display.notebook.repr_html', True) html = out._repr_html_() label = 'Selected Rows from Table DATASOURCES.CARS_SINGLE' columns = [ 'Make', 'Model', 'Type', 'Origin', 'DriveTrain', 'MSRP', 'Invoice', 'EngineSize', 'Cylinders', 'Horsepower', 'MPG_City', 'MPG_Highway', 'Weight', 'Wheelbase', 'Length' ] thstr = [None] + columns soup = BeautifulSoup(html, 'html.parser') htbl = soup.find_all('table')[0] caption = [x.string for x in htbl.find_all('caption')] self.assertEqual(caption, [label]) headers = [x.string for x in htbl.thead.find_all('th')] self.assertEqual(headers, thstr) index = [x.string for x in htbl.tbody.find_all('tr')] data = [x.string for x in htbl.tbody.find_all('td')] self.assertEqual(len(index), 20) self.assertTrue((len(data) == 300) | (len(data) == 320)) self.assertFalse(re.search(r'\d+ rows x \d+ columns', html)) # Add index name out.index.name = 'Index' html = out._repr_html_() thstr = [None] + columns + ['Index'] + [None] * 15 soup = BeautifulSoup(html, 'html.parser') htbl = soup.find_all('table')[0] headers = [x.string for x in htbl.thead.find_all('th')] self.assertEqual(headers, thstr) index = [x.string for x in htbl.tbody.find_all('tr')] data = [x.string for x in htbl.tbody.find_all('td')] self.assertEqual(len(index), 20) self.assertTrue((len(data) == 300) | (len(data) == 320)) self.assertFalse(re.search(r'\d+ rows x \d+ columns', html)) # Truncate out.index.name = None pd.options.display.max_rows = 5 html = out._repr_html_() thstr = [None] + columns soup = BeautifulSoup(html, 'html.parser') htbl = soup.find_all('table')[0] caption = [x.string for x in htbl.find_all('caption')] self.assertEqual(caption, [label]) headers = [x.string for x in htbl.thead.find_all('th')] self.assertEqual(headers, thstr) index = [x.string for x in htbl.tbody.find_all('tr')] data = [x.string for x in htbl.tbody.find_all('td')] self.assertEqual(len(index), 5) self.assertTrue((len(data) == 75) | (len(data) == 80)) self.assertTrue(data.count('...'), len(out.columns)) self.assertTrue(re.search(r'\d+ rows \S \d+ columns', html)) # Don't show dimensions pd.options.display.show_dimensions = False html = out._repr_html_() self.assertFalse(re.search(r'\d+ rows \S \d+ columns', html)) # Only show dimensions on truncate pd.options.display.show_dimensions = 'truncate' html = out._repr_html_() self.assertTrue(re.search(r'\d+ rows \S \d+ columns', html)) pd.options.display.max_rows = 100 html = out._repr_html_() self.assertFalse(re.search(r'\d+ rows \S \d+ columns', html)) # No colinfo swat.reset_option() out.colinfo.clear() html = out._repr_html_() label = 'Selected Rows from Table DATASOURCES.CARS_SINGLE' columns = [ 'Make', 'Model', 'Type', 'Origin', 'DriveTrain', 'MSRP', 'Invoice', 'EngineSize', 'Cylinders', 'Horsepower', 'MPG_City', 'MPG_Highway', 'Weight', 'Wheelbase', 'Length' ] thstr = [None] + columns soup = BeautifulSoup(html, 'html.parser') htbl = soup.find_all('table')[0] caption = [x.string for x in htbl.find_all('caption')] self.assertEqual(caption, [label]) headers = [x.string for x in htbl.thead.find_all('th')] self.assertEqual(headers, thstr) index = [x.string for x in htbl.tbody.find_all('tr')] data = [x.string for x in htbl.tbody.find_all('td')] self.assertEqual(len(index), 20) self.assertTrue((len(data) == 300) | (len(data) == 320)) self.assertFalse(re.search(r'\d+ rows x \d+ columns', html))