Пример #1
0
def test_read_comments():
    xml = """<?xml version="1.0" standalone="yes"?>
    <comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><authors>
    <author>Cuke</author><author>Not Cuke</author></authors><commentList><comment ref="A1"
    authorId="0" shapeId="0"><text><r><rPr><b/><sz val="9"/><color indexed="81"/><rFont
    val="Tahoma"/><charset val="1"/></rPr><t>Cuke:\n</t></r><r><rPr><sz val="9"/><color
    indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr>
    <t xml:space="preserve">First Comment</t></r></text></comment><comment ref="D1" authorId="0" shapeId="0">
    <text><r><rPr><b/><sz val="9"/><color indexed="81"/><rFont val="Tahoma"/><charset val="1"/>
    </rPr><t>Cuke:\n</t></r><r><rPr><sz val="9"/><color indexed="81"/><rFont val="Tahoma"/>
    <charset val="1"/></rPr><t xml:space="preserve">Second Comment</t></r></text></comment>
    <comment ref="A2" authorId="1" shapeId="0"><text><r><rPr><b/><sz val="9"/><color
    indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr><t>Not Cuke:\n</t></r><r><rPr>
    <sz val="9"/><color indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr>
    <t xml:space="preserve">Third Comment</t></r></text></comment></commentList></comments>"""
    wb = Workbook()
    ws = Worksheet(wb)
    comments.read_comments(ws, xml)
    comments_expected = [['A1', 'Cuke', 'Cuke:\nFirst Comment'],
                         ['D1', 'Cuke', 'Cuke:\nSecond Comment'],
                         ['A2', 'Not Cuke', 'Not Cuke:\nThird Comment']
                        ]
    for cell, author, text in comments_expected:
        assert ws.cell(coordinate=cell).comment.author == author
        assert ws.cell(coordinate=cell).comment.text == text
        assert ws.cell(coordinate=cell).comment._parent == ws.cell(coordinate=cell)
Пример #2
0
def test_init():
    wb = Workbook()
    ws = Worksheet(wb)
    c = Comment("text", "author")
    ws.cell(coordinate="A1").comment = c
    assert c._parent == ws.cell(coordinate="A1")
    assert c.text == "text"
    assert c.author == "author"
Пример #3
0
def _create_ws():
    wb = Workbook()
    ws = Worksheet(wb)
    comment1 = Comment("text", "author")
    comment2 = Comment("text2", "author2")
    comment3 = Comment("text3", "author3")
    ws.cell(coordinate="B2").comment = comment1
    ws.cell(coordinate="C7").comment = comment2
    ws.cell(coordinate="D9").comment = comment3
    return ws, comment1, comment2, comment3
Пример #4
0
 def test_garbage_collect(self):
     ws = Worksheet(self.wb)
     ws.cell('A1').value = ''
     ws.cell('B2').value = '0'
     ws.cell('C4').value = 0
     ws.cell('D1').comment = Comment('Comment', 'Comment')
     ws.garbage_collect()
     eq_(set(ws.get_cell_collection()),
         set([ws.cell('B2'), ws.cell('C4'),
              ws.cell('D1')]))
Пример #5
0
    def test_freeze(self):
        ws = Worksheet(self.wb)
        ws.freeze_panes = ws.cell('b2')
        assert ws.freeze_panes == 'B2'

        ws.freeze_panes = ''
        assert ws.freeze_panes is None

        ws.freeze_panes = 'c5'
        assert ws.freeze_panes == 'C5'

        ws.freeze_panes = ws.cell('A1')
        assert ws.freeze_panes is None
Пример #6
0
    def test_append_dict_letter(self):
        ws = Worksheet(self.wb)

        ws.append({'A': 'This is A1', 'C': 'This is C1'})

        eq_('This is A1', ws.cell('A1').value)
        eq_('This is C1', ws.cell('C1').value)
Пример #7
0
    def test_append_list(self):
        ws = Worksheet(self.wb)

        ws.append(['This is A1', 'This is B1'])

        eq_('This is A1', ws.cell('A1').value)
        eq_('This is B1', ws.cell('B1').value)
Пример #8
0
    def test_append_dict_index(self):
        ws = Worksheet(self.wb)

        ws.append({0: 'This is A1', 2: 'This is C1'})

        eq_('This is A1', ws.cell('A1').value)
        eq_('This is C1', ws.cell('C1').value)
