Skip to content

test: Snapshot updates for rcc-smoke (null) #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions R/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,26 @@ graph.complementer <- function(graph, loops = FALSE) {
###################################################################

rename.attr.if.needed <- function(
type,
type = c("g", "v", "e"),
graphs,
newsize = NULL,
maps = NULL,
maps2 = NULL,
ignore = character()
) {
type <- igraph.match.arg(type)

listfun <- switch(
type,
"g" = graph_attr_names,
"v" = vertex_attr_names,
"e" = edge_attr_names,
stop("Internal igraph error")
"e" = edge_attr_names
)
getfun <- switch(
type,
"g" = graph_attr,
"v" = vertex_attr,
"e" = edge_attr,
stop("Internal igraph error")
"e" = edge_attr
)
alist <- lapply(graphs, listfun)
an <- unique(unlist(alist))
Expand Down Expand Up @@ -1176,7 +1176,7 @@ path <- function(...) {
## Adding named vertices
res <- add_vertices(e1, length(e2), name = e2)
} else {
cli::cli_abort("Cannot add {.obj_type_friendly type} to igraph graph.")
cli::cli_abort("Cannot add {.obj_type_friendly {type}} to igraph graph.")
}
res
}
Expand Down Expand Up @@ -1257,7 +1257,7 @@ path <- function(...) {
res <- delete_vertices(e1, e2)
} else {
cli::cli_abort(
"Cannot substract {.obj_type_friendly type} from igraph graph."
"Cannot substract {.obj_type_friendly {type}} from igraph graph."
)
}
res
Expand Down Expand Up @@ -1310,7 +1310,7 @@ rep.igraph <- function(x, n, mark = TRUE, ...) {
rep.igraph(x, n)
} else {
cli::cli_abort(
"Cannot multiply igraph graph with {.obj_type_friendly type}."
"Cannot multiply igraph graph with {.obj_type_friendly {type}}."
)
}
}
Expand Down
13 changes: 8 additions & 5 deletions R/plot.common.R
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,13 @@ i.parse.plot.params <- function(graph, params) {
}
}

