@@ -12,12 +12,24 @@ def pyproject_poetry(load_files, file_types):
1212 return files [file_types .POETRY ]
1313
1414
15+ @pytest .fixture
16+ def pyproject_poetry2 (load_files , file_types ):
17+ files = load_files ([file_types .POETRY2 ])
18+ return files [file_types .POETRY2 ]
19+
20+
1521@pytest .fixture
1622def pyproject_poetry_file (create_files , file_types ):
1723 folder = create_files ([(file_types .POETRY , "pyproject.toml" )])
1824 return folder / Path ("pyproject.toml" )
1925
2026
27+ @pytest .fixture
28+ def pyproject_poetry2_file (create_files , file_types ):
29+ folder = create_files ([(file_types .POETRY2 , "pyproject2.toml" )])
30+ return folder / Path ("pyproject2.toml" )
31+
32+
2133@pytest .fixture
2234def pyproject_setuptools (load_files , file_types ):
2335 files = load_files ([file_types .SETUPTOOLS ])
@@ -30,7 +42,7 @@ def pyproject_setuptools_file(create_files, file_types):
3042 return folder / Path ("pyproject.toml" )
3143
3244
33- def test_content_match (pyproject_poetry , pyproject_setuptools ):
45+ def test_content_match (pyproject_poetry , pyproject_poetry2 , pyproject_setuptools ):
3446 # create a function to check both file formats
3547 def assert_content_match (pyproject_file ):
3648 assert pyproject_file .name == "test-package"
@@ -43,29 +55,32 @@ def assert_content_match(pyproject_file):
4355 )
4456 assert len (pyproject_file .authors ) == 1
4557
46- # assert for both formats
58+ # assert for all formats
4759 assert_content_match (pyproject_poetry )
60+ assert_content_match (pyproject_poetry2 )
4861 assert_content_match (pyproject_setuptools )
4962
5063
51- def test_sync (pyproject_poetry , pyproject_setuptools , somesy_input ):
64+ def test_sync (pyproject_poetry , pyproject_poetry2 , pyproject_setuptools , somesy_input ):
5265 def assert_sync (pyproject ):
5366 pyproject .sync (somesy_input .project )
5467 assert pyproject .name == "testproject"
5568 assert pyproject .version == "1.0.0"
5669
5770 assert_sync (pyproject_poetry )
71+ assert_sync (pyproject_poetry2 )
5872 assert_sync (pyproject_setuptools )
5973
6074
61- def test_save (tmp_path , pyproject_poetry , pyproject_setuptools ):
75+ def test_save (tmp_path , pyproject_poetry , pyproject_poetry2 , pyproject_setuptools ):
6276 def assert_save (pyproject ):
6377 custom_path = tmp_path / Path ("pyproject.toml" )
6478 pyproject .save (custom_path )
6579 assert custom_path .is_file ()
6680 custom_path .unlink ()
6781
6882 assert_save (pyproject_poetry )
83+ assert_save (pyproject_poetry2 )
6984 assert_save (pyproject_setuptools )
7085
7186
@@ -97,13 +112,25 @@ def test_from_to_person(person):
97112
98113
99114@pytest .mark .parametrize (
100- "writer_class, writer_file_fixture" ,
101- [(Poetry , "pyproject_poetry_file" ), (SetupTools , "pyproject_setuptools_file" )],
115+ "writer_class, writer_file_fixture, version" ,
116+ [
117+ (Poetry , "pyproject_poetry_file" , 1 ),
118+ (Poetry , "pyproject_poetry2_file" , 2 ),
119+ (SetupTools , "pyproject_setuptools_file" , None ),
120+ ],
102121)
103- def test_person_merge_pyproject (request , writer_class , writer_file_fixture , person ):
122+ def test_person_merge_pyproject (
123+ request , writer_class , writer_file_fixture , version , person
124+ ):
104125 # get suitable project file
105126 writer_file = request .getfixturevalue (writer_file_fixture )
106- pj = writer_class (writer_file )
127+
128+ # Initialize with correct version for Poetry
129+ if writer_class == Poetry :
130+ pj = writer_class (writer_file , version = version )
131+ else :
132+ pj = writer_class (writer_file )
133+
107134 # update project file with known data
108135 pm = ProjectMetadata (
109136 name = "My awesome project" ,
@@ -176,7 +203,8 @@ def test_person_merge_pyproject(request, writer_class, writer_file_fixture, pers
176203
177204
178205def test_without_email (tmp_path , person ):
179- pyproject_str = """
206+ # Test Poetry v1
207+ pyproject_v1_str = """
180208 [tool.poetry]
181209 name = "ttt"
182210 version = "0.1.0"
@@ -187,33 +215,58 @@ def test_without_email(tmp_path, person):
187215 [tool.poetry.dependencies]
188216 python = "^3.10"
189217
190-
191218 [build-system]
192219 requires = ["poetry-core"]
193220 build-backend = "poetry.core.masonry.api"
194221 """
195222
196- # save to file
197- pyproject_file = tmp_path / Path ("pyproject.toml" )
198- pyproject_file .write_text (pyproject_str )
223+ # Test Poetry v2
224+ pyproject_v2_str = """
225+ [tool.poetry]
226+ name = "ttt"
227+ version = "0.1.0"
228+ description = "asd"
229+ authors = ["John Doe"]
230+ license = "MIT"
199231
200- # load and sync
201- p = Poetry (pyproject_file )
202- assert len (p .authors ) == 1
232+ [project]
233+ name = "ttt"
234+ version = "0.1.0"
235+ description = "asd"
236+ authors = ["John Doe"]
237+ license = "MIT"
203238
204- pm = ProjectMetadata (
205- name = "My awesome project" ,
206- description = "Project description" ,
207- license = LicenseEnum .MIT ,
208- version = "0.1.0" ,
209- people = [
210- person .model_copy (
211- update = dict (author = True , publication_author = True , maintainer = True )
212- )
213- ],
214- )
239+ [tool.poetry.dependencies]
240+ python = "^3.10"
241+
242+ [build-system]
243+ requires = ["poetry-core"]
244+ build-backend = "poetry.core.masonry.api"
245+ """
246+
247+ # Test both versions
248+ for pyproject_str , version in [(pyproject_v1_str , 1 ), (pyproject_v2_str , 2 )]:
249+ # save to file
250+ pyproject_file = tmp_path / Path (f"pyproject_v{ version } .toml" )
251+ pyproject_file .write_text (pyproject_str )
252+
253+ # load and sync
254+ p = Poetry (pyproject_file , version = version )
255+ assert len (p .authors ) == 1
256+
257+ pm = ProjectMetadata (
258+ name = "My awesome project" ,
259+ description = "Project description" ,
260+ license = LicenseEnum .MIT ,
261+ version = "0.1.0" ,
262+ people = [
263+ person .model_copy (
264+ update = dict (author = True , publication_author = True , maintainer = True )
265+ )
266+ ],
267+ )
215268
216- p .sync (pm )
269+ p .sync (pm )
217270
218- assert len (p .authors ) == 1
219- assert len (p .maintainers ) == 1
271+ assert len (p .authors ) == 1
272+ assert len (p .maintainers ) == 1
0 commit comments