This file is indexed.

/usr/lib/python2.7/dist-packages/openpyxl/descriptors/tests/test_nested.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
from __future__ import absolute_import
#copyright openpyxl 2010-2015

from openpyxl.xml.functions import tostring, fromstring
from openpyxl.tests.helper import compare_xml
from ..serialisable import Serialisable


import pytest

@pytest.fixture
def NestedValue():
    from ..nested import NestedValue

    class Simple(Serialisable):

        tagname = "simple"

        size = NestedValue(expected_type=int)

        def __init__(self, size):
            self.size = size

    return Simple


class TestValue:

    def test_to_tree(self, NestedValue):

        simple = NestedValue(4)

        assert simple.size == 4
        xml = tostring(NestedValue.size.to_tree("size", simple.size))
        expected = """
        <size val="4"></size>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_from_tree(self, NestedValue):

        xml = """
            <size val="4"></size>
            """
        node = fromstring(xml)
        simple = NestedValue(size=node)
        assert simple.size == 4


    def test_tag_mismatch(self, NestedValue):

        xml = """
        <length val="4"></length>
        """
        node = fromstring(xml)
        with pytest.raises(ValueError):
            simple = NestedValue(size=node)


    def test_nested_to_tree(self, NestedValue):
        simple = NestedValue(4)
        xml = tostring(simple.to_tree())
        expected = """
        <simple>
          <size val="4"/>
        </simple>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_nested_from_tree(self, NestedValue):
        xml = """
        <simple>
          <size val="4"/>
        </simple>
        """
        node = fromstring(xml)
        obj = NestedValue.from_tree(node)
        assert obj.size == 4


@pytest.fixture
def NestedText():

    from ..nested import NestedText

    class Simple(Serialisable):

        tagname = "simple"

        coord = NestedText(expected_type=int)

        def __init__(self, coord):
            self.coord = coord

    return Simple


class TestText:

    def test_to_tree(self, NestedText):

        simple = NestedText(4)

        assert simple.coord == 4
        xml = tostring(NestedText.coord.to_tree("coord", simple.coord))
        expected = """
        <coord>4</coord>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_from_tree(self, NestedText):
        xml = """
            <coord>4</coord>
            """
        node = fromstring(xml)

        simple = NestedText(node)
        assert simple.coord == 4


    def test_nested_to_tree(self, NestedText):
        simple = NestedText(4)
        xml = tostring(simple.to_tree())
        expected = """
        <simple>
          <coord>4</coord>
        </simple>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_nested_from_tree(self, NestedText):
        xml = """
        <simple>
          <coord>4</coord>
        </simple>
        """
        node = fromstring(xml)
        obj = NestedText.from_tree(node)
        assert obj.coord == 4


def test_bool_value():
    from ..nested import NestedBool

    class Simple(Serialisable):

        bold = NestedBool()

        def __init__(self, bold):
            self.bold = bold


    xml = """
    <font>
       <bold val="true"/>
    </font>
    """
    node = fromstring(xml)
    simple = Simple.from_tree(node)
    assert simple.bold is True


def test_noneset_value():
    from ..nested import NestedNoneSet


    class Simple(Serialisable):

        underline = NestedNoneSet(values=('1', '2', '3'))

        def __init__(self, underline):
            self.underline = underline

    xml = """
    <font>
       <underline val="1" />
    </font>
    """

    node = fromstring(xml)
    simple = Simple.from_tree(node)
    assert simple.underline == '1'

def test_min_max_value():
    from ..nested import NestedMinMax


    class Simple(Serialisable):

        size = NestedMinMax(min=5, max=10)

        def __init__(self, size):
            self.size = size


    xml = """
    <font>
         <size val="6"/>
    </font>
    """

    node = fromstring(xml)
    simple = Simple.from_tree(node)
    assert simple.size == 6


def test_nested_integer():
    from ..nested import NestedInteger


    class Simple(Serialisable):

        tagname = "font"

        size = NestedInteger()

        def __init__(self, size):
            self.size = size


    simple = Simple('4')
    assert simple.size == 4


def test_nested_float():
    from ..nested import NestedFloat


    class Simple(Serialisable):

        tagname = "font"

        size = NestedFloat()

        def __init__(self, size):
            self.size = size


    simple = Simple('4.5')
    assert simple.size == 4.5


def test_nested_string():
    from ..nested import NestedString


    class Simple(Serialisable):

        tagname = "font"

        name = NestedString()

        def __init__(self, name):
            self.name = name


    simple = Simple('4')
    assert simple.name == '4'


@pytest.fixture
def Empty():
    from ..nested import EmptyTag

    class Simple(Serialisable):

        tagname = "break"

        height = EmptyTag()

        def __init__(self, height=None):
            self.height = height

    return Simple


class TestEmptyTag:

    @pytest.mark.parametrize("value, result",
                             [
                                 (False, False),
                                 (True, True),
                                 (None, False),
                                 (1, True)
                             ]
                             )
    def test_ctor(self, Empty, value, result):
        obj = Empty(value)
        assert obj.height is result


    @pytest.mark.parametrize("value, result",
                             [
                                 (False, "<break />"),
                                 (True, "<break><height /></break>")
                             ]
                             )
    def test_to_tree(self, Empty, value, result):
        obj = Empty(height=value)
        xml = tostring(obj.to_tree())
        diff = compare_xml(xml, result)
        assert diff is None, diff


    @pytest.mark.parametrize("value, src",
                             [
                                 (False, "<break />"),
                                 (True, "<break><height /></break>")
                             ]
                             )
    def test_from_xml(self, Empty, value, src):
        node = fromstring(src)
        obj = Empty.from_tree(node)
        assert obj.height is value


@pytest.fixture
def CustomAttribute():
    from ..nested import NestedValue

    class Simple(Serialisable):

        tagname = "simple"

        size = NestedValue(expected_type=int, attribute="something")

        def __init__(self, size):
            self.size = size

    return Simple


class TestCustomAttribute:

    def test_to_tree(self, CustomAttribute):

        simple = CustomAttribute(4)

        assert simple.size == 4
        xml = tostring(CustomAttribute.size.to_tree("size", simple.size))
        expected = """
        <size something="4"></size>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff


    def test_from_tree(self, CustomAttribute):

        xml = """
        <size something="4"></size>
        """
        node = fromstring(xml)
        simple = CustomAttribute(size=node)
        assert simple.size == 4