示例#1
0
 def setUp(self):
     self.t = Table([
         ('A', 'i'),
         ('B', 'u'),
         ('C', 'f'),
         ('D', int)
     ])
示例#2
0
 def test_nones_always_valid(self):
     t = Table([
         ('A', int),
         ('B', float),
         ('C', int),
     ])
     t.append([1, 2.2, None])
示例#3
0
 def test_repr(self):
     t = Table([('A', int), 'B', ('C', float)])
     t.extend([
         [1, "hello", 1.1],
         [2, "goodbye", 2.2],
     ])
     print(repr(t))
示例#4
0
class TestRename(unittest.TestCase):
    def setUp(self):
        self.s = ['pkmn', 'lvl', 'ownr']
        self.t = Table(self.s)

        self.t.extend([
            ('Pikachu', 12, 'ash'),
            ('Squirtle', 18, 'ash'),
            ('Starmie', 4, 'misty'),
        ])

    def test_basic_rename(self):
        t = self.t.rename(old_names=self.t.column_names,
                          new_names=['Pokemon', 'Level', 'Owner'])

        self.assertEqual(t._rename_dict, {
            'pkmn': 'Pokemon',
            'lvl': 'Level',
            'ownr': 'Owner'
        })

        self.assertEquals(t.column_names, ['Pokemon', 'Level', 'Owner'])

    def test_get_renamed_column(self):
        t = self.t.rename(old_names=self.t.column_names,
                          new_names=['Pokemon', 'Level', 'Owner'])
        p = t._get_column('Pokemon')
        self.assertEqual(list(p), ['Pikachu', 'Squirtle', 'Starmie'])
示例#5
0
 def test_nones_always_valid(self):
     t = Table([
         ('A', int),
         ('B', float),
         ('C', int),
     ])
     t.append([1, 2.2, None])
示例#6
0
class TestRestrict(unittest.TestCase):
    def setUp(self):
        self.s = ['A', 'B', 'C']
        self.t = Table(self.s)

        self.t.extend([
            (1, True, 'charmander'),
            (2, False, 'bulbasaur'),
            (3, True, 'squirtle'),
            (4, True, 'pikachu'),
            (5, False, 'butterfree'),
        ])

    def test_restrict_with_materialize(self):
        r = self.t.restrict(col_names=('B'), fn=lambda b: b)

        # We also need to be able to do this
        # operation without a materilize!
        self.assertEquals(list(r.copy().A), [1, 3, 4])

    def test_restrict_without_materialize(self):
        r = self.t.restrict(col_names=('B'), fn=lambda b: b)

        # No copy operation
        self.assertEquals(list(r.A), [1, 3, 4])

    def test_that_restricted_columns_are_consistent(self):
        r = self.t.restrict(col_names=('B'), fn=lambda b: b)

        self.assertEquals(len(r), len(r.A))

        self.assertEquals(list(r), list(zip(list(r.A), list(r.B), list(r.C))))
示例#7
0
 def test_append_invalid_row2(self):
     t = Table([
         ('A', int),
         ('B', float),
         ('C', int),
     ])
     with self.assertRaises(InvalidData):
         t.append([1, 2.2, 'hello'])
示例#8
0
 def test_append_row(self):
     t = Table([
         ('A', int),
         ('B', float),
         ('C', str),
     ])
     t.append([1, 2.2, 'hello'])
     self.assertEqual(list(t), [(1, 2.2, 'hello')])
示例#9
0
 def test_append_invalid_row2(self):
     t = Table([
         ('A', int),
         ('B', float),
         ('C', int),
     ])
     with self.assertRaises(InvalidData):
         t.append([1, 2.2, 'hello'])
示例#10
0
 def test_joined_table_repr(self):
     p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])
     o = Table([('Owner Id', int), ('Owner Name', str)])
     j = p.left_join(keys=('Owner Id',), other=o)
     self.assertEquals(
         repr(j),
         "| Owner Id (int) | Pokemon | Level (int) | Owner Name (str) |"
     )
