aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2024-06-01 17:17:27 +0200
committerGitHub <noreply@github.com>2024-06-01 17:17:27 +0200
commit0950b15060067f752fde13a779a994f59516ce3d (patch)
treea3ca63d8db0b590e91427f4a6bbd8e421d1e5991 /tests/mason-core
parentci: upgrade deps (#1726) (diff)
downloadmason-0950b15060067f752fde13a779a994f59516ce3d.tar
mason-0950b15060067f752fde13a779a994f59516ce3d.tar.gz
mason-0950b15060067f752fde13a779a994f59516ce3d.tar.bz2
mason-0950b15060067f752fde13a779a994f59516ce3d.tar.lz
mason-0950b15060067f752fde13a779a994f59516ce3d.tar.xz
mason-0950b15060067f752fde13a779a994f59516ce3d.tar.zst
mason-0950b15060067f752fde13a779a994f59516ce3d.zip
feat(pypi): improve resolving suitable python version (#1725)
Diffstat (limited to 'tests/mason-core')
-rw-r--r--tests/mason-core/installer/managers/pypi_spec.lua109
-rw-r--r--tests/mason-core/installer/registry/providers/pypi_spec.lua1
-rw-r--r--tests/mason-core/pep440_spec.lua22
3 files changed, 130 insertions, 2 deletions
diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua
index df979fe9..a746ef08 100644
--- a/tests/mason-core/installer/managers/pypi_spec.lua
+++ b/tests/mason-core/installer/managers/pypi_spec.lua
@@ -2,6 +2,7 @@ local Result = require "mason-core.result"
local installer = require "mason-core.installer"
local match = require "luassert.match"
local path = require "mason-core.path"
+local providers = require "mason-core.providers"
local pypi = require "mason-core.installer.managers.pypi"
local spawn = require "mason-core.spawn"
local spy = require "luassert.spy"
@@ -26,9 +27,10 @@ describe("pypi manager", function()
it("should init venv without upgrading pip", function()
local ctx = create_dummy_context()
stub(ctx, "promote_cwd")
+ stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.failure()))
installer.exec_in_context(ctx, function()
- pypi.init { upgrade_pip = false }
+ pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = false }
end)
assert.spy(ctx.promote_cwd).was_called(1)
@@ -44,10 +46,15 @@ describe("pypi manager", function()
local ctx = create_dummy_context()
stub(ctx, "promote_cwd")
stub(ctx.fs, "file_exists")
+ stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.failure()))
ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true)
installer.exec_in_context(ctx, function()
- pypi.init { upgrade_pip = true, install_extra_args = { "--proxy", "http://localhost" } }
+ pypi.init {
+ package = { name = "cmake-language-server", version = "0.1.10" },
+ upgrade_pip = true,
+ install_extra_args = { "--proxy", "http://localhost" },
+ }
end)
assert.spy(ctx.promote_cwd).was_called(1)
@@ -69,6 +76,104 @@ describe("pypi manager", function()
}
end)
+ it("should find versioned candidates during init", function()
+ local ctx = create_dummy_context()
+ stub(ctx, "promote_cwd")
+ stub(ctx.fs, "file_exists")
+ stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.12"))
+ stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.12").returns(1)
+ stub(spawn, "python3.12")
+ spawn["python3.12"].on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.12.0" })
+ ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true)
+
+ installer.exec_in_context(ctx, function()
+ pypi.init {
+ package = { name = "cmake-language-server", version = "0.1.10" },
+ upgrade_pip = false,
+ install_extra_args = {},
+ }
+ end)
+
+ assert.spy(ctx.promote_cwd).was_called(1)
+ assert.spy(ctx.spawn["python3.12"]).was_called(1)
+ assert.spy(ctx.spawn["python3.12"]).was_called_with {
+ "-m",
+ "venv",
+ "venv",
+ }
+ end)
+
+ it("should error if unable to find a suitable python3 version", function()
+ local ctx = create_dummy_context()
+ spy.on(ctx.stdio_sink, "stderr")
+ stub(ctx, "promote_cwd")
+ stub(ctx.fs, "file_exists")
+ stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8"))
+ stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.12").returns(0)
+ vim.fn.executable.on_call_with("python3.11").returns(0)
+ vim.fn.executable.on_call_with("python3.10").returns(0)
+ vim.fn.executable.on_call_with("python3.9").returns(0)
+ vim.fn.executable.on_call_with("python3.8").returns(0)
+ stub(spawn, "python3", mockx.returns(Result.success()))
+ spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.5.0" })
+
+ local result = installer.exec_in_context(ctx, function()
+ return pypi.init {
+ package = { name = "cmake-language-server", version = "0.1.10" },
+ upgrade_pip = false,
+ install_extra_args = {},
+ }
+ end)
+
+ assert.same(
+ Result.failure "Failed to find a python3 installation in PATH that meets the required versions (>=3.8). Found version: 3.5.0.",
+ result
+ )
+ assert
+ .spy(ctx.stdio_sink.stderr)
+ .was_called_with "Run with :MasonInstall --force to bypass this version validation.\n"
+ end)
+
+ it(
+ "should default to stock version if unable to find suitable versioned candidate during init and when force=true",
+ function()
+ local ctx = create_dummy_context { force = true }
+ spy.on(ctx.stdio_sink, "stderr")
+ stub(ctx, "promote_cwd")
+ stub(ctx.fs, "file_exists")
+ stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8"))
+ stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.12").returns(0)
+ vim.fn.executable.on_call_with("python3.11").returns(0)
+ vim.fn.executable.on_call_with("python3.10").returns(0)
+ vim.fn.executable.on_call_with("python3.9").returns(0)
+ vim.fn.executable.on_call_with("python3.8").returns(0)
+ stub(spawn, "python3", mockx.returns(Result.success()))
+ spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.5.0" })
+
+ installer.exec_in_context(ctx, function()
+ pypi.init {
+ package = { name = "cmake-language-server", version = "0.1.10" },
+ upgrade_pip = true,
+ install_extra_args = { "--proxy", "http://localhost" },
+ }
+ end)
+
+ assert.spy(ctx.promote_cwd).was_called(1)
+ assert.spy(ctx.spawn.python3).was_called(1)
+ assert.spy(ctx.spawn.python3).was_called_with {
+ "-m",
+ "venv",
+ "venv",
+ }
+ assert
+ .spy(ctx.stdio_sink.stderr)
+ .was_called_with "Warning: The resolved python3 version 3.5.0 is not compatible with the required Python versions: >=3.8.\n"
+ end
+ )
+
it("should install", function()
local ctx = create_dummy_context()
stub(ctx.fs, "file_exists")
diff --git a/tests/mason-core/installer/registry/providers/pypi_spec.lua b/tests/mason-core/installer/registry/providers/pypi_spec.lua
index 5ba9609b..539ba53b 100644
--- a/tests/mason-core/installer/registry/providers/pypi_spec.lua
+++ b/tests/mason-core/installer/registry/providers/pypi_spec.lua
@@ -72,6 +72,7 @@ describe("pypi provider :: installing", function()
assert.is_true(result:is_success())
assert.spy(manager.init).was_called(1)
assert.spy(manager.init).was_called_with {
+ package = { name = "package", version = "1.5.0" },
upgrade_pip = true,
install_extra_args = { "--proxy", "http://localghost" },
}
diff --git a/tests/mason-core/pep440_spec.lua b/tests/mason-core/pep440_spec.lua
new file mode 100644
index 00000000..c8ff9880
--- /dev/null
+++ b/tests/mason-core/pep440_spec.lua
@@ -0,0 +1,22 @@
+local pep440 = require "mason-core.pep440"
+
+describe("pep440 version checking", function()
+ it("should check single version specifier", function()
+ assert.is_false(pep440.check_version("3.5.0", ">=3.6"))
+ assert.is_true(pep440.check_version("3.6.0", ">=3.6"))
+ assert.is_false(pep440.check_version("3.6.0", ">=3.6.1"))
+ end)
+
+ it("should check version specifier with lower and upper bound", function()
+ assert.is_true(pep440.check_version("3.8.0", ">=3.8,<3.12"))
+ assert.is_false(pep440.check_version("3.12.0", ">=3.8,<3.12"))
+ assert.is_true(pep440.check_version("3.12.0", ">=3.8,<4.0.0"))
+ end)
+
+ it("should check multiple specifiers with different constraints", function()
+ assert.is_false(pep440.check_version("3.5.0", "!=4.0,<=4.0,>=3.8"))
+ assert.is_false(pep440.check_version("4.0.0", "!=4.0,<=4.0,>=3.8"))
+ assert.is_true(pep440.check_version("3.8.1", "!=4.0,<=4.0,>=3.8"))
+ assert.is_true(pep440.check_version("3.12.0", "!=4.0,<=4.0,>=3.8"))
+ end)
+end)