From 1c71d7c6e145d3ef72f4ecd658b1b4224b8f498a 2021-03-10 15:25:19 From: Brett Smith Date: 2021-03-10 15:25:19 Subject: [PATCH] tests: Add tests for BaseODS.add_annotation(). --- diff --git a/tests/test_reports_spreadsheet.py b/tests/test_reports_spreadsheet.py index a5b0c4d25b33ae11d4d5e3c3cd0023b8f57ffa41..4a9302b56833603d72a53ffdf2273a1a2c2b24d1 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