@@ -106,20 +106,17 @@ def test_pipenv_dependency_incompatibility_resolution(pipenv_instance_pypi):
106
106
107
107
108
108
@pytest .mark .upgrade
109
- def test_upgrade_updates_package_in_all_categories (pipenv_instance_private_pypi ):
110
- """Test that upgrading a package updates it in all categories where it appears ."""
109
+ def test_upgrade_updates_lockfile_in_all_categories (pipenv_instance_private_pypi ):
110
+ """Test that upgrading a package updates it in all categories of the lockfile ."""
111
111
with pipenv_instance_private_pypi () as p :
112
- # Create a Pipfile with a package in multiple categories
112
+ # Create a Pipfile with a package in default and a dev package that depends on it
113
113
with open (p .pipfile_path , "w" ) as f :
114
114
contents = """
115
115
[packages]
116
- six = "==1.11 .0"
116
+ requests = "==2.25 .0"
117
117
118
118
[dev-packages]
119
- six = "==1.11.0"
120
-
121
- [custom-category]
122
- six = "==1.11.0"
119
+ pytest = "*"
123
120
""" .strip ()
124
121
f .write (contents )
125
122
@@ -132,24 +129,84 @@ def test_upgrade_updates_package_in_all_categories(pipenv_instance_private_pypi)
132
129
with open (lockfile_path ) as lockfile :
133
130
lock_data = json .load (lockfile )
134
131
135
- # Check initial versions in all categories
136
- assert lock_data ["default" ]["six" ]["version" ] == "==1.11.0"
137
- assert lock_data ["develop" ]["six" ]["version" ] == "==1.11.0"
132
+ # Check initial version in default section
133
+ assert lock_data ["default" ]["requests" ]["version" ] == "==2.25.0"
138
134
139
- # Get the lockfile section for the custom category
140
- custom_section = get_lockfile_section_using_pipfile_category ("custom-category" )
141
- assert lock_data [custom_section ]["six" ]["version" ] == "==1.11.0"
135
+ # Check if requests is in develop section (as a dependency of pytest)
136
+ # If it's there, note its initial version
137
+ develop_has_requests = "requests" in lock_data ["develop" ]
138
+ if develop_has_requests :
139
+ initial_dev_version = lock_data ["develop" ]["requests" ]["version" ]
142
140
143
141
# Upgrade the package
144
- target_version = "1.16 .0"
145
- c = p .pipenv (f"upgrade six =={ target_version } " )
146
- assert c .returncode == 0 , f"Failed to upgrade six : { c .stderr } "
142
+ target_version = "2.28 .0"
143
+ c = p .pipenv (f"upgrade requests =={ target_version } " )
144
+ assert c .returncode == 0 , f"Failed to upgrade requests : { c .stderr } "
147
145
148
- # Verify the package was updated in all categories
146
+ # Verify the package was updated in the lockfile
149
147
with open (lockfile_path ) as lockfile :
150
148
updated_lock_data = json .load (lockfile )
151
149
152
- # Check updated versions in all categories
153
- assert updated_lock_data ["default" ]["six" ]["version" ] == f"=={ target_version } "
154
- assert updated_lock_data ["develop" ]["six" ]["version" ] == f"=={ target_version } "
155
- assert updated_lock_data [custom_section ]["six" ]["version" ] == f"=={ target_version } "
150
+ # Check updated version in default section
151
+ assert updated_lock_data ["default" ]["requests" ]["version" ] == f"=={ target_version } "
152
+
153
+ # If requests was in develop section, check it was updated there too
154
+ if develop_has_requests :
155
+ assert updated_lock_data ["develop" ]["requests" ]["version" ] == f"=={ target_version } "
156
+
157
+
158
+ @pytest .mark .upgrade
159
+ def test_upgrade_only_adds_to_explicit_categories (pipenv_instance_private_pypi ):
160
+ """Test that upgrading a package only adds it to the Pipfile for explicitly requested categories."""
161
+ with pipenv_instance_private_pypi () as p :
162
+ # Create a Pipfile with a package in default but not in dev-packages
163
+ with open (p .pipfile_path , "w" ) as f :
164
+ contents = """
165
+ [packages]
166
+ requests = "==2.25.0"
167
+
168
+ [dev-packages]
169
+ pytest = "*"
170
+ """ .strip ()
171
+ f .write (contents )
172
+
173
+ # Lock the dependencies
174
+ c = p .pipenv ("lock" )
175
+ assert c .returncode == 0 , f"Failed to lock dependencies: { c .stderr } "
176
+
177
+ # Verify initial state
178
+ with open (p .pipfile_path ) as pipfile :
179
+ initial_pipfile_content = pipfile .read ()
180
+
181
+ # Make sure requests is not in dev-packages initially
182
+ assert "requests" not in initial_pipfile_content .split ("[dev-packages]" )[1 ].split ("[" )[0 ]
183
+
184
+ # Upgrade the package
185
+ target_version = "2.28.0"
186
+ c = p .pipenv (f"upgrade requests=={ target_version } " )
187
+ assert c .returncode == 0 , f"Failed to upgrade requests: { c .stderr } "
188
+
189
+ # Verify the Pipfile was updated correctly
190
+ with open (p .pipfile_path ) as pipfile :
191
+ updated_pipfile_content = pipfile .read ()
192
+
193
+ # Check that requests was updated in packages section
194
+ packages_section = updated_pipfile_content .split ("[packages]" )[1 ].split ("[" )[0 ]
195
+ assert f'requests = "=={ target_version } "' in packages_section
196
+
197
+ # Check that requests was NOT added to dev-packages section
198
+ dev_packages_section = updated_pipfile_content .split ("[dev-packages]" )[1 ].split ("[" )[0 ] if "[dev-packages]" in updated_pipfile_content else ""
199
+ assert "requests" not in dev_packages_section
200
+
201
+ # Verify the lockfile was updated in both sections
202
+ lockfile_path = os .path .join (p .path , "Pipfile.lock" )
203
+ with open (lockfile_path ) as lockfile :
204
+ updated_lock_data = json .load (lockfile )
205
+
206
+ # Check that requests was updated in default section
207
+ assert updated_lock_data ["default" ]["requests" ]["version" ] == f"=={ target_version } "
208
+
209
+ # Check if requests is in develop section (it might be there as a dependency of pytest)
210
+ if "requests" in updated_lock_data ["develop" ]:
211
+ # If it's there, it should be updated
212
+ assert updated_lock_data ["develop" ]["requests" ]["version" ] == f"=={ target_version } "
0 commit comments