From e2d01ee6a177df4a51ba6bdae76fa40205dfc8ba Mon Sep 17 00:00:00 2001 From: Trevor L Davis Date: Tue, 19 Nov 2024 12:07:05 -0800 Subject: [PATCH] tests: Skip 'parse_known_intermixed_args()' tests on Debian on CRAN * Skips two `parse_known_intermixed_args()` tests on CRAN on Debian Testing to avoid raising an ERROR due to a bug in Debian Testing's version of python: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087681 closes #53 --- DESCRIPTION | 3 ++- R/utils.R | 12 ++++++++++++ cran-comments.md | 8 ++++++-- tests/testthat/test-argparse.R | 11 +++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 R/utils.R diff --git a/DESCRIPTION b/DESCRIPTION index c0d1cfd..70b0e1a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,8 @@ Depends: Imports: findpython, jsonlite, - R6 + R6, + utils SystemRequirements: python (>= 3.2) Suggests: knitr (>= 1.15.19), diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..2c7d1fd --- /dev/null +++ b/R/utils.R @@ -0,0 +1,12 @@ +# Based on code from Dirk Eddelbuettel +# https://fosstodon.org/@eddelbuettel@mastodon.social/113499555242268476 +get_linux_flavor <- function() { + flavor <- NA_character_ + osrel <- "/etc/os-release" + if (isTRUE(file.exists(osrel))) { # on (at least) Debian, Ubuntu, Fedora + x <- utils::read.table(osrel, sep = "=", row.names = 1L, + col.names = c("","Val"), header = FALSE) + flavor <- tolower(x["ID", "Val"]) + } + flavor +} diff --git a/cran-comments.md b/cran-comments.md index 0b17908..57376be 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,5 +1,9 @@ ## Notes +* Skips two `parse_known_intermixed_args()` tests on CRAN on Debian Testing + to avoid raising an ERROR due to a bug in Debian Testing's version of python: + https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087681 + * As in previous uploads while in a non-interactive session (i.e. in an Rscript) if ``parse_args()`` observes a help flag it will print a usage message and then call ``quit()``. Additionally if a user specifically adds @@ -12,7 +16,7 @@ ## Test environments -* local (linux), R 4.3.3 +* local (linux), R 4.4.2 * win-builder (windows), R devel * Github Actions (linux), R devel, release, oldrel * Github Actions (windows), R release @@ -24,7 +28,7 @@ Status: OK ## revdepcheck results -We checked 3 reverse dependencies (0 from CRAN + 3 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. +We checked 4 reverse dependencies (0 from CRAN + 4 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. * We saw 0 new problems * We failed to check 0 packages diff --git a/tests/testthat/test-argparse.R b/tests/testthat/test-argparse.R index e354433..e66f37a 100644 --- a/tests/testthat/test-argparse.R +++ b/tests/testthat/test-argparse.R @@ -169,7 +169,18 @@ test_that("parse_intermixed_args() works as expected", { expect_equal(args$cmd, 'doit') expect_equal(args$foo, 'bar') expect_equal(args$rest, 1:3) +}) +test_that("parse_known_intermixed_args() works as expected", { + skip_if_not(detects_python(minimum_version = '3.7')) + # Bug in Debian Testing's version of python causes CRAN ERROR + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087681 + if (isTRUE(get_linux_flavor() == "debian")) + skip_on_cran() + parser <- ArgumentParser() + parser$add_argument('--foo') + parser$add_argument('cmd') + parser$add_argument('rest', nargs='*', type='integer') args <- strsplit('doit 1 --foo bar 2 3 -n 4', ' ')[[1]] a_r <- parser$parse_known_intermixed_args(args) expect_equal(a_r[[1]]$cmd, 'doit')