22import pytest
33
44from somesy .core .models import LicenseEnum , Person , ProjectMetadata
5- from somesy .pyproject .writer import Poetry , Pyproject , PyprojectCommon , SetupTools
5+ from somesy .pyproject .writer import Poetry , SetupTools
66
77
88@pytest .fixture
@@ -23,6 +23,12 @@ def pyproject_setuptools(load_files, file_types):
2323 return files [file_types .SETUPTOOLS ]
2424
2525
26+ @pytest .fixture
27+ def pyproject_setuptools_file (create_files , file_types ):
28+ folder = create_files ([(file_types .SETUPTOOLS , "pyproject.toml" )])
29+ return folder / Path ("pyproject.toml" )
30+
31+
2632def test_content_match (pyproject_poetry , pyproject_setuptools ):
2733 # create a function to check both file formats
2834 def assert_content_match (pyproject_file ):
@@ -79,7 +85,7 @@ def test_from_to_person(person):
7985 assert p .email == person .email
8086
8187
82- def test_person_merge_poetry (pyproject_poetry_file , person : Person ):
88+ def test_person_merge_poetry (pyproject_poetry_file , person ):
8389 pj = Poetry (pyproject_poetry_file )
8490
8591 pm = ProjectMetadata (
@@ -113,11 +119,12 @@ def test_person_merge_poetry(pyproject_poetry_file, person: Person):
113119 pj .sync (pm )
114120 pj .save ()
115121
116- # existing author order preserved
117- # ERROR: not preserved
118- assert pj .authors [0 ] == f" { person1b . full_name } < { person1b . email } >"
122+ # existing author info preserved, order not preserved because no orcid
123+ person1b_str = f" { person1b . full_name } < { person1b . email } >"
124+ assert ( pj .authors [0 ] == person1b_str ) or ( pj . authors [ 1 ] == person1b_str )
119125
120- assert pj .authors [1 ] == f"{ person2 .full_name } <{ person2 .email } >"
126+ person2_str = f"{ person2 .full_name } <{ person2 .email } >"
127+ assert (pj .authors [0 ] == person2_str ) or (pj .authors [1 ] == person2_str )
121128
122129 # new person
123130 person3 = Person (
@@ -144,3 +151,71 @@ def test_person_merge_poetry(pyproject_poetry_file, person: Person):
144151 assert len (pj .maintainers ) == 1
145152 assert pj .authors [0 ] == f"{ person1c .full_name } <{ person1c .email } >"
146153 assert pj .authors [1 ] == f"{ person3 .full_name } <{ person3 .email } >"
154+
155+
156+ def test_person_merge_setuptools (pyproject_setuptools_file , person ):
157+ pj = SetupTools (pyproject_setuptools_file )
158+
159+ pm = ProjectMetadata (
160+ name = "My awesome project" ,
161+ description = "Project description" ,
162+ license = LicenseEnum .MIT ,
163+ people = [person .copy (update = dict (author = True , publication_author = True ))],
164+ )
165+ pj .sync (pm )
166+ pj .save ()
167+
168+ # jane becomes john -> modified person
169+ person1b = person .copy (
170+ update = {"given_names" : "John" , "author" : True , "publication_author" : True }
171+ )
172+
173+ # different Jane Doe with different orcid -> new person
174+ person2 = person .copy (
175+ update = {
176+ "orcid" : "https://orcid.org/4321-0987-3231" ,
177+ "email" : "i.am.jane@doe.com" ,
178+ "author" : True ,
179+ "publication_author" : True ,
180+ }
181+ )
182+ # use different order, just for some difference
183+ person2 .set_key_order (["given_names" , "orcid" , "family_names" , "email" ])
184+
185+ # listed in "arbitrary" order in somesy metadata (new person comes first)
186+ pm .people = [person2 , person1b ] # need to assign like that to keep _key_order
187+ pj .sync (pm )
188+ pj .save ()
189+
190+ # existing author info preserved, order not preserved because no orcid
191+ person1b_dump = {"name" : person1b .full_name , "email" : person1b .email }
192+ assert (pj .authors [0 ] == person1b_dump ) or (pj .authors [1 ] == person1b_dump )
193+
194+ person2_dump = {"name" : person2 .full_name , "email" : person2 .email }
195+ assert (pj .authors [0 ] == person2_dump ) or (pj .authors [1 ] == person2_dump )
196+
197+ # new person
198+ person3 = Person (
199+ ** {
200+ "given_names" : "Janice" ,
201+ "family_names" : "Doethan" ,
202+ "email" : "jane93@gmail.com" ,
203+ "author" : True ,
204+ "publication_author" : True ,
205+ }
206+ )
207+ # john has a new email address
208+ person1c = person1b .copy (update = {"email" : "john.of.us@qualityland.com" })
209+ # jane 2 is removed from authors, but added to maintainers
210+ person2 .author = False
211+ person2 .publication_author = False
212+ person2 .maintainer = True
213+ # reflect in project metadata
214+ pm .people = [person3 , person2 , person1c ]
215+ # sync to CFF file
216+ pj .sync (pm )
217+ pj .save ()
218+
219+ assert len (pj .maintainers ) == 1
220+ assert pj .authors [0 ] == {"name" : person1c .full_name , "email" : person1c .email }
221+ assert pj .authors [1 ] == {"name" : person3 .full_name , "email" : person3 .email }
0 commit comments