From 1c71d7c6e145d3ef72f4ecd658b1b4224b8f498a Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 10 Mar 2021 10:25:19 -0500 Subject: [PATCH] tests: Add tests for BaseODS.add_annotation(). --- tests/test_reports_spreadsheet.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_reports_spreadsheet.py b/tests/test_reports_spreadsheet.py index a5b0c4d..4a9302b 100644 --- a/tests/test_reports_spreadsheet.py +++ b/tests/test_reports_spreadsheet.py @@ -782,3 +782,23 @@ def test_ods_writer_common_command(ods_writer): ods_writer.set_common_properties(command=['testcmd', 'testarg*']) cmd_prop = get_child(ods_writer.document.meta, odf.meta.UserDefined, name='ReportCommand') assert cmd_prop.text == 'testcmd \'testarg*\'' + +@pytest.mark.parametrize('text,when,parent', itertools.product( + [None, 'comment text'], + [None, datetime.datetime.now()], + [True, False], +)) +def test_ods_add_annotation(ods_writer, text, when, parent): + start_time = datetime.datetime.now() + parent = odf.table.TableCell() if parent else None + actual = ods_writer.add_annotation(text, when, parent) + if text is None: + assert actual.firstChild is actual.lastChild + else: + assert actual.lastChild.text == text + if when is None: + assert actual.firstChild.text >= start_time.isoformat(timespec='seconds') + else: + assert actual.firstChild.text == when.isoformat(timespec='seconds') + if parent is not None: + assert parent.lastChild is actual