示例#11
0
 def test_append_row(self):
     t = Table([
         ('A', int),
         ('B', float),
         ('C', str),
     ])
     t.append([1, 2.2, 'hello'])
     self.assertEqual(list(t), [(1, 2.2, 'hello')])
示例#12
0
    def setUp(self):
        self.s = ['pkmn', 'lvl', 'ownr']
        self.t = Table(self.s)

        self.t.extend([
            ('Pikachu', 12, 'ash'),
            ('Squirtle', 18, 'ash'),
            ('Starmie', 4, 'misty'),
        ])
示例#13
0
    def test_append_invalid_row(self):
        t = Table([
            ('A', int),
            ('B', float),
            ('C', str),
        ])

        with self.assertRaises(InvalidData):
            t.append([2, 2.2, int])
示例#14
0
    def test_append_invalid_row(self):
        t = Table([
            ('A', int),
            ('B', float),
            ('C', str),
        ])

        with self.assertRaises(InvalidData):
            t.append([2, 2.2, int])
示例#15
0
    def test_extend_rows(self):
        t = Table([
            ('A', int),
            ('B', float),
            ('C', str),
        ])
        t.extend([[1, 1.1, 'hello'], [2, 2.2, 'goodbye']])

        self.assertEqual(len(t), 2)
示例#16
0
 def test_repr_on_expands(self):
     t = Table([('A', int), ('B', int)])
     t.append([1, 2])
     e = t.expand('C', ['A', 'B'], lambda *args: sum(args), int)
     self.assertEqual(repr(e),
                      "\n".join([
                          "| A (int) | B (int) | C (int) |",
                          "| 1       | 2       | 3       |"
                      ])
                      )
示例#17
0
 def test_repr_on_expand_const(self):
     t = Table([('A', int), ('B', int)])
     t.append([1, 2])
     e = t.expand_const('C', 3, int)
     self.assertEqual(repr(e),
                      "\n".join([
                          "| A (int) | B (int) | C (int) |",
                          "| 1       | 2       | 3       |"
                      ])
                      )
示例#18
0
 def test_empty_table_not_equal_when_schemas_same_but_data_different(self):
     s = [
         ('A', int),
         ('B', float),
         ('C', int),
     ]
     t0 = Table(s)
     t1 = Table(s)
     t0.append([2, 2.22, 1])
     self.assertNotEqual(t0, t1)
示例#19
0
    def test_empty_table_equivalence_when_schemas_same(self):
        s = [
            ('A', int),
            ('B', float),
            ('C', int),
        ]
        t0 = Table(s)
        t1 = Table(s)

        self.assertEqual(t0, t1)
示例#20
0
 def test_empty_table_not_equal_when_schemas_same_but_data_different(self):
     s = [
         ('A', int),
         ('B', float),
         ('C', int),
     ]
     t0 = Table(s)
     t1 = Table(s)
     t0.append([2, 2.22, 1])
     self.assertNotEqual(t0, t1)
示例#21
0
class TestRestrict(unittest.TestCase):

    def setUp(self):
        self.s = ['A', 'B', 'C']
        self.t = Table(self.s)

        self.t.extend([
            (1, True, 'charmander'),
            (2, False, 'bulbasaur'),
            (3, True, 'squirtle'),
            (4, True, 'pikachu'),
            (5, False, 'butterfree'),
        ])

    def test_restrict_with_materialize(self):
        r = self.t.restrict(
            col_names=('B'),
            fn=lambda b: b
        )

        # We also need to be able to do this
        # operation without a materilize!
        self.assertEquals(
            list(r.copy().A),
            [1, 3, 4]
        )

    def test_restrict_without_materialize(self):
        r = self.t.restrict(
            col_names=('B'),
            fn=lambda b: b
        )

        # No copy operation
        self.assertEquals(
            list(r.A),
            [1, 3, 4]
        )

    def test_that_restricted_columns_are_consistent(self):
        r = self.t.restrict(
            col_names=('B'),
            fn=lambda b: b
        )

        self.assertEquals(len(r), len(r.A))

        self.assertEquals(
            list(r),
            list(zip(list(r.A),
                     list(r.B),
                     list(r.C)
                     ))

        )
