Esempio n. 1
0
def test_write_row_passing_no_style():
    ("XL backend.write_row should write row using appropriate "
     "index, value and style")
    row = Mock()

    xl_backend = XL()
    xl_backend.write_row(row, ['Cell One', 'Cell Two'])

    row.write.assert_has_calls([
        call(0, 'Cell One', default_style),
        call(1, 'Cell Two', default_style),
    ])
Esempio n. 2
0
def test_write_row_passing_style():
    ("XL backend.write_row should write row using appropriate "
     "index, value and style")
    # Given a row
    row = Mock()

    # When .write_row is called
    xl_backend = XL()
    xl_backend.write_row(row, ['Cell One', 'Cell Two'], default_style)

    # Then row.write is called appropriately
    row.write.assert_has_calls([
        call(0, 'Cell One', default_style),
        call(1, 'Cell Two', default_style),
    ])
Esempio n. 3
0
def test_writing_with_none_format_string():
    "Writer should not use a format string if None is passed"

    STYLE_CACHE.clear()

    backend = XL()
    output = Mock()

    mock_row = Mock()

    backend.write_row(
        mock_row,
        [['Chuck Norris', 'Power']],
        format_string=None,
    )

    STYLE_CACHE.should.have.length_of(1)
    active_style = STYLE_CACHE.values()[0]
    active_style.num_format_str.should.equal("General")
Esempio n. 4
0
def test_xl_style_cache_works():
    ("The XL backend should cache styles that are the same instead of creating "
    "a new style each time")

    STYLE_CACHE.clear()

    backend = XL()
    output = Mock()

    mock_row = Mock()

    backend.write_row(
        mock_row,
        [['Chuck Norris', 'Power']],
        output=output,
        bold=True,
    )

    STYLE_CACHE.should.have.length_of(1)
    bold_style = STYLE_CACHE.values()[0]

    backend.write_row(
        mock_row,
        [['Name', 'Some other guy']],
        output=output,
    )

    STYLE_CACHE.should.have.length_of(2)
    non_bold_style = [style for style in STYLE_CACHE.values() if style != bold_style][0]

    backend.write_row(
        mock_row,
        [['Name', 'Another person']],
        output=output,
        bold=True,
    )

    mock_row.write.assert_has_calls([
        call(0, ['Chuck Norris', 'Power'], bold_style),
        call(0, ['Name', 'Some other guy'], non_bold_style),
        call(0, ['Name', 'Another person'], bold_style),
    ])

    STYLE_CACHE.should.have.length_of(2)