Skip to content

Commit

Permalink
Removed aastex.CorrespondingAuthor, and added aastex.Author.email
Browse files Browse the repository at this point in the history
… field. (#2)
  • Loading branch information
byrdie committed Jun 3, 2024
1 parent f972bee commit 6e6a317
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 41 deletions.
47 changes: 25 additions & 22 deletions aastex/_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"Title",
"Affiliation",
"Author",
"CorrespondingAuthor",
"Acronym",
"Abstract",
"Section",
Expand Down Expand Up @@ -76,33 +75,37 @@ class Author(pylatex.base_classes.LatexObject):

name: str
"""Name of the author"""
affiliation: Affiliation
"""organization affiliated with the author"""

def dumps(self) -> str:
return pylatex.Command("author", self.name).dumps() + self.affiliation.dumps()
affiliation: Affiliation
"""The organization affiliated with the author"""

email: None | str = None
"""
The optional email address of the author.
If this is not :obj:`None`, this author is assumed to be the corresponding
author.
"""

@dataclasses.dataclass
class CorrespondingAuthor(pylatex.base_classes.LatexObject):
"""The corresponding author of this article."""
def dumps(self) -> str:
author = pylatex.Command("author", self.name).dumps()
affilation = self.affiliation.dumps()
result = f"{author}\n{affilation}"

if self.email is not None:
corresponding_author = pylatex.Command(
command="correspondingauthor",
arguments=self.name,
).dumps()

name: str
"""Name of the corresponding author"""
email = pylatex.Command(
command="email",
arguments=self.email,
).dumps()

email: str
"""Email address of the corresponding author"""
result += f"\n{corresponding_author}\n{email}"

def dumps(self) -> str:
author = pylatex.Command(
command="correspondingauthor",
arguments=self.name,
)
email = pylatex.Command(
command="email",
arguments=self.email,
)
return author.dumps() + email.dumps()
return result


@dataclasses.dataclass
Expand Down
23 changes: 4 additions & 19 deletions aastex/_tests/test_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_dumps(self, a: aastex.Affiliation):
aastex.Author(
name="Jane Doe",
affiliation=aastex.Affiliation("Fancy University"),
email="jane.doe@tmp.com",
),
],
)
Expand All @@ -51,26 +52,10 @@ def test_name(self, a: aastex.Author):
def test_affiliation(self, a: aastex.Author):
assert isinstance(a.affiliation, aastex.Affiliation)

def test_dumps(self, a: aastex.Author):
assert isinstance(a.dumps(), str)


@pytest.mark.parametrize(
argnames="a",
argvalues=[
aastex.CorrespondingAuthor(
name="Jane Doe",
email="jane.doe@tmp.com",
),
],
)
class TestCorrespondingAuthor:

def test_name(self, a: aastex.Author):
assert isinstance(a.name, str)

def test_email(self, a: aastex.Author):
assert isinstance(a.email, str)
result = a.email
if result is not None:
assert isinstance(result, str)

def test_dumps(self, a: aastex.Author):
assert isinstance(a.dumps(), str)
Expand Down

0 comments on commit 6e6a317

Please sign in to comment.