示例#22
0
    def test_repr_joined_table(self):
        p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])
        p.extend([
            [1, 'Pikachu', 18],
            [99, 'Mew', 43],  # Cannot be joined
        ])
        o = Table([('Owner Id', int), ('Name', str)])
        o.append([1, 'Ash Ketchum'])
        j = p.left_join(
            keys=('Owner Id',),
            other=o
        )

        expected = [
            "| Owner Id (int) | Pokemon | Level (int) | Name (str)  |",
            "| 1              | Pikachu | 18          | Ash Ketchum |",
            "| 99             | Mew     | 43          | None        |"
        ]

        for resultrow, expectedrow in zip(
            repr(j).split('\n'),
                expected):
                self.assertEqual(
                    resultrow,
                    expectedrow
                )
示例#23
0
    def setUp(self):
        self.s = ['A', 'B', 'C']
        self.t = Table(self.s)

        self.t.extend([
            (1, 1.1, 'hello'),
            (2, 2.2, 'goodbye'),
            (3, 3.3, 'yaloo'),
            (4, 4.4, 'fnuu'),
            (5, 6.4, 'Animal Crossing'),
        ])
示例#24
0
    def test_extend_invalid_rows(self):
        t = Table([
            ('A', int),
            ('B', float),
            ('C', str),
        ])

        with self.assertRaises(InvalidData):
            t.extend([
                [1, 1.1, 0],
            ])
示例#25
0
    def setUp(self):
        self.s = ['A', 'B', 'C']
        self.t = Table(self.s)

        self.t.extend([
            (1, True, 'charmander'),
            (2, False, 'bulbasaur'),
            (3, True, 'squirtle'),
            (4, True, 'pikachu'),
            (5, False, 'butterfree'),
        ])
示例#26
0
    def test_extend_invalid_rows(self):
        t = Table([
            ('A', int),
            ('B', float),
            ('C', str),
        ])

        with self.assertRaises(InvalidData):
            t.extend([
                [1, 1.1, 0],
            ])
示例#27
0
    def test_extend_rows(self):
        t = Table([
            ('A', int),
            ('B', float),
            ('C', str),
        ])
        t.extend([
            [1, 1.1, 'hello'],
            [2, 2.2, 'goodbye']
        ])

        self.assertEqual(len(t), 2)
示例#28
0
    def setUp(self):
        self.s = [
            ('A', int),
            ('B', float),
            ('C', str),
        ]
        self.t = Table(self.s)

        self.t.extend([
            [1, 1.1, 'hello'],
            [2, 2.2, 'yello'],
        ])
示例#29
0
    def setUp(self):
        self.s = [
            ('A', int),
            ('B', float),
            ('C', str),
        ]
        self.t = Table(self.s)

        self.t.extend([
            [1, 0.0, 'x'],
            [2, 5.0, 'y'],
            [3, 10.0, 'z'],
        ])
示例#30
0
    def setUp(self):
        self.s = [
            ('A', int),
            ('B', float),
            ('C', str),
        ]
        self.t = Table(self.s)

        self.t.extend([
            (1, 1.1, 'hello'),
            (2, 2.2, 'goodbye'),
            (3, 3.3, 'yaloo'),
            (4, 4.4, 'fnuu'),
        ])
