This file is indexed.

/usr/lib/python2.7/dist-packages/openpyxl/worksheet/tests/test_dimensions.py is in python-openpyxl 2.4.9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from __future__ import absolute_import
# Copyright (c) 2010-2017 openpyxl

import pytest

from copy import copy

from openpyxl.utils.indexed_list import IndexedList
from openpyxl.styles.styleable import StyleArray

from openpyxl.xml.functions import tostring
from openpyxl.tests.helper import compare_xml


class DummyWorkbook:

    def __init__(self):
        self.shared_styles = IndexedList()
        self._cell_styles = IndexedList()
        self._cell_styles.add(StyleArray())
        self._cell_styles.add(StyleArray([10,0,0,0,0,0,0,0,0,0]))
        self.sheetnames = []


class DummyWorksheet:

    def __init__(self):
        self.parent = DummyWorkbook()


def test_dimension_interface():
    from .. dimensions import Dimension
    d = Dimension(1, True, 1, False, DummyWorksheet())
    assert isinstance(d.parent, DummyWorksheet)
    assert dict(d) == {'hidden': '1', 'outlineLevel': '1'}


def test_invalid_dimension_ctor():
    from .. dimensions import Dimension
    with pytest.raises(TypeError):
        Dimension()


@pytest.fixture
def RowDimension():
    from ..dimensions import RowDimension
    return RowDimension


class TestRowDimension:

    @pytest.mark.parametrize("key, value, expected",
                             [
                                 ('ht', 1, {'ht':'1', 'customHeight':'1'}),
                                 ('_font_id', 10, {'s':'1', 'customFormat':'1'}),
                                 ('thickBot', True, {'thickBot':'1'}),
                                 ('thickTop', True, {'thickTop':'1'}),
                             ]
                             )
    def test_row_dimension(self, RowDimension, key, value, expected):
        rd = RowDimension(worksheet=DummyWorksheet())
        setattr(rd, key, value)
        assert dict(rd) == expected


    def test_row_dimension(self, RowDimension):
        from ..worksheet import Worksheet
        ws = Worksheet(DummyWorkbook())
        row_info = ws.row_dimensions
        assert isinstance(row_info[1], RowDimension)


    def test_copy(self, RowDimension):
        rd1 = RowDimension(worksheet=DummyWorksheet(), s=[])
        rd2 = copy(rd1)
        assert rd1._style is not rd2._style
        assert dict(rd1) == dict(rd2)


@pytest.fixture
def ColumnDimension():
    from ..dimensions import ColumnDimension
    return ColumnDimension


class TestColDimension:

    @pytest.mark.parametrize("key, value, expected",
                             [
                                 ('width', 1, {'width':'1', 'customWidth':'1'}),
                                 ('bestFit', True, {'bestFit':'1'}),
                             ]
                             )
    def test_col_dimensions(self, ColumnDimension, key, value, expected):
        cd = ColumnDimension(worksheet=DummyWorksheet())
        setattr(cd, key, value)
        assert dict(cd) == expected


    def test_column_dimension(self, ColumnDimension):
        from ..worksheet import Worksheet
        ws = Worksheet(DummyWorkbook())
        cols = ws.column_dimensions
        assert isinstance(cols['A'], ColumnDimension)


    def test_col_reindex(self, ColumnDimension):
        cd = ColumnDimension(DummyWorksheet(), index="D")
        assert dict(cd) == {}
        cd.reindex()
        assert dict(cd) == {'max': '4', 'min': '4'}


    def test_col_width(self, ColumnDimension):
        cd = ColumnDimension(DummyWorksheet(), index="A", width=4)
        cd.reindex()
        col = cd.to_tree()
        xml = tostring(col)
        expected = """<col width="4" min="1" max="1" customWidth="1" />"""
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_col_style(self, ColumnDimension):
        from ..worksheet import Worksheet
        from openpyxl import Workbook
        from openpyxl.styles import Font

        ws = Worksheet(Workbook())
        cd = ColumnDimension(ws, index="A")
        cd.font = Font(color="FF0000")
        cd.reindex()
        col = cd.to_tree()
        xml = tostring(col)
        expected = """<col max="1" min="1" style="1" />"""
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_outline_cols(self, ColumnDimension):
        ws = DummyWorksheet()
        cd = ColumnDimension(ws, index="B", outline_level=1)
        cd.reindex()
        col = cd.to_tree()
        xml = tostring(col)
        expected = """<col max="2" min="2" outlineLevel="1"/>"""
        diff = compare_xml(expected, xml)
        assert diff is None, diff


    def test_copy(self, ColumnDimension):
        cd1 = ColumnDimension(worksheet=DummyWorksheet(), style=[])
        cd2 = copy(cd1)
        assert cd1._style is not cd2._style
        assert dict(cd1) == dict(cd2)


    def test_no_named_style(self, ColumnDimension):
        cd = ColumnDimension(worksheet=DummyWorksheet())
        with pytest.raises(AttributeError):
            cd.style = "Normal"


class TestGrouping:

    def test_group_columns_simple(self):
        from ..worksheet import Worksheet
        ws = Worksheet(DummyWorkbook())
        dims = ws.column_dimensions
        dims.group('A', 'C', 1)
        assert len(dims) == 1
        group = list(dims.values())[0]
        assert group.outline_level == 1
        assert group.min == 1
        assert group.max == 3


    def test_group_columns_collapse(self):
        from ..worksheet import Worksheet
        ws = Worksheet(DummyWorkbook())
        dims = ws.column_dimensions
        dims.group('A', 'C', 1, hidden=True)
        group = list(dims.values())[0]
        assert group.hidden


    def test_no_cols(self):
        from ..dimensions import DimensionHolder
        dh = DimensionHolder(None)
        node = dh.to_tree()
        assert node is None