Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed aastex.CorrespondingAuthor, and added aastex.Author.email field. #2

Merged
merged 2 commits into from
Jun 3, 2024
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
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
Loading