Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
- uses: actions/checkout@v4
- name: Install LaTeX
if: runner.os == 'Linux'
run: sudo apt-get install texlive-publishers texlive-science cm-super latexmk
# `apt-get` waits forever if another process on the runner holds the
# dpkg lock, so bound that wait and answer its prompts non-interactively.
run: >-
sudo apt-get install -y -o DPkg::Lock::Timeout=300
texlive-publishers texlive-science cm-super latexmk
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
24 changes: 20 additions & 4 deletions aastex/_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ class Author(pylatex.base_classes.LatexObject):
name: str
"""Name of the author"""

affiliation: Affiliation
"""The organization affiliated with the author"""
affiliation: Affiliation | list[Affiliation]
"""
The organization affiliated with the author.

A list may be given for an author with more than one affiliation, such as
someone who has moved since the work was done, in which case the
organization where the work was done is usually given first.
"""

email: None | str = None
"""
Expand Down Expand Up @@ -115,12 +121,22 @@ def dumps(self) -> str:
options=show,
).dumps()

affilation = self.affiliation.dumps()
affiliation = "\n".join(a.dumps() for a in self.affiliations)

result += f"{author}\n{email}\n{affilation}"
result += f"{author}\n{email}\n{affiliation}"

return result

@property
def affiliations(self) -> list[Affiliation]:
"""
The organizations affiliated with the author, as a list, whether one
or several were given.
"""
if isinstance(self.affiliation, Affiliation):
return [self.affiliation]
return list(self.affiliation)


@dataclasses.dataclass
class Acronym(pylatex.base_classes.LatexObject):
Expand Down
23 changes: 22 additions & 1 deletion aastex/_tests/test_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,35 @@ def test_dumps(self, a: aastex.Affiliation):
name="John Doe",
affiliation=aastex.Affiliation("Fancy University"),
),
aastex.Author(
name="Jane Roe",
affiliation=[
aastex.Affiliation("Fancy University"),
aastex.Affiliation("Another Fancy University"),
],
),
],
)
class TestAuthor:
def test_name(self, a: aastex.Author):
assert isinstance(a.name, str)

def test_affiliation(self, a: aastex.Author):
assert isinstance(a.affiliation, aastex.Affiliation)
result = a.affiliation
if not isinstance(result, aastex.Affiliation):
assert all(isinstance(r, aastex.Affiliation) for r in result)

def test_affiliations(self, a: aastex.Author):
result = a.affiliations
assert isinstance(result, list)
assert result
assert all(isinstance(r, aastex.Affiliation) for r in result)

# every affiliation given is rendered
dumps = a.dumps()
assert dumps.count(r"\affiliation") == len(result)
for affiliation in result:
assert affiliation.name in dumps

def test_orcid(self, a: aastex.Author):
result = a.orcid
Expand Down
Loading