From 79d3dfc77c93c7d544977c5e85038648201dcd1e Mon Sep 17 00:00:00 2001 From: "Trevor L. Davis" Date: Wed, 27 Nov 2024 12:23:09 -0800 Subject: [PATCH] tests: Tweak 'parse_known_intermixed_args()' tests * Tweaks the `parse_known_intermixed_args()` tests so they work with the development version of Python. closes #53 --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ R/utils.R | 12 ------------ README.rst | 2 +- cran-comments.md | 4 ---- tests/testthat/test-argparse.R | 26 +++++++++++--------------- 6 files changed, 18 insertions(+), 33 deletions(-) delete mode 100644 R/utils.R diff --git a/DESCRIPTION b/DESCRIPTION index d2de259..0c8ec4b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: argparse Type: Package Title: Command Line Optional and Positional Argument Parser -Version: 2.2.4 +Version: 2.2.5-0 Authors@R: c(person("Trevor L.", "Davis", role=c("aut", "cre"), email="trevor.l.davis@gmail.com", comment = c(ORCID = "0000-0001-6341-4639")), diff --git a/NEWS.md b/NEWS.md index 6a1f247..61c5f6d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +argparse 2.2.5 +============== + +* Tweaks the `parse_known_intermixed_args()` tests so they work with the development version of Python. + argparse 2.2.4 ============== diff --git a/R/utils.R b/R/utils.R deleted file mode 100644 index 2c7d1fd..0000000 --- a/R/utils.R +++ /dev/null @@ -1,12 +0,0 @@ -# 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/README.rst b/README.rst index da384b8..ced0840 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ argparse: Command line optional and positional argument parser :target: https://cran.r-project.org/package=argparse :alt: CRAN Status Badge -.. image:: https://github.com/trevorld/r-argparse/workflows/R-CMD-check/badge.svg +.. image:: https://github.com/trevorld/r-argparse/actions/workflows/R-CMD-check.yaml/badge.svg?branch=master :target: https://github.com/trevorld/r-argparse/actions :alt: R-CMD-check diff --git a/cran-comments.md b/cran-comments.md index 57376be..2e7c9cb 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,9 +1,5 @@ ## 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 diff --git a/tests/testthat/test-argparse.R b/tests/testthat/test-argparse.R index e66f37a..b3043b9 100644 --- a/tests/testthat/test-argparse.R +++ b/tests/testthat/test-argparse.R @@ -38,7 +38,7 @@ test_that("print_help works as expected", { expect_error(capture.output(parser$parse_args("-h")), "help requested") }) -test_that("convert_argument works as expected", { +test_that("`convert_argument()` works as expected", { skip_if_not(detects_python()) expect_equal(convert_argument("foobar"), 'r"""foobar"""') expect_equal(convert_argument(14.9), "14.9") @@ -46,7 +46,7 @@ test_that("convert_argument works as expected", { expect_equal(convert_argument(c("a", "b")), '(r"""a""", r"""b""")') }) -test_that("convert_..._to_arguments works as expected", { +test_that("`convert_..._to_arguments()` works as expected", { skip_if_not(detects_python()) # test in mode "add_argument" c.2a <- function(...) convert_..._to_arguments("add_argument", ...) @@ -67,7 +67,7 @@ test_that("convert_..._to_arguments works as expected", { "formatter_class=argparse.ArgumentDefaultsHelpFormatter") }) -test_that("add_argument works as expected", { +test_that("`add_argument()` works as expected", { skip_if_not(detects_python()) parser <- ArgumentParser() parser$add_argument("integers", metavar = "N", type = "integer", nargs = "+", @@ -148,7 +148,7 @@ test_that("version flags works as expected", { expect_equal(length(el), 0) }) -test_that("parse_known_args() works as expected", { +test_that("`parse_known_args()` works as expected", { skip_if_not(detects_python()) parser <- ArgumentParser() parser$add_argument("-o", "--output_filename", default = "outfile.txt") @@ -158,7 +158,7 @@ test_that("parse_known_args() works as expected", { }) -test_that("parse_intermixed_args() works as expected", { +test_that("`parse_intermixed_args()` works as expected", { skip_if_not(detects_python(minimum_version = '3.7')) parser <- ArgumentParser() parser$add_argument('--foo') @@ -171,25 +171,21 @@ test_that("parse_intermixed_args() works as expected", { expect_equal(args$rest, 1:3) }) -test_that("parse_known_intermixed_args() works as expected", { +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]] + args <- strsplit('doit 1 --foo bar 2 3 -n', ' ')[[1]] a_r <- parser$parse_known_intermixed_args(args) expect_equal(a_r[[1]]$cmd, 'doit') expect_equal(a_r[[1]]$foo, 'bar') expect_equal(a_r[[1]]$rest, 1:3) - expect_equal(a_r[[2]], c('-n', '4')) + expect_equal(a_r[[2]], c('-n')) }) -test_that("set_defaults() works as expected", { +test_that("`set_defaults()` works as expected", { skip_if_not(detects_python()) parser <- ArgumentParser() parser$set_defaults(bar=42) @@ -199,7 +195,7 @@ test_that("set_defaults() works as expected", { # expect_equal(parser$get_default("bar"), 42) }) -test_that("ArgumentParser works as expected", { +test_that("`ArgumentParser()` works as expected", { skip_if_not(detects_python()) parser <- ArgumentParser(prog = "foobar", usage = "%(prog)s arg1 arg2") parser$add_argument("--hello", dest = "saying", action = "store_const", @@ -215,7 +211,7 @@ test_that("ArgumentParser works as expected", { expect_error(ArgumentParser(add_help = FALSE)$parse_args("-h"), "unrecognized arguments") }) -test_that("parse_args() works as expected", { +test_that("`parse_args()` works as expected", { skip_if_not(detects_python()) parser <- ArgumentParser("foobar", usage = "%(prog)s arg1 arg2") parser$add_argument("--hello", dest = "saying", action = "store", default = "foo",