Skip to content

Commit b8f61bf

Browse files
committed
add test for poetry person merge
1 parent 0311c80 commit b8f61bf

1 file changed

Lines changed: 64 additions & 2 deletions

File tree

tests/output/test_pyproject_writer.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,67 @@ def test_from_to_person(person):
8080

8181

8282
def test_person_merge_poetry(pyproject_poetry_file, person: Person):
83-
# TODO: package.json is a good example
84-
pass
83+
pj = Poetry(pyproject_poetry_file)
84+
85+
pm = ProjectMetadata(
86+
name="My awesome project",
87+
description="Project description",
88+
license=LicenseEnum.MIT,
89+
people=[person.copy(update=dict(author=True, publication_author=True))],
90+
)
91+
pj.sync(pm)
92+
pj.save()
93+
94+
# jane becomes john -> modified person
95+
person1b = person.copy(
96+
update={"given_names": "John", "author": True, "publication_author": True}
97+
)
98+
99+
# different Jane Doe with different orcid -> new person
100+
person2 = person.copy(
101+
update={
102+
"orcid": "https://orcid.org/4321-0987-3231",
103+
"email": "i.am.jane@doe.com",
104+
"author": True,
105+
"publication_author": True,
106+
}
107+
)
108+
# use different order, just for some difference
109+
person2.set_key_order(["given_names", "orcid", "family_names", "email"])
110+
111+
# listed in "arbitrary" order in somesy metadata (new person comes first)
112+
pm.people = [person2, person1b] # need to assign like that to keep _key_order
113+
pj.sync(pm)
114+
pj.save()
115+
116+
# existing author order preserved
117+
# ERROR: not preserved
118+
assert pj.authors[0] == f"{person1b.full_name} <{person1b.email}>"
119+
120+
assert pj.authors[1] == f"{person2.full_name} <{person2.email}>"
121+
122+
# new person
123+
person3 = Person(
124+
**{
125+
"given_names": "Janice",
126+
"family_names": "Doethan",
127+
"email": "jane93@gmail.com",
128+
"author": True,
129+
"publication_author": True,
130+
}
131+
)
132+
# john has a new email address
133+
person1c = person1b.copy(update={"email": "john.of.us@qualityland.com"})
134+
# jane 2 is removed from authors, but added to maintainers
135+
person2.author = False
136+
person2.publication_author = False
137+
person2.maintainer = True
138+
# reflect in project metadata
139+
pm.people = [person3, person2, person1c]
140+
# sync to CFF file
141+
pj.sync(pm)
142+
pj.save()
143+
144+
assert len(pj.maintainers) == 1
145+
assert pj.authors[0] == f"{person1c.full_name} <{person1c.email}>"
146+
assert pj.authors[1] == f"{person3.full_name} <{person3.email}>"

0 commit comments

Comments
 (0)