@@ -1027,110 +1027,6 @@ def test_run_with_dependencies_nested_extras(
10271027 assert locker .written_data == expected
10281028
10291029
1030- @pytest .mark .parametrize ("locked" , [False ]) # TODO: lock data
1031- @pytest .mark .parametrize ("extra" , [None , "extra-one" , "extra-two" ])
1032- def test_run_with_conflicting_dependency_extras (
1033- installer : Installer ,
1034- pool : RepositoryPool ,
1035- locker : Locker ,
1036- installed : CustomInstalledRepository ,
1037- repo : Repository ,
1038- config : Config ,
1039- package : ProjectPackage ,
1040- extra : str | None ,
1041- locked : bool ,
1042- ) -> None :
1043- """https://github.com/python-poetry/poetry/issues/834
1044-
1045- Tests resolution of extras in both root ('extra-one', 'extra-two') and transitive
1046- ('demo-extra-one', 'demo-extra-two') dependencies
1047- """
1048- # Demo package with two optional transitive dependencies, one for each extra
1049- demo_pkg = get_package ("demo" , "1.0.0" )
1050- transitive_dep_one = get_package ("transitive-dep" , "1.1.0" )
1051- transitive_dep_two = get_package ("transitive-dep" , "1.2.0" )
1052- demo_pkg .extras = {
1053- canonicalize_name ("demo-extra-one" ): [
1054- get_dependency ("transitive-dep" , constraint = {"version" : "1.1.0" , "optional" : True })
1055- ],
1056- canonicalize_name ("demo-extra-two" ): [
1057- get_dependency ("transitive-dep" , constraint = {"version" : "1.2.0" , "optional" : True })
1058- ],
1059- }
1060- demo_pkg .add_dependency (
1061- Factory .create_dependency (
1062- "transitive-dep" ,
1063- {
1064- "version" : "1.1.0" ,
1065- "markers" : "extra == 'demo-extra-one' and extra != 'demo-extra-two'" ,
1066- "optional" : True ,
1067- }
1068- )
1069- )
1070- demo_pkg .add_dependency (
1071- Factory .create_dependency (
1072- "transitive-dep" ,
1073- {
1074- "version" : "1.2.0" ,
1075- "markers" : "extra != 'demo-extra-one' and extra == 'demo-extra-two'" ,
1076- "optional" : True ,
1077- }
1078- )
1079- )
1080- repo .add_package (demo_pkg )
1081- repo .add_package (transitive_dep_one )
1082- repo .add_package (transitive_dep_two )
1083-
1084- # 'demo' with extra 'demo-extra-one' when package has 'extra-one' extra
1085- # and with extra 'demo-extra-two' when 'extra-two'
1086- extra_one_dep = Factory .create_dependency (
1087- "demo" ,
1088- {
1089- "version" : "1.0.0" ,
1090- "markers" : "extra == 'extra-one' and extra != 'extra-two'" ,
1091- "extras" : ["demo-extra-one" ],
1092- "optional" : True ,
1093- },
1094- )
1095- extra_two_dep = Factory .create_dependency (
1096- "demo" ,
1097- {
1098- "version" : "1.0.0" ,
1099- "markers" : "extra != 'extra-one' and extra == 'extra-two'" ,
1100- "extras" : ["demo-extra-two" ],
1101- "optional" : True ,
1102- },
1103- )
1104- package .add_dependency (extra_one_dep )
1105- package .add_dependency (extra_two_dep )
1106- package .extras = {
1107- canonicalize_name ("extra-one" ): [extra_one_dep ],
1108- canonicalize_name ("extra-two" ): [extra_two_dep ],
1109- }
1110-
1111- locker .locked (locked )
1112- if locked :
1113- raise ValueError ("no lock data for this test yet" )
1114- locker .mock_lock_data (dict (fixture ("TODO" )))
1115-
1116- if extra is not None :
1117- installer .extras ([extra ])
1118- result = installer .run ()
1119- assert result == 0
1120-
1121- if not locked :
1122- raise ValueError ("no lock data for this test yet" )
1123- expected = fixture ("TODO" )
1124- assert locker .written_data == expected
1125-
1126- # Results of installation are consistent with the 'extra' input
1127- assert isinstance (installer .executor , Executor )
1128- if extra is None :
1129- assert len (installer .executor .installations ) == 0
1130- else :
1131- assert len (installer .executor .installations ) == 2
1132-
1133-
11341030@pytest .mark .parametrize ("locked" , [True , False ])
11351031@pytest .mark .parametrize ("extra" , [None , "cpu" , "cuda" ])
11361032def test_run_with_exclusive_extras_different_sources (
@@ -1331,30 +1227,42 @@ def test_run_with_different_dependency_extras(
13311227 extra : str | None ,
13321228 locked : bool ,
13331229) -> None :
1334- """https://github.com/python-poetry/poetry/issues/834"""
1335- # Demo package with two optional transitive dependencies, one for each extra
1230+ """https://github.com/python-poetry/poetry/issues/834
1231+
1232+ This tests different sets of extras in a dependency of the root project. These different dependency extras are
1233+ themselves conditioned on extras in the root project.
1234+ """
1235+ # Three packages in additon to root: demo (direct dependency) and two transitive dep packages
13361236 demo_pkg = get_package ("demo" , "1.0.0" )
1337- transitive_dep_one = get_package ("transitive-dep-one" , "1.1.0" )
1338- transitive_dep_two = get_package ("transitive-dep-two" , "1.2.0" )
1339- demo_pkg .extras = {
1340- canonicalize_name ("demo-extra-one" ): [get_dependency ("transitive-dep-one" )],
1341- canonicalize_name ("demo-extra-two" ): [get_dependency ("transitive-dep-two" )],
1342- }
1343- demo_pkg .add_dependency (
1344- Factory .create_dependency (
1345- "transitive-dep-one" , {"version" : "1.1.0" , "optional" : True }
1346- )
1237+ transitive_one_pkg = get_package ("transitive-dep-one" , "1.1.0" )
1238+ transitive_two_pkg = get_package ("transitive-dep-two" , "1.2.0" )
1239+
1240+ # Switch each transitive dependency based on extra markers in the 'demo' package
1241+ transitive_dep_one = Factory .create_dependency (
1242+ "transitive-dep-one" ,
1243+ {
1244+ "version" : "1.1.0" ,
1245+ "markers" : "extra == 'demo-extra-one' and extra != 'demo-extra-two'" ,
1246+ "optional" : True ,
1247+ }
13471248 )
1348- demo_pkg .add_dependency (
1349- Factory .create_dependency (
1350- "transitive-dep-two" , {"version" : "1.2.0" , "optional" : True }
1351- )
1249+ transitive_dep_two = Factory .create_dependency (
1250+ "transitive-dep-two" ,
1251+ {
1252+ "version" : "1.2.0" ,
1253+ "markers" : "extra != 'demo-extra-one' and extra == 'demo-extra-two'" ,
1254+ "optional" : True ,
1255+ }
13521256 )
1353- repo .add_package (demo_pkg )
1354- repo .add_package (transitive_dep_one )
1355- repo .add_package (transitive_dep_two )
1257+ # Include both packages in both demo extras, to validate that they're filtered out based on extra markers alone
1258+ demo_pkg .extras = {
1259+ canonicalize_name ("demo-extra-one" ): [get_dependency ("transitive-dep-one" ), get_dependency ("transitive-dep-two" )],
1260+ canonicalize_name ("demo-extra-two" ): [get_dependency ("transitive-dep-one" ), get_dependency ("transitive-dep-two" )],
1261+ }
1262+ demo_pkg .add_dependency (transitive_dep_one )
1263+ demo_pkg .add_dependency (transitive_dep_two )
13561264
1357- # 'demo' with extra 'one' when package has 'extra-one' extra and with extra 'two' when 'extra-two'
1265+ # Now define the demo dependency, similarly switched on extra markers in the root package
13581266 extra_one_dep = Factory .create_dependency (
13591267 "demo" ,
13601268 {
@@ -1373,12 +1281,16 @@ def test_run_with_different_dependency_extras(
13731281 )
13741282 package .add_dependency (extra_one_dep )
13751283 package .add_dependency (extra_two_dep )
1376- # We don't want to cheat by only including the correct dependency in the 'extra' mapping
1284+ # Again we don't want to cheat by only including the correct dependency in the 'extra' mapping
13771285 package .extras = {
13781286 canonicalize_name ("extra-one" ): [extra_one_dep , extra_two_dep ],
13791287 canonicalize_name ("extra-two" ): [extra_one_dep , extra_two_dep ],
13801288 }
13811289
1290+ repo .add_package (demo_pkg )
1291+ repo .add_package (transitive_one_pkg )
1292+ repo .add_package (transitive_two_pkg )
1293+
13821294 locker .locked (locked )
13831295 if locked :
13841296 locker .mock_lock_data (dict (fixture ("with-dependencies-differing-extras" )))
0 commit comments