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)
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")