79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
"""test_reports_spreadsheet - Unit tests for spreadsheet classes"""
|
|
# Copyright © 2020 Brett Smith
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import pytest
|
|
|
|
from . import testutil
|
|
|
|
from conservancy_beancount.reports import core
|
|
|
|
class BaseTester(core.BaseSpreadsheet[tuple, str]):
|
|
def __init__(self):
|
|
self.start_call = None
|
|
self.end_call = None
|
|
self.started_sections = []
|
|
self.ended_sections = []
|
|
self.written_rows = []
|
|
|
|
def section_key(self, row):
|
|
return row[0]
|
|
|
|
def start_spreadsheet(self):
|
|
self.start_call = self.started_sections.copy()
|
|
|
|
def start_section(self, key):
|
|
self.started_sections.append(key)
|
|
|
|
def end_section(self, key):
|
|
self.ended_sections.append(key)
|
|
|
|
def end_spreadsheet(self):
|
|
self.end_call = self.ended_sections.copy()
|
|
|
|
def write_row(self, key):
|
|
self.written_rows.append(key)
|
|
|
|
|
|
@pytest.fixture
|
|
def spreadsheet():
|
|
return BaseTester()
|
|
|
|
def test_spreadsheet(spreadsheet):
|
|
rows = [(ch, ii) for ii, ch in enumerate('aabbcc', 1)]
|
|
spreadsheet.write(iter(rows))
|
|
assert spreadsheet.written_rows == rows
|
|
assert spreadsheet.ended_sections == spreadsheet.started_sections
|
|
assert spreadsheet.started_sections == list('abc')
|
|
assert spreadsheet.start_call == []
|
|
assert spreadsheet.end_call == spreadsheet.ended_sections
|
|
|
|
def test_empty_spreadsheet(spreadsheet):
|
|
empty_list = []
|
|
spreadsheet.write(iter(empty_list))
|
|
assert spreadsheet.start_call == empty_list
|
|
assert spreadsheet.end_call == empty_list
|
|
assert spreadsheet.started_sections == empty_list
|
|
assert spreadsheet.ended_sections == empty_list
|
|
assert spreadsheet.written_rows == empty_list
|
|
|
|
def test_one_section_spreadsheet(spreadsheet):
|
|
rows = [('A', n) for n in range(1, 4)]
|
|
spreadsheet.write(iter(rows))
|
|
assert spreadsheet.written_rows == rows
|
|
assert spreadsheet.ended_sections == spreadsheet.started_sections
|
|
assert spreadsheet.started_sections == list('A')
|
|
assert spreadsheet.start_call == []
|
|
assert spreadsheet.end_call == spreadsheet.ended_sections
|