Esempio n. 1
0
    def testSetValues(self):
        """Tests setting row values from 'From' method."""

        # Set values from Dict.
        self.row._SetValues({'a': 'seven', 'b': 'eight', 'c': 'nine'})
        self.assertEqual(['seven', 'eight', 'nine'], self.row._values)
        self.row._SetValues({'b': '8', 'a': '7', 'c': '9'})
        self.assertEqual(['7', '8', '9'], self.row._values)

        # Converts integers to string equivalents.
        # Excess key/value pairs are ignored.
        self.row._SetValues({'a': 1, 'b': 2, 'c': 3, 'd': 4})
        self.assertEqual(['1', '2', '3'], self.row._values)

        # Values can come from a list of equal length the the keys.
        self.row._SetValues((7, '8', 9))
        self.assertEqual(['7', '8', '9'], self.row._values)

        # Or from a tuple of the same length.
        self.row._SetValues(('vb', 'coopers', 'squires'))
        self.assertEqual(['vb', 'coopers', 'squires'], self.row._values)

        # Raise error if list length is incorrect.
        self.assertRaises(TypeError, self.row._SetValues,
                          ['seven', 'eight', 'nine', 'ten'])
        # Raise error if row object has mismatched header.
        row = texttable.Row()
        self.row._keys = ['a']
        self.row._values = ['1']
        self.assertRaises(TypeError, self.row._SetValues, row)
        # Raise error if assigning wrong data type.
        self.assertRaises(TypeError, row._SetValues, 'abc')
Esempio n. 2
0
 def testCustomRow(self):
     table = texttable.TextTable()
     table.header = ('a', 'b', 'c')
     self.assertEqual(type(texttable.Row()), type(table[0]))
     table = texttable.TextTable(row_class=MyRow)
     self.assertEqual(MyRow, table.row_class)
     table.header = ('a', 'b', 'c')
     self.assertEqual(type(MyRow()), type(table[0]))
Esempio n. 3
0
 def testRowPublicMethods(self):
     self.row.header = ('x', 'y', 'z')
     # Header should be set, values initialised to None.
     self.assertEqual(['x', 'y', 'z'], self.row.header)
     self.assertEqual(['1', '2', '3'], self.row.values)
     row = texttable.Row()
     row.header = ('x', 'y', 'z')
     self.assertEqual(['x', 'y', 'z'], row.header)
     self.assertEqual([None, None, None], row.values)
Esempio n. 4
0
    def testRowBasicMethods(self):
        row = texttable.Row()
        # Setting columns (__setitem__).
        row['a'] = 'one'
        row['b'] = 'two'
        row['c'] = 'three'

        # Access a single column (__getitem__).
        self.assertEqual('one', row['a'])
        self.assertEqual('two', row['b'])
        self.assertEqual('three', row['c'])

        # Access multiple columns (__getitem__).
        self.assertEqual(['one', 'three'], row[('a', 'c')])
        self.assertEqual(['two', 'three'], row[('b', 'c')])

        # Access integer indexes (__getitem__).
        self.assertEqual('one', row[0])
        self.assertEqual(['two', 'three'], row[1:])

        # Test "get".
        self.assertEqual('one', row.get('a'))
        self.assertEqual('one', row.get('a', 'four'))
        self.assertEqual('four', row.get('d', 'four'))
        self.assertIsNone(row.get('d'))

        self.assertEqual(['one', 'three'], row.get(('a', 'c'), 'four'))
        self.assertEqual(['one', 'four'], row.get(('a', 'd'), 'four'))
        self.assertEqual(['one', None], row.get(('a', 'd')))

        self.assertEqual('one', row.get(0, 'four'))
        self.assertEqual('four', row.get(3, 'four'))
        self.assertIsNone(row.get(3))

        # Change existing column value.
        row['b'] = 'Two'
        self.assertEqual('Two', row['b'])

        # Length.
        self.assertEqual(3, len(row))

        # Contains.
        self.assertTrue('two' not in row)
        self.assertTrue('Two' in row)

        # Iteration.
        self.assertEqual(['one', 'Two', 'three'], list(row))
Esempio n. 5
0
 def setUp(self):
     super(UnitTestRow, self).setUp()
     self.row = texttable.Row()
     self.row._keys = ['a', 'b', 'c']
     self.row._values = ['1', '2', '3']
     self.row._BuildIndex()
Esempio n. 6
0
 def setUp(self):
   self.row = texttable.Row()
   self.row._keys = ['a', 'b', 'c']
   self.row._values = ['1', '2', '3']
   self.row._BuildIndex()