示例#31
0
def table_this(data_object, headers=None):
    """Get an eztable.Table of an iterable like a dataset.
	
	data_object: a list of lists, Ignition DataSet or pyDataSet
	headers: iterable of strings to use as the headers for the table, can be ('header string', type) tuples
		for a typed table
	
	returns: eztable.Table
	"""

    from eztable import Table
    from com.inductiveautomation.ignition.common import BasicDataset
    from com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities import PyDataSet
    from Shared.ds.PyDataList import PyDataList

    if isinstance(data_object, BasicDataset):
        data_object = system.dataset.toPyDataSet(data_object)
        headers = data_object.columnNames if headers is None else headers
    elif isinstance(data_object, PyDataSet):
        headers = data_object.columnNames if headers is None else headers
    elif isinstance(data_object, PyDataList):
        headers = data_object.headers if headers is None else headers
    else:
        headers = [
            'header{}'.format(num) for num in range(len(data_object[0]))
        ] if headers is None else headers

    return Table(headers, data_object)
示例#32
0
 def test_formatted_column_descriptions(self):
     s = [('A', int), ('B', float), ('C', str), ('D', datetime.datetime),
          'E']
     t = Table(s)
     self.assertEqual(
         t._column_descriptions,
         ['A (int)', 'B (float)', 'C (str)', 'D (datetime.datetime)', 'E'])
示例#33
0
class TestTableRowAccess(unittest.TestCase):

    def setUp(self):
        self.s = [
            ('A', int),
            ('B', float),
            ('C', str),
        ]
        self.t = Table(self.s)

        self.t.extend([
            (1, 1.1, 'hello'),
            (2, 2.2, 'goodbye'),
            (3, 3.3, 'yaloo'),
            (4, 4.4, 'fnuu'),
        ])

    def test_basic_slice(self):
        t = self.t[0:2:]
        self.assertEqual(len(t), 2)
        self.assertEqual(t.schema, self.s)

    def test_get_row(self):
        self.assertEqual(
            self.t[0],
            (1, 1.1, 'hello')
        )

    def test_get_sliced_row(self):
        t = self.t[1:]
        self.assertEqual(
            t[0],
            (2, 2.2, 'goodbye'),
        )

    def test_get_sliced_row_reverse(self):
        t = self.t[::-1]
        self.assertEqual(
            t[0],
            (4, 4.4, 'fnuu'),
        )

    def test_get_sliced_row_indexerror(self):
        t = self.t[1:]
        with self.assertRaises(IndexError):
            assert t[3]
示例#34
0
    def setUp(self):
        self.s = ['pkmn', 'lvl', 'ownr']
        self.t = Table(self.s)

        self.t.extend([
            ('Pikachu', 12, 'ash'),
            ('Squirtle', 18, 'ash'),
            ('Starmie', 4, 'misty'),
        ])
示例#35
0
class TestJoinWithNonMatchingKeys(unittest.TestCase):

    def setUp(self):
        self.pokedex = Table(['pokemon', 'owner', 'level'])
        self.pokedex.extend([
            ['Charmander', 'Ash', 12],
            ['Pikachu', 'Ash', 15],
            ['Squirtle', 'Ash', 19],
            ['Starmie', 'Misty', 19],
            ['Togepi', 'Misty', 5],
            ['Onyx', 'Brock', 22],
            ['Meowth', 'Team Rocket', 22],
        ])

        self.types = Table(['pkmn', 'type'])
        self.types.extend([
            ['Togepi', 'Fairy'],
            ['Onyx', 'Rock'],
            ['Meowth', 'Normal'],
            ['Pikachu', 'Electric'],
            ['Squirtle', 'Water'],
            ['Starmie', 'Water'],
            ['Charmander', 'Fire'],
        ])

    def test_basic_join(self):

        t = self.pokedex.left_join(
            keys=('pokemon',),
            other=self.types,
            other_keys=('pkmn',),
        )

        self.assertIsInstance(t, JoinTable)

        self.assertEquals(
            t._key_columns,
            [t.pokemon, ]
        )

        self.assertEquals(
            t.column_names,
            ['pokemon', 'owner', 'level', 'type']
        )
