Ejemplo n.º 1
0
class TestUIPrimitiveBuilder(unittest.TestCase):
    def setUp(self):
        self.builder = XVIZBuilder()
        setup_pose(self.builder)

    def test_null(self):
        builder = XVIZUIPrimitiveBuilder(None, None)
        data = builder.stream('/test').get_data()

        assert data is None

    def test_treetable(self):
        TEST_COLUMNS = [{
            'display_text': 'Name',
            'type': 'STRING'
        }]  # FIXME: type is in lower case in XVIZ
        self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        data = self.builder.get_data().to_object()

        expected = {
            '/test': {
                'treetable': {
                    'columns': TEST_COLUMNS,
                    # 'nodes': [] # FIXME: nodes are no serialized
                }
            }
        }
        assert json.dumps(data['ui_primitives'],
                          sort_keys=True) == json.dumps(expected,
                                                        sort_keys=True)
Ejemplo n.º 2
0
class TestUIPrimitiveBuilder(unittest.TestCase):
    def setUp(self):
        self.builder = XVIZBuilder()
        setup_pose(self.builder)

    def test_null(self):
        builder = XVIZUIPrimitiveBuilder(None, None)
        data = builder.stream('/test').get_data()

        assert data is None

    def test_treetable_no_rows(self):
        TEST_COLUMNS = [{'display_text': 'Name', 'type': 'STRING'}]
        self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        data = self.builder.get_data().to_object()

        expected = {'/test': {'treetable': {'columns': TEST_COLUMNS}}}
        assert data['ui_primitives'] == expected

    def test_treetable_row(self):
        TEST_COLUMNS = [{'display_text': 'Name', 'type': 'STRING'}]
        table = self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        table.row(None, ['Test Row 1'])
        data = self.builder.get_data().to_object()

        expected = {
            '/test': {
                'treetable': {
                    'columns': TEST_COLUMNS,
                    'nodes': [{
                        'column_values': ['Test Row 1']
                    }]
                }
            }
        }
        assert data['ui_primitives'] == expected

    def test_treetable_rows(self):
        TEST_COLUMNS = [{'display_text': 'Name', 'type': 'STRING'}]
        table = self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        table.row(None, ['Test Row 1'])
        table.row(None, ['Test Row 2'])
        data = self.builder.get_data().to_object()

        expected = {
            '/test': {
                'treetable': {
                    'columns':
                    TEST_COLUMNS,
                    'nodes': [{
                        'column_values': ['Test Row 1']
                    }, {
                        'column_values': ['Test Row 2']
                    }]
                }
            }
        }
        assert data['ui_primitives'] == expected

    def test_treetable_row_children(self):
        TEST_COLUMNS = [{'display_text': 'Name', 'type': 'STRING'}]
        table = self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        row1 = table.row(1, ['Test Row 1'])
        row1 = row1.child(2, ['Test Row 2'])
        row2 = table.row(10, ['Test Row 10'])
        row2 = row2.child(20, ['Test Row 20'])
        data = self.builder.get_data().to_object()

        expected = {
            '/test': {
                'treetable': {
                    'columns':
                    TEST_COLUMNS,
                    'nodes': [{
                        'id': 1,
                        'column_values': ['Test Row 1']
                    }, {
                        'parent': 1,
                        'id': 2,
                        'column_values': ['Test Row 2']
                    }, {
                        'id': 10,
                        'column_values': ['Test Row 10']
                    }, {
                        'parent': 10,
                        'id': 20,
                        'column_values': ['Test Row 20']
                    }]
                }
            }
        }
        assert data['ui_primitives'] == expected

    def test_treetable_row_children_creation_order(self):
        TEST_COLUMNS = [{'display_text': 'Name', 'type': 'STRING'}]
        table = self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        # Ensure rows can be created and references remain valid
        row1 = table.row(1, ['Test Row 1'])
        row2 = table.row(10, ['Test Row 10'])

        # Children can be added to rows
        row1.child(2, ['Test Row 2'])
        row2.child(20, ['Test Row 20'])
        data = self.builder.get_data().to_object()

        expected = {
            '/test': {
                'treetable': {
                    'columns':
                    TEST_COLUMNS,
                    'nodes': [{
                        'id': 1,
                        'column_values': ['Test Row 1']
                    }, {
                        'parent': 1,
                        'id': 2,
                        'column_values': ['Test Row 2']
                    }, {
                        'id': 10,
                        'column_values': ['Test Row 10']
                    }, {
                        'parent': 10,
                        'id': 20,
                        'column_values': ['Test Row 20']
                    }]
                }
            }
        }
        assert data['ui_primitives'] == expected

    def test_treetable_column_types(self):
        TEST_COLUMNS = [{
            'display_text': 'string',
            'type': 'STRING'
        }, {
            'display_text': 'int32',
            'type': 'INT32'
        }, {
            'display_text': 'bool',
            'type': 'BOOLEAN'
        }, {
            'display_text': 'double',
            'type': 'DOUBLE'
        }]
        table = self.builder.ui_primitives('/test').treetable(TEST_COLUMNS)
        table.row(1, ['Test', 1, True, 3.14159])
        data = self.builder.get_data().to_object()

        expected = {
            '/test': {
                'treetable': {
                    'columns':
                    TEST_COLUMNS,
                    'nodes': [{
                        'id': 1,
                        'column_values': ['Test', '1', 'True', '3.14159']
                    }]
                }
            }
        }
        assert data['ui_primitives'] == expected