From 4275b93867c78d20d0bd116749c1e7603cd9d473 Mon Sep 17 00:00:00 2001 From: Thomas Bock Date: Sun, 2 Apr 2023 21:51:09 +0200 Subject: [PATCH] Fix class of date attributes author-network test As of igraph version 1.4.0, the classes of edge attributes are respected in igraph. Therefore, dates in the expected outcomes of our tests need to be of class `POSIXct`. As the `I()` operator prevents an automatic conversion, we need to manually convert the dates to the correct class. However, as `I()` adds the `AsIs` class, we need to remove this class from the affected edge attributes again, as otherwise the expected network and the built network would not be equal. To make this test succeed in both, igraph versions < 1.4.0 and igraph versions >= 1.4.0, the expected class is derived from the class of the date attribute in the built network. This way, the test is able to pass independent of the used igraph version. This fix addresses se-sic#236. Signed-off-by: Christian Hechtl Signed-off-by: Thomas Bock --- tests/test-networks-author.R | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test-networks-author.R b/tests/test-networks-author.R index 2a62b127..613c1862 100644 --- a/tests/test-networks-author.R +++ b/tests/test-networks-author.R @@ -13,9 +13,11 @@ ## ## Copyright 2017, 2019 by Claus Hunsen ## Copyright 2017 by Christian Hechtl +## Copyright 2023 by Christian Hechtl ## Copyright 2017 by Felix Prasse ## Copyright 2018 by Barbara Eckl ## Copyright 2018 by Thomas Bock +## Copyright 2023 by Thomas Bock ## Copyright 2018 by Jakob Kronawitter ## Copyright 2018-2019 by Anselm Fehnker ## Copyright 2021 by Johannes Hostert @@ -421,12 +423,19 @@ test_that("Network construction of the undirected simplified author-cochange net kind = TYPE.AUTHOR, type = TYPE.AUTHOR) + ## make test independent of igraph version + date.attr = igraph::get.edge.attribute(network.built, "date") + date.conversion.function = ifelse(all(sapply(date.attr, lubridate::is.POSIXct)), + get.date.from.unix.timestamp, identity) + ## edge attributes data = data.frame( from = c("Björn", "Olaf", "Olaf", "Karl"), to = c("Olaf", "Karl", "Thomas", "Thomas"), - date = I(list(c(1468339139, 1468339245), c(1468339541, 1468339570), c(1468339541, 1468339592), - c(1468339570, 1468339592))), + date = I(list(date.conversion.function(c(1468339139, 1468339245)), + date.conversion.function(c(1468339541, 1468339570)), + date.conversion.function(c(1468339541, 1468339592)), + date.conversion.function(c(1468339570, 1468339592)))), artifact.type = I(list(c("Feature", "Feature"), c("Feature", "Feature"), c("Feature", "Feature"), c("Feature", "Feature"))), hash = I(list( @@ -442,6 +451,13 @@ test_that("Network construction of the undirected simplified author-cochange net relation = "cochange" ) + ## remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` + data[["date"]] = unclass(data[["date"]]) + data[["artifact.type"]] = unclass(data[["artifact.type"]]) + data[["hash"]] = unclass(data[["hash"]]) + data[["file"]] = unclass(data[["file"]]) + data[["artifact"]] = unclass(data[["artifact"]]) + ## build expected network network.expected = igraph::graph.data.frame(data, directed = FALSE, vertices = authors)