示例#36
0
class TestInnerJoin(unittest.TestCase, TableTestMixin):

    def setUp(self):
        self.pokedex = Table([('pokemon', str), ('owner', str), ('level', 'i')])
        self.pokedex.extend([
            ['Charmander', 'Ash', 12],
            ['Pikachu', 'Ash', 15],
            ['Squirtle', 'Ash', 19],
            ['Starmie', 'Misty', 19],
            ['Togepi', 'Misty', 5],
            ['Onyx', 'Brock', 22],
            ['Meowth', 'Team Rocket', 22],
            ['Mew', None, 1],
            ['Mewtwo', None, 1],
        ])

        self.types = Table([('pokemon', str), ('type', str)])
        self.types.extend([
            ['Togepi', 'Fairy'],
            ['Onyx', 'Rock'],
            ['Meowth', 'Normal'],
            ['Charmander', 'Fire'],
            ['Snorlax', 'Normal']
        ])

    def test_inner_join_simple(self):
        j = self.pokedex.inner_join(
            keys=('pokemon',),
            other=self.types
        )

        expected = table_literal("""
            | pokemon (str) | owner (str) | level (i) | type (str) |
            | Charmander    | Ash         | 12        | Fire       |
            | Togepi        | Misty       | 5         | Fairy      |
            | Onyx          | Brock       | 22        | Rock       |
            | Meowth        | Team Rocket | 22        | Normal     |
        """)

        self.assertTablesEqual(
            j.copy(),
            expected
        )
示例#37
0
    def test_column_descriptions_on_join(self):
        p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])
        p.extend([
            [1, 'Pikachu', 18],
        ])
        o = Table([('Owner Id', int), ('Name', str)])
        o.append([1, 'Ash Ketchum'])
        j = p.left_join(
            keys=('Owner Id',),
            other=o
        )

        self.assertEqual(
            ['Owner Id (int)', 'Pokemon', 'Level (int)', 'Name (str)'],
            j._column_descriptions
        )
示例#38
0
    def setUp(self):
        self.s = ['A', 'B', 'C']
        self.t = Table(self.s)

        self.t.extend([
            (1, True, 'charmander'),
            (2, False, 'bulbasaur'),
            (3, True, 'squirtle'),
            (4, True, 'pikachu'),
            (5, False, 'butterfree'),
        ])
示例#39
0
    def setUp(self):
        self.s = [
            ('A', int),
            ('B', float),
            ('C', str),
        ]
        self.t = Table(self.s)

        self.t.extend([
            [1, 1.1, 'hello'],
            [2, 2.2, 'yello'],
        ])
示例#40
0
def printDataGroupedByProjects(data):

    if not data.has_key("issue"):
        print "data doesn't have key issue"

    project = {}

    p = Table(
        # ['project' , ('issue_id',int) , 'issue_subject','issue']
        ['project', 'tracker', ('issue_id', int),
         'issue_status', 'issue_subject', 'issue_description']
    )

    for issue in data['issue']:
        project_name = issue["project"]["@name"]
        issue_id = issue["id"]
        issue_status = issue["status"]["@name"]
        issue_subject = str((issue["subject"])).strip()
        tracker = issue["tracker"]["@name"]
        issue_description = issue["description"]
        # p.append([project_name,issue_id,issue_subject,issue["description"]])
        p.append([project_name, tracker, issue_id, issue_status,
                  issue_subject, issue_description])

    p.to_csv(open("issues.csv", "w"))
示例#41
0
class TestProject(unittest.TestCase):
    def setUp(self):
        self.s = [("A", int), ("B", float), ("C", str)]
        self.t = Table(self.s)

        self.t.extend([[1, 1.1, "hello"], [2, 2.2, "yello"]])

    def test_simple_project(self):
        t = self.t.project(["A", "C"])
        self.assertEqual(t.schema, [("A", int), ("C", str)])
        self.assertEqual(t[0], (1, "hello"))

    def test_anti_project(self):
        t = self.t.anti_project(["B"])
        self.assertEqual(t.schema, [("A", int), ("C", str)])
        self.assertEqual(t[0], (1, "hello"))

    def test_anti_project_multiple_arguments(self):
        t = self.t.anti_project("A", "B")
        self.assertEqual(t.schema, [("C", str)])
        self.assertEqual(t[0], ("hello",))

    def test_expand_const_on_project(self):
        t0 = self.t.project(["C"])
        t1 = t0.expand_const("D", 0)
        self.assertEqual(list(t1.D), [0] * len(self.t))
