Permalink
Browse files

Sort hashes for requirements files

  • Loading branch information...
Callek committed May 7, 2018
1 parent e290143 commit 4d21d4891387b2ccef560ebfeaafb15cd7aec8a3
Showing with 24 additions and 1 deletion.
  1. +1 −1 pyup/requirements.py
  2. +23 −0 tests/test_requirements.py
@@ -493,7 +493,7 @@ def update_content(self, content, update_hashes=True):
)
hashes = []
if self.hashes and update_hashes:
for item in self.get_hashes(self.latest_version_within_specs):
for item in sorted(self.get_hashes(self.latest_version_within_specs), key=lambda x: x["hash"]):
hashes.append({"method": "sha256", "hash": item["hash"]})
return updater_class.update(
@@ -152,6 +152,29 @@ def test_update_with_hashes(self, get_hashes_mock, _):
" --hash=sha256:123 \\\n"
" --hash=sha256:456")
@patch("pyup.requirements.Requirement.package", return_value="pkg")
@patch("pyup.requirements.Requirement.get_hashes")
def test_update_with_hashes_sorted(self, get_hashes_mock, _):
get_hashes_mock.return_value = [{"hash": "abc"}, {"hash": "456"},
{"hash": "789"}, {"hash": "123"}]
with patch('pyup.requirements.Requirement.latest_version_within_specs',
new_callable=PropertyMock,
return_value="1.4.2"):
content = "alembic==0.8.9 \\\n" \
" --hash=sha256:abcde"
req_file = RequirementFile("req.txt", content)
req = list(req_file.requirements)[0]
self.assertEqual(
Requirement.parse("alembic==0.8.9", 1),
req
)
self.assertEqual(req.update_content(content), "alembic==1.4.2 \\\n"
" --hash=sha256:123 \\\n"
" --hash=sha256:456 \\\n"
" --hash=sha256:789 \\\n"
" --hash=sha256:abc")
@patch("pyup.requirements.Requirement.package", return_value="pkg")
@patch("pyup.requirements.Requirement.get_hashes")
def test_update_with_hashes_and_comment(self, get_hashes_mock, _):

0 comments on commit 4d21d48

Please sign in to comment.