1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
from itertools import count
from unittest import TestCase
from unittest.mock import Mock
from pyface.data_view.exporters.row_exporter import RowExporter
from pyface.data_view.i_data_wrapper import DataFormat
trivial_format = DataFormat(
'null/null',
lambda x: str(x).encode('utf-8'),
lambda x: x,
)
class TestRowExporter(TestCase):
def setUp(self):
self.value_type = Mock()
self.value_type.has_text = Mock(return_value=False)
self.value_type.has_editor_value = Mock(return_value=True)
self.value_type.get_editor_value = Mock(
return_value=1,
side_effect=count(),
)
self.model = Mock()
self.model.get_column_count = Mock(return_value=3)
self.model.get_value = Mock(return_value=0)
self.model.get_value_type = Mock(return_value=self.value_type)
def test_get_data(self):
exporter = RowExporter(format=trivial_format)
result = exporter.get_data(self.model, [((0,), (0,)), ((1,), ())])
self.assertEqual(result, [[0, 1, 2], [3, 4, 5]])
def test_get_data_deduplicate(self):
exporter = RowExporter(format=trivial_format)
result = exporter.get_data(
self.model,
[
((0,), (0,)),
((0,), (2,)),
((1,), ()),
])
self.assertEqual(result, [[0, 1, 2], [3, 4, 5]])
def test_get_data_row_headers(self):
exporter = RowExporter(format=trivial_format, row_headers=True)
result = exporter.get_data(self.model, [((0,), (0,)), ((1,), ())])
self.assertEqual(result, [[0, 1, 2, 3], [4, 5, 6, 7]])
def test_get_data_column_headers(self):
exporter = RowExporter(format=trivial_format, column_headers=True)
result = exporter.get_data(self.model, [((0,), (0,)), ((1,), ())])
self.assertEqual(result, [[0, 1, 2], [3, 4, 5], [6, 7, 8]])
|