示例#42
0
class TestProject(unittest.TestCase):
    def setUp(self):
        self.s = [
            ('A', int),
            ('B', float),
            ('C', str),
        ]
        self.t = Table(self.s)

        self.t.extend([
            [1, 1.1, 'hello'],
            [2, 2.2, 'yello'],
        ])

    def test_simple_project(self):
        t = self.t.project(['A', 'C'])
        self.assertEqual(t.schema, [('A', int), ('C', str)])
        self.assertEqual(t[0], (1, 'hello'))

    def test_anti_project(self):
        t = self.t.anti_project(['B'])
        self.assertEqual(t.schema, [('A', int), ('C', str)])
        self.assertEqual(t[0], (1, 'hello'))

    def test_anti_project_multiple_arguments(self):
        t = self.t.anti_project('A', 'B')
        self.assertEqual(t.schema, [('C', str)])
        self.assertEqual(t[0], ('hello', ))

    def test_expand_const_on_project(self):
        t0 = self.t.project(['C'])
        t1 = t0.expand_const('D', 0)
        self.assertEqual(list(t1.D), [0] * len(self.t))
示例#43
0
    def setUp(self):
        self.pokedex = Table([('pokemon', str), ('owner', str), ('level', 'i')])
        self.pokedex.extend([
            ['Charmander', 'Ash', 12],
            ['Pikachu', 'Ash', 15],
            ['Squirtle', 'Ash', 19],
            ['Starmie', 'Misty', 19],
            ['Togepi', 'Misty', 5],
            ['Onyx', 'Brock', 22],
            ['Meowth', 'Team Rocket', 22],
            ['Mew', None, 1],
            ['Mewtwo', None, 1],
        ])

        self.types = Table([('pokemon', str), ('type', str)])
        self.types.extend([
            ['Togepi', 'Fairy'],
            ['Onyx', 'Rock'],
            ['Meowth', 'Normal'],
            ['Charmander', 'Fire'],
            ['Snorlax', 'Normal']
        ])
示例#44
0
    def setUp(self):
        self.pokedex = Table(['pokemon', 'owner', 'level'])
        self.pokedex.extend([
            ['Charmander', 'Ash', 12],
            ['Pikachu', 'Ash', 15],
            ['Squirtle', 'Ash', 19],
            ['Starmie', 'Misty', 19],
            ['Togepi', 'Misty', 5],
            ['Onyx', 'Brock', 22],
            ['Meowth', 'Team Rocket', 22],
        ])

        self.types = Table(['pkmn', 'type'])
        self.types.extend([
            ['Togepi', 'Fairy'],
            ['Onyx', 'Rock'],
            ['Meowth', 'Normal'],
            ['Pikachu', 'Electric'],
            ['Squirtle', 'Water'],
            ['Starmie', 'Water'],
            ['Charmander', 'Fire'],
        ])
示例#45
0
class TestRename(unittest.TestCase):

    def setUp(self):
        self.s = ['pkmn', 'lvl', 'ownr']
        self.t = Table(self.s)

        self.t.extend([
            ('Pikachu', 12, 'ash'),
            ('Squirtle', 18, 'ash'),
            ('Starmie', 4, 'misty'),
        ])

    def test_basic_rename(self):
        t = self.t.rename(
            old_names=self.t.column_names,
            new_names=['Pokemon', 'Level', 'Owner']
        )

        self.assertEqual(
            t._rename_dict,
            {'pkmn': 'Pokemon', 'lvl': 'Level', 'ownr': 'Owner'}

        )

        self.assertEquals(
            t.column_names,
            ['Pokemon', 'Level', 'Owner']
        )

    def test_get_renamed_column(self):
        t = self.t.rename(
            old_names=self.t.column_names,
            new_names=['Pokemon', 'Level', 'Owner']
        )
        p = t._get_column('Pokemon')
        self.assertEqual(
            list(p),
            ['Pikachu', 'Squirtle', 'Starmie']
        )
