# Copyright (c) 2010-2023 openpyxl
import pytest
from openpyxl.xml.functions import fromstring, tostring
from openpyxl.tests.helper import compare_xml
[docs]
@pytest.fixture
def AuthorList():
from ..author import AuthorList
return AuthorList
[docs]
class TestAuthor:
[docs]
def test_ctor(self, AuthorList):
vals = ["Bob", "Alice", "Eve"]
author = AuthorList(author=vals)
xml = tostring(author.to_tree())
expected = """
<authors>
<author>Bob</author>
<author>Alice</author>
<author>Eve</author>
</authors>
"""
diff = compare_xml(xml, expected)
assert diff is None, diff
[docs]
def test_from_xml(self, AuthorList):
src = """
<authors>
<author>author2</author>
<author>author</author>
<author>author3</author>
</authors>
"""
node = fromstring(src)
author = AuthorList.from_tree(node)
assert author.author == ["author2", "author", "author3"]