Skip to content

Commit

Permalink
Fixup pip_version_resolver specs (dependabot#7699)
Browse files Browse the repository at this point in the history
While working on the PR to drop support for Python 3.6, I noticed these specs could use some tidying up:
1. `3.7` will soon be dropped, so bumped the "latest" version to `3.11`.
2. We had no explicit test of what happens when an outdated Python version was specified.

Finally, the biggest change is removing the test of "old python version supported by Dependabot but not supported by a newer version of the library". The problem is that while nice to have the scenario it's testing is becoming less realistic.

Overall (and I say this as someone who helps maintain several popular Python open source libraries) the Python ecosystem has been aligning pretty closely to the upstream version support lifecycle. Ie, library maintainers are starting to align when they drop support for old python versions with the upstream EOL cycle.

Similarly, we're moving towards here in Dependabot.

So it's going to be really hard to find an example of a library that releases a new version dropping support for a Python version that isn't EOL'd... or if it is EOL'd, then most likely we've dropped support for that Python version here in Dependabot.

And even if I do manage to track down a library doing this, or mock a fake response from PyPI, it'll be a brittle test because every year we'll be dropping support for that old version.

So instead I think the test of "that is set to a python version no longer supported by Dependabot" is a more realistic test scenario.

I also tidied up some similar examples of this test to be consistent in
formatting... their contents didn't change.
  • Loading branch information
jeffwidman authored Aug 2, 2023
1 parent a2a8900 commit 3e39085
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,24 @@

context "with a .python-version file" do
let(:dependency_files) { [requirements_file, python_version_file] }
let(:python_version_content) { "3.7.0\n" }

let(:python_version_content) { "3.11.0\n" }
it { is_expected.to eq(Gem::Version.new("3.2.4")) }

context "that disallows the latest version" do
context "that is set to the oldest version of python supported by Dependabot" do
let(:python_version_content) { "3.5.3\n" }
it { is_expected.to eq(Gem::Version.new("2.2.24")) }
end

context "that is set to a python version no longer supported by Dependabot" do
let(:python_version_content) { "3.4.0\n" }
it "raises a helpful error" do
expect { subject }.to raise_error(Dependabot::DependencyFileNotResolvable) do |err|
expect(err.message).to start_with(
"Dependabot detected the following Python requirement for your project: '3.4.0'."
)
end
end
end
end
end

Expand All @@ -111,23 +121,25 @@

context "with a .python-version file" do
let(:dependency_files) { [requirements_file, python_version_file] }
let(:python_version_content) { "3.7.0\n" }
let(:python_version_content) { "3.11.0\n" }

it { is_expected.to eq(Gem::Version.new("2.1.1")) }

context "that disallows all fixed versions" do
context "that is set to the oldest version of python supported by Dependabot" do
let(:python_version_content) { "3.5.3\n" }
let(:dependency_version) { "3.0.0" }
let(:dependency_requirements) do
[{
file: "requirements.txt",
requirement: "==3.0.0",
groups: [],
source: nil
}]
end
it { is_expected.to eq(Gem::Version.new("2.1.1")) }
end

it { is_expected.to be_nil }
context "that is set to a python version no longer supported by Dependabot" do
let(:python_version_content) { "3.4.0\n" }

it "raises a helpful error" do
expect { subject }.to raise_error(Dependabot::DependencyFileNotResolvable) do |err|
expect(err.message).to start_with(
"Dependabot detected the following Python requirement for your project: '3.4.0'."
)
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,15 @@
end
end

context "that is unsupported" do
context "that is set to a python version no longer supported by Dependabot" do
let(:pipfile_fixture_name) { "required_python_unsupported" }

it "raises a helpful error" do
expect { subject }.
to raise_error(Dependabot::DependencyFileNotResolvable) do |error|
expect(error.message).
to start_with("Dependabot detected the following Python")
expect(error.message).to include("3.4.*")
expect(error.message).
to include(
"supported in Dependabot: 3.11.4, 3.11.3, 3.11.2, 3.11.1, 3.11.0, 3.10.12, 3.10.11, 3.10.10, 3.10.9"
)
end
expect { subject }.to raise_error(Dependabot::DependencyFileNotResolvable) do |err|
expect(err.message).to start_with(
"Dependabot detected the following Python requirement for your project: '3.4.*'."
)
end
end
end

Expand Down
5 changes: 2 additions & 3 deletions python/spec/dependabot/python/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@

context "that is set to a python version no longer supported by Dependabot" do
let(:python_version_content) { "3.4.0\n" }
it "raises a Dependabot::DependencyFileNotResolvable error" do
expect { checker.latest_resolvable_version }.
to raise_error(Dependabot::DependencyFileNotResolvable) do |err|
it "raises a helpful error" do
expect { subject }.to raise_error(Dependabot::DependencyFileNotResolvable) do |err|
expect(err.message).to start_with(
"Dependabot detected the following Python requirement for your project: '3.4.0'."
)
Expand Down

0 comments on commit 3e39085

Please sign in to comment.