func <- function(type, name, range = NULL, dontcall = FALSE) {
if (!type %in% names(p)) {
stop("Invalid plot option type")
}
func <- function(
type = c("vertex", "edge", "plot"),
name,
range = NULL,
dontcall = FALSE
) {
type <- igraph.match.arg(type)
ret <- function() {
v <- p[[type]][[name]]
if (is.function(v) && !dontcall) {
Expand Down Expand Up @@ -676,7 +679,7 @@ igraph.check.shapes <- function(x) {
bad.shapes <- !xx %in% ls(.igraph.shapes)
if (any(bad.shapes)) {
bs <- paste(xx[bad.shapes], collapse = ", ")
stop("Bad vertex shape(s): ", bs, ".")
cli::cli_abort("Bad vertex {cli::qty(length(bad.shapes))} shape{?s}: {bs}.")
}
x
}
Expand Down
7 changes: 5 additions & 2 deletions R/printr.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ head_print_callback <- function(
#' @export

indent_print <- function(..., .indent = " ", .printer = print) {
if (length(.indent) != 1) {
stop(".indent must be a scalar")
if (length(.indent) != 1 || !is.character(.indent)) {
indent <- .indent # cli literal cannot start with a dot
cli::cli_abort(
"{.arg .indent} must be a character scalar, not {.obj_type_friendly {indent}}."
)
}

opt <- options(width = getOption("width") - nchar(.indent))
Expand Down
10 changes: 8 additions & 2 deletions R/rewire.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
#' print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10)))
rewire <- function(graph, with) {
if (!is(with, "igraph_rewiring_method")) {
stop("'with' is not an igraph rewiring method")
cli::cli_abort(
"{.arg with} must be an igraph rewiring method,
not {.obj_type_friendly {with}}."
)
}
do_call(with$fun, list(graph), .args = with$args)
}
Expand Down Expand Up @@ -140,7 +143,10 @@ each_edge <- function(
multiple <- as.logical(multiple)
if (mode != 3) {
if (!multiple) {
stop("multiple = FALSE not supported when mode != \"all\"")
cli::cli_abort(
'{.code multiple = FALSE} is not supported
when {.code mode != "all"}'
)
}
method <- list(
fun = rewire_each_directed_edge,
Expand Down
17 changes: 14 additions & 3 deletions R/sgm.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
solve_LSAP <- function(x, maximum = FALSE) {
if (!is.matrix(x) || any(x < 0)) {
stop("x must be a matrix with nonnegative entries.")
if (!is.matrix(x)) {
cli::cli_abort("{.arg x} must be a matrix, not {.obj_type_friendly {x}}.")
}
if (any(x < 0)) {
cli::cli_abort(c(
"{.arg x} must not have negative entries.",
i = "It has {sum(x<0)} negative entr{?y/ies}."
))
}
nr <- nrow(x)
nc <- ncol(x)
if (nr > nc) {
stop("x must not have more rows than columns.")
cli::cli_abort(
c(
"{.arg x} must not have more rows than columns.",
i = "It has {nrow(x)} rows and {ncol(x)} columns."
)
)
}
if (nc > nr) {
x <- rbind(x, matrix(2 * sum(x), nc - nr, nc))
Expand Down
8 changes: 6 additions & 2 deletions R/stochastic_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ stochastic_matrix <- function(

column.wise <- as.logical(column.wise)
if (length(column.wise) != 1) {
stop("`column.wise' must be a logical scalar")
cli::cli_abort(
"{.arg column.wise} must be a logical scalar, not {.obj_type_friendly {column.wise}}."
)
}

sparse <- as.logical(sparse)
if (length(sparse) != 1) {
stop("`sparse' must be a logical scalar")
cli::cli_abort(
"{.arg sparse} must be a logical scalar, not {.obj_type_friendly {sparse}}."
)
}

on.exit(.Call(R_igraph_finalizer))
Expand Down
16 changes: 8 additions & 8 deletions R/versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ upgrade_graph <- function(graph) {
}

if (g_ver > p_ver) {
stop(
"Don't know how to downgrade graph from version ",
g_ver,
" to ",
p_ver
cli::cli_abort(
"Don't know how to downgrade graph from version {g_ver} to {p_ver}."
)
}

Expand All @@ -119,7 +116,9 @@ upgrade_graph <- function(graph) {

graph
} else {
stop("Don't know how to upgrade graph from version ", g_ver, " to ", p_ver)
cli::cli_abort(
"Don't know how to upgrade graph from version {g_ver} to {p_ver}."
)
}
}

Expand Down Expand Up @@ -157,8 +156,9 @@ warn_version <- function(graph) {
return(TRUE)
}

stop(
"This graph was created by a new(er) igraph version. Please install the latest version of igraph and try again."
cli::cli_abort(
"This graph was created by a newer igraph version.
Please install the latest version of igraph and try again."
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
upgrade_graph(g)
Condition
Error in `upgrade_graph()`:
! Don't know how to upgrade graph from version 0 to 4
! Don't know how to upgrade graph from version 0 to 4.

# we can't upgrade from 0.2 to 1.5.0, on the fly

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cliques.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ test_that("max_cliques() work", {
numeric()
}
if (any(duplicated(PX$PX))) {
stop("foo2")
cli::cli_abort("foo2")
}
}
pres
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ threshold.net <- function(graph, level) {

graphlets.old <- function(graph) {
if (!is_weighted(graph)) {
stop("Graph not weighted")
cli::cli_abort("Graph not weighted")
}
if (min(E(graph)$weight) <= 0 || any(!is.finite(E(graph)$weight))) {
stop("Edge weights must be non-negative and finite")
cli::cli_abort("Edge weights must be non-negative and finite")
}

## Do all thresholds
Expand Down Expand Up @@ -94,18 +94,18 @@ test_that("Graphlets work for a bigger graph", {

graphlets.project.old <- function(graph, cliques, iter, Mu = NULL) {
if (!is_weighted(graph)) {
stop("Graph not weighted")
cli::cli_abort("Graph not weighted")
}
if (min(E(graph)$weight) <= 0 || any(!is.finite(E(graph)$weight))) {
stop("Edge weights must be non-negative and finite")
cli::cli_abort("Edge weights must be non-negative and finite")
}
if (
length(iter) != 1 ||
!is.numeric(iter) ||
!is.finite(iter) ||
iter != as.integer(iter)
) {
stop("`iter' must be a non-negative finite integer scalar")
cli::cli_abort("`iter' must be a non-negative finite integer scalar")
}

clf <- cliques
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ test_that("BFS callback does not blow up when an invalid value is returned", {

test_that("BFS callback does not blow up when an error is raised within the callback", {
callback <- function(graph, data, extra) {
stop("test")
cli::cli_abort("test")
FALSE
}

Expand Down