コード例 #1
0
 def test_basic_table_no_content(self):
     t = Table(('Key', 'Value'))
     self.assertEqual(t.nrows, 0)
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "</table>")
コード例 #2
0
 def test_table_append_columns(self):
     t = Table(('Key', 'Person1'))
     t.add_row(Key="Name", Person1="John Doe")
     t.add_row(Key="D.O.B", Person1="12/06/1982")
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Person1</th></tr>\n"
         "<tr><td>Name</td><td>John Doe</td></tr>\n"
         "<tr><td>D.O.B</td><td>12/06/1982</td></tr>\n"
         "</table>")
     t.append_columns("Person2", "Person3")
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Person1</th><th>Person2</th><th>Person3</th></tr>\n"
         "<tr><td>Name</td><td>John Doe</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n"
         "<tr><td>D.O.B</td><td>12/06/1982</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n"
         "</table>")
コード例 #3
0
 def test_basic_table(self):
     t = Table(('Key', 'Value'))
     idx = t.add_row(Key="Employee name", Value="John Doe")
     self.assertEqual(idx, 0)
     self.assertEqual(t.nrows, 1)
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "<tr><td>Employee name</td><td>John Doe</td></tr>\n"
         "</table>")
コード例 #4
0
 def test_table_add_css_classes(self):
     t = Table(('Key', 'Value'))
     t.add_row(Key="Employee name", Value="John Doe")
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "<tr><td>Employee name</td><td>John Doe</td></tr>\n"
         "</table>")
     t.add_css_classes("employee-data")
     self.assertEqual(
         t.html(), "<table class='employee-data'>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "<tr><td>Employee name</td><td>John Doe</td></tr>\n"
         "</table>")
     t.add_css_classes("summary", "sunny")
     self.assertEqual(
         t.html(), "<table class='employee-data summary sunny'>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "<tr><td>Employee name</td><td>John Doe</td></tr>\n"
         "</table>")
コード例 #5
0
 def test_table_with_column_aliases(self):
     t = Table(('name', 'date', 'result'),
               name="Experiment",
               date="Date run",
               result="Final result")
     idx = t.add_row(name="Test setup", date="10/10/2017", result="Ok")
     self.assertEqual(idx, 0)
     self.assertEqual(t.nrows, 1)
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Experiment</th><th>Date run</th><th>Final result</th></tr>\n"
         "<tr><td>Test setup</td><td>10/10/2017</td><td>Ok</td></tr>\n"
         "</table>")
コード例 #6
0
 def test_table_set_value(self):
     t = Table(('Key', 'Value'))
     t.add_row(Key="Name", Value="John Doe")
     t.add_row(Key="D.O.B", Value="12/06/1982")
     t.add_row(Key="Mobile", Value="+44 1726254")
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "<tr><td>Name</td><td>John Doe</td></tr>\n"
         "<tr><td>D.O.B</td><td>12/06/1982</td></tr>\n"
         "<tr><td>Mobile</td><td>+44 1726254</td></tr>\n"
         "</table>")
     t.append_columns("Value2")
     t.set_value(0, "Value2", "Jane Doe")
     t.set_value(1, "Value2", "19/04/1979")
     t.set_value(2, "Value2", "+44 1745262")
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Value</th><th>Value2</th></tr>\n"
         "<tr><td>Name</td><td>John Doe</td><td>Jane Doe</td></tr>\n"
         "<tr><td>D.O.B</td><td>12/06/1982</td><td>19/04/1979</td></tr>\n"
         "<tr><td>Mobile</td><td>+44 1726254</td><td>+44 1745262</td></tr>\n"
         "</table>")
コード例 #7
0
 def test_table_multiple_rows(self):
     t = Table(('Key', 'Value'))
     idx = t.add_row(Key="Name", Value="John Doe")
     self.assertEqual(idx, 0)
     self.assertEqual(t.nrows, 1)
     idx = t.add_row(Key="D.O.B", Value="12/06/1982")
     self.assertEqual(idx, 1)
     self.assertEqual(t.nrows, 2)
     idx = t.add_row(Key="Mobile", Value="+44 1726254")
     self.assertEqual(idx, 2)
     self.assertEqual(t.nrows, 3)
     self.assertEqual(
         t.html(), "<table>\n"
         "<tr><th>Key</th><th>Value</th></tr>\n"
         "<tr><td>Name</td><td>John Doe</td></tr>\n"
         "<tr><td>D.O.B</td><td>12/06/1982</td></tr>\n"
         "<tr><td>Mobile</td><td>+44 1726254</td></tr>\n"
         "</table>")