def test_setup_new(self, m_s): """Call _setup with titles for Indexes sheet.""" wb = Workbook() ws = wb.active iws = IndexesWorksheet(ws) iws.setup() m_s.assert_called_with(('Index', 'Description'))
def test_add_one_bad_type(self): """Raise a TypeError given non-Index data.""" wb = Workbook() ws = wb.active iws = IndexesWorksheet(ws) iws.setup() with pytest.raises(TypeError): iws.add_one('Frogs!')
def test_setup_existing(self, m_s): """Call _setup with no data if sheet titles already populated.""" wb = Workbook() ws = wb.active sws = SeedsWorksheet(ws) sws.set_column_titles(('Index', 'Description')) iws = IndexesWorksheet(sws._ws) iws.setup() assert m_s.call_args_list == [mock.call()]
def test_add_one(self): """Add a single Index to worksheet.""" messages = StringIO() wb = Workbook() ws = wb.active iws = IndexesWorksheet(ws) iws.setup() idx = Index(name='Perennial', description='Built to last.') iws.add_one(idx, stream=messages) assert iws.cell(2, iws.cols['Index']).value == 'Perennial' assert iws.cell( 2, iws.cols['Description'] ).value == 'Built to last.' messages.seek(0) msgs = messages.read() assert ('Adding data from <Index "Perennial"> to row #2 of indexes ' 'worksheet.') in msgs