Пример #9
0
    def test_hyperlink_relationships(self):
        ws = Worksheet(self.wb)
        eq_(len(ws.relationships), 0)

        ws.cell('A1').hyperlink = "http://test.com"
        eq_(len(ws.relationships), 1)
        eq_("rId1", ws.cell('A1').hyperlink_rel_id)
        eq_("rId1", ws.relationships[0].id)
        eq_("http://test.com", ws.relationships[0].target)
        eq_("External", ws.relationships[0].target_mode)

        ws.cell('A2').hyperlink = "http://test2.com"
        eq_(len(ws.relationships), 2)
        eq_("rId2", ws.cell('A2').hyperlink_rel_id)
        eq_("rId2", ws.relationships[1].id)
        eq_("http://test2.com", ws.relationships[1].target)
        eq_("External", ws.relationships[1].target_mode)
Пример #10
0
 def test_cell_range_name(self):
     ws = Worksheet(self.wb)
     self.wb.create_named_range('test_range_single', ws, 'B12')
     assert_raises(CellCoordinatesException, ws.cell, 'test_range_single')
     c_range_name = ws.range('test_range_single')
     c_range_coord = ws.range('B12')
     c_cell = ws.cell('B12')
     eq_(c_range_coord, c_range_name)
     eq_(c_range_coord, c_cell)
Пример #11
0
    def test_cols(self):

        ws = Worksheet(self.wb)

        ws.cell('A1').value = 'first'
        ws.cell('C9').value = 'last'

        cols = ws.columns

        eq_(len(cols), 3)

        eq_(cols[0][0].value, 'first')
        eq_(cols[-1][-1].value, 'last')
Пример #12
0
    def test_rows(self):

        ws = Worksheet(self.wb)

        ws.cell('A1').value = 'first'
        ws.cell('C9').value = 'last'

        rows = ws.rows

        eq_(len(rows), 9)

        eq_(rows[0][0].value, 'first')
        eq_(rows[-1][-1].value, 'last')
Пример #13
0
def test_comment_count():
    wb = Workbook()
    ws = Worksheet(wb)
    cell = ws.cell(coordinate="A1")
    assert ws._comment_count == 0
    cell.comment = Comment("text", "author")
    assert ws._comment_count == 1
    cell.comment = Comment("text", "author")
    assert ws._comment_count == 1
    cell.comment = None
    assert ws._comment_count == 0
    cell.comment = None
    assert ws._comment_count == 0
Пример #14
0
    def test_merge(self):
        ws = Worksheet(self.wb)
        string_table = {'': '', 'Cell A1': 'Cell A1', 'Cell B1': 'Cell B1'}

        ws.cell('A1').value = 'Cell A1'
        ws.cell('B1').value = 'Cell B1'
        xml_string = write_worksheet(ws, string_table, None)
        assert '<v>Cell B1</v>' in xml_string

        ws.merge_cells('A1:B1')
        xml_string = write_worksheet(ws, string_table, None)
        assert '<v>Cell B1</v>' not in xml_string
        assert '<mergeCells count="1"><mergeCell ref="A1:B1"></mergeCell></mergeCells>' in xml_string

        ws.unmerge_cells('A1:B1')
        xml_string = write_worksheet(ws, string_table, None)
        assert '<mergeCell ref="A1:B1"/>' not in xml_string
Пример #15
0
def test_comment_assignment():
    wb = Workbook()
    ws = Worksheet(wb)
    c = Comment("text", "author")
    ws.cell(coordinate="A1").comment = c
    with pytest.raises(AttributeError):
        ws.cell(coordinate="A2").commment = c
    ws.cell(coordinate="A2").comment = Comment("text2", "author2")
    with pytest.raises(AttributeError):
        ws.cell(coordinate="A1").comment = ws.cell(coordinate="A2").comment
    # this should orphan c, so that assigning it to A2 does not raise AttributeError
    ws.cell(coordinate="A1").comment = None
    ws.cell(coordinate="A2").comment = c
Пример #16
0
 def test_worksheet_dimension(self):
     ws = Worksheet(self.wb)
     eq_('A1:A1', ws.calculate_dimension())
     ws.cell('B12').value = 'AAA'
     eq_('A1:B12', ws.calculate_dimension())
Пример #17
0
 def test_get_cell(self):
     ws = Worksheet(self.wb)
     cell = ws.cell('A1')
     eq_(cell.get_coordinate(), 'A1')
Пример #18
0
 def test_cell_alternate_coordinates(self):
     ws = Worksheet(self.wb)
     cell = ws.cell(row=8, column=4)
     eq_('E9', cell.get_coordinate())
Пример #19
0
 def test_cell_offset(self):
     ws = Worksheet(self.wb)
     eq_('C17', ws.cell('B15').offset(2, 1).get_coordinate())
Пример #20
0
 def test_cell_insufficient_coordinates(self):
     ws = Worksheet(self.wb)
     cell = ws.cell(row=8)