Skip to content

Commit

Permalink
Adds two more tests, aligns var setting better, adds test reset helpe…
Browse files Browse the repository at this point in the history
…r function
  • Loading branch information
edgararuiz committed Jan 10, 2025
1 parent 0273f8f commit 59d72af
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
9 changes: 5 additions & 4 deletions R/py_require.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,20 @@ get_or_create_venv <- function(
# path to a requirements.txt
requirements <- c("--with-requirements", maybe_shQuote(requirements))
} else {
packages <- paste0("\"", requirements, "\"", collapse = ", ")
packages <- sprintf("# dependencies =[%s]", packages)
requirements <- paste0("\"", requirements, "\"", collapse = ", ")
packages <- sprintf("# dependencies =[%s]", requirements)
}
}

py_ver <- NULL
if (!is.null(python_version)) {
has_const <- substr(python_version, 1, 1) %in% c(">", "<", "=", "!")
python_version[!has_const] <- paste0("==", python_version[!has_const])
py_ver <- paste0(python_version, collapse = ",")
py_ver <- sprintf("# requires-python = \"%s\"", py_ver)
python_version <- paste0(python_version, collapse = ",")
py_ver <- sprintf("# requires-python = \"%s\"", python_version)
}

excl_newer <- NULL
if (!is.null(exclude_newer)) {
# todo, accept a POSIXct/lt, format correctly
excl_newer <- c("--exclude-newer", maybe_shQuote(exclude_newer))
Expand Down
34 changes: 33 additions & 1 deletion tests/testthat/_snaps/py_require.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Error in `get_or_create_venv()`:
! Python requirements could not be satisfied.
✖ Requirements:
Packages: tensorflow==2.18.*
Packages: "numpy", "tensorflow==2.18.*"
Python:
Exclude newer: 2024-10-20
✖ Output from 'uv':
Expand All @@ -20,3 +20,35 @@
tensorflow>=2.18.dev0), but pre-releases weren't enabled (try:
`--prerelease=allow`)

# Error requesting conflicting package versions

Code
get_or_create_venv()
Condition
Error in `get_or_create_venv()`:
! Python requirements could not be satisfied.
✖ Requirements:
Packages: "numpy", "pandas==2.2.3", "pandas==2.2.2"
Python:
Exclude newer:
✖ Output from 'uv':
Reading inline script metadata from `stdin`
× No solution found when resolving script dependencies:
╰─▶ Because you require pandas==2.2.3 and pandas==2.2.2, we can conclude
that your requirements are unsatisfiable.

# Error requesting conflicting Python versions

Code
get_or_create_venv()
Condition
Error in `get_or_create_venv()`:
! Python requirements could not be satisfied.
✖ Requirements:
Packages: "numpy"
Python: ==3.11,>=3.10
Exclude newer:
✖ Output from 'uv':
Reading inline script metadata from `stdin`
error: No interpreter found for Python >=3.10, ==3.11 in virtual environments or managed installations

3 changes: 3 additions & 0 deletions tests/testthat/helper-py-require.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_py_require_reset <- function() {
.globals$python_requirements <- NULL
}
17 changes: 17 additions & 0 deletions tests/testthat/test-py_require.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
test_that("Error requesting newer package version against an older snapshot", {
local_edition(3)
test_py_require_reset()
py_require("tensorflow==2.18.*", exclude_newer = "2024-10-20")
expect_snapshot(get_or_create_venv(), error = TRUE)
})

test_that("Error requesting conflicting package versions", {
local_edition(3)
test_py_require_reset()
py_require("pandas==2.2.3")
py_require("pandas==2.2.2")
expect_snapshot(get_or_create_venv(), error = TRUE)
})

test_that("Error requesting conflicting Python versions", {
local_edition(3)
test_py_require_reset()
py_require(python_version = ">=3.10")
py_require(python_version = "3.11")
expect_snapshot(get_or_create_venv(), error = TRUE)
})

0 comments on commit 59d72af

Please sign in to comment.