示例#46
0
 def test_repr_bigger_broken_join_with_project(self):
     p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])
     p.extend([
         [1, 'Pikachu', 18],
         [1, 'Bulbasaur', 22],
         [1, 'Charmander', 12],
         [3, 'Togepi', 5],
         [1, 'Starmie', 44],
         [9, 'Mew', 99],
     ])
     o = Table([('Owner Id', int), ('Name', str)])
     o.append([1, 'Ash Ketchum'])
     o.append([2, 'Brock'])
     o.append([3, 'Misty'])
     j = p.left_join(
         keys=('Owner Id',),
         other=o
     )
     j2 = j.project('Pokemon', 'Level', 'Name')
     print(repr(j2))
示例#47
0
    def test_incomplete_join(self):
        p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])

        p.extend([
            [1, 'Pikachu', 18],
            [2, 'Blastoise', 22],
            [3, 'Weedle', 4],
        ])

        o = Table([('Owner Id', int), ('Owner Name', str)])
        o.append([1, 'Ash Ketchum'])
        o.append([2, 'Brock'])
        o.append([2, 'Misty'])

        j = p.left_join(
            keys=('Owner Id',),
            other=o
        )

        self.assertEquals(
            j.column_names,
            ['Owner Id', 'Pokemon', 'Level', 'Owner Name']
        )
示例#48
0
class TestArrayTable(unittest.TestCase):

    def setUp(self):
        self.t = Table([
            ('A', 'i'),
            ('B', 'u'),
            ('C', 'f'),
            ('D', int)
        ])

    def test_array_columns(self):
        self.assertIsInstance(self.t._get_column('A'), ArrayColumn)
        self.assertIsInstance(self.t._get_column('D'), Column)

    def test_append(self):
        self.t.append(
            (3, u'h', 2.2, 9)
        )


    def test_repr_column(self):
        self.t.append(
            (3, u'h', 2.5, 9)
        )

        expected = '\n'.join([
            '| A (i) | B (u) | C (f) | D (int) |',
            '| 3     | h     | 2.5   | 9       |'

        ])

        self.assertEquals(
            self.t._get_column('A').column_type,
            'i'
        )

        self.assertEquals(
            self.t._get_column('C').column_type,
            'f'
        )

        self.assertEquals(
            repr(self.t),
            expected
        )
示例#49
0
    def test_joined_table_repr_one_row(self):
        p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])
        p.extend([
            [1, 'Pikachu', 18],
        ])
        o = Table([('Owner Id', int), ('Name', str)])
        o.append([1, 'Ash Ketchum'])
        j = p.left_join(
            keys=('Owner Id',),
            other=o
        )

        self.assertEquals(
            j[0],
            (1, 'Pikachu', 18, 'Ash Ketchum')

        )

        self.assertEquals(
            list(j)[0],
            (1, 'Pikachu', 18, 'Ash Ketchum'),
        )
示例#50
0
    def test_get_maximum_column_widths_for_join(self):
        p = Table([('Owner Id', int), 'Pokemon', ('Level', int)])
        p.extend([
            [1, 'Pikachu', 18],
        ])
        o = Table([('Owner Id', int), ('Name', str)])
        o.append([1, 'Ash Ketchum'])
        j = p.left_join(
            keys=('Owner Id',),
            other=o
        )
        expected = [
            len(j._get_column('Owner Id').description),
            len(j._get_column('Pokemon').description),
            len(j._get_column('Level').description),
            len('Ash Ketchum'),
        ]

        widths = j._get_column_widths()

        self.assertEqual(
            expected,
            widths
        )