Skip to content

Commit

Permalink
tests: Tweak 'parse_known_intermixed_args()' tests
Browse files Browse the repository at this point in the history
* Tweaks the `parse_known_intermixed_args()` tests so they work with the development version of Python.

closes #53
  • Loading branch information
trevorld committed Nov 27, 2024
1 parent 5d20b52 commit 79d3dfc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
comment = c(ORCID = "0000-0001-6341-4639")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
==============

Expand Down
12 changes: 0 additions & 12 deletions R/utils.R

This file was deleted.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 11 additions & 15 deletions tests/testthat/test-argparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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")
expect_equal(convert_argument(c(12.1, 14.9)), "(12.1, 14.9)")
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", ...)
Expand All @@ -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 = "+",
Expand Down Expand Up @@ -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")
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 79d3dfc

Please sign in to comment.