From a4db2cbae10fc397005efeddbdf073c970b9d7b1 Mon Sep 17 00:00:00 2001 From: gothub Date: Wed, 30 Sep 2020 11:49:03 -0700 Subject: [PATCH] Update tests for testthat 3e compatibility (#125) --- inst/tests/test.ResourceMap.R | 7 +- inst/tests/test.SystemMetadata.R | 35 +++++----- inst/tests/test_DataObject.R | 54 +++++++-------- inst/tests/test_DataPackage.R | 114 +++++++++++++++---------------- 4 files changed, 102 insertions(+), 108 deletions(-) diff --git a/inst/tests/test.ResourceMap.R b/inst/tests/test.ResourceMap.R index 1994447..5a2ecef 100644 --- a/inst/tests/test.ResourceMap.R +++ b/inst/tests/test.ResourceMap.R @@ -1,4 +1,3 @@ -context("ResourceMap") test_that("datapack library loads", { expect_true(library(datapack, logical.return=TRUE)) }) @@ -48,20 +47,20 @@ test_that("ResourceMap creation from DataPackage triples", { relations <- getRelationships(dp) # Test if the data frame with retrieved relationships was constructed correctly - expect_that(nrow(relations), equals(7)) + expect_equal(nrow(relations), 7) expect_match(relations[relations$subject == mdId, 'predicate'], "documents") # Now initialize a ResourceMap with the relationships. resMapId <- sprintf("resourceMap:%s", UUIDgenerate()) resMap <- new("ResourceMap", id=resMapId) - expect_that(class(resMap)[[1]], equals("ResourceMap")) + expect_equal(class(resMap)[[1]], "ResourceMap") resMap <- createFromTriples(resMap, relations, getIdentifiers(dp)) # Serialize the ResourceMap to a file. filePath <- sprintf("%s/%s.rdf", tempdir(), resMapId) status <- serializeRDF(resMap, filePath) found <- grep("wasDerivedFrom", readLines(filePath)) - expect_that(length(found), is_more_than(0)) + expect_gt(length(found), 0) freeResourceMap(resMap) rm(resMap) diff --git a/inst/tests/test.SystemMetadata.R b/inst/tests/test.SystemMetadata.R index 4ebf946..088874a 100644 --- a/inst/tests/test.SystemMetadata.R +++ b/inst/tests/test.SystemMetadata.R @@ -1,29 +1,28 @@ -context("SystemMetadata") test_that("datapack library loads", { expect_true(library(datapack, logical.return = TRUE)) }) test_that("SystemMetadata constructors", { library(datapack) sysmeta <- new("SystemMetadata") - expect_that(sysmeta@serialVersion, equals(1)) + expect_equal(sysmeta@serialVersion, 1) expect_true(is.na(sysmeta@identifier)) sysmeta <- new("SystemMetadata", identifier="TestId", formatId="text/csv") - expect_that(sysmeta@identifier, equals("TestId")) - expect_that(sysmeta@formatId, equals("text/csv")) + expect_equal(sysmeta@identifier, "TestId") + expect_equal(sysmeta@formatId, "text/csv") }) test_that("XML SystemMetadata parsing works", { library(datapack) library(XML) testid <- "doi:10.xxyy/AA/tesdoc123456789" sysmeta <- new("SystemMetadata") - expect_that(sysmeta@serialVersion, equals(1)) + expect_equal(sysmeta@serialVersion, 1) doc <- xmlParseDoc("../testfiles/sysmeta.xml", asText=FALSE) expect_match(xmlValue(xmlRoot(doc)[["identifier"]]), testid) xml <- xmlRoot(doc) #getEncoding(doc) sysmeta <- parseSystemMetadata(sysmeta, xmlRoot(xml)) expect_match(sysmeta@identifier, testid) - expect_that(nrow(sysmeta@accessPolicy), equals(5)) + expect_equal(nrow(sysmeta@accessPolicy), 5) expect_match(as.character(sysmeta@accessPolicy$permission[[1]]), "read") expect_true(sysmeta@archived) csattrs <- xmlAttrs(xml[["checksum"]]) @@ -39,13 +38,13 @@ test_that("XML SystemMetadata parsing works", { # Parse v2.0 system metadata testid <- "0007f892-0d8f-4451-94e9-94d02ba5dd0d_0" sysmeta <- new("SystemMetadata") - expect_that(sysmeta@serialVersion, equals(1)) + expect_equal(sysmeta@serialVersion, 1) doc <- xmlParseDoc("../testfiles/sysmeta-v2.xml", asText=FALSE) expect_match(xmlValue(xmlRoot(doc)[["identifier"]]), testid) xml <- xmlRoot(doc) sysmeta <- parseSystemMetadata(sysmeta, xmlRoot(xml)) expect_match(sysmeta@identifier, testid) - expect_that(nrow(sysmeta@accessPolicy), equals(1)) + expect_equal(nrow(sysmeta@accessPolicy), 1) expect_match(as.character(sysmeta@accessPolicy$permission[[1]]), "read") expect_false(sysmeta@archived) csattrs <- xmlAttrs(xml[["checksum"]]) @@ -57,7 +56,7 @@ test_that("XML SystemMetadata parsing works", { # Parse v2.0 system metadata, checking parsing of replication policy testid <- "0007f892-0d8f-4451-94e9-94d02ba5dd0d_0" sysmeta <- new("SystemMetadata") - expect_that(sysmeta@serialVersion, equals(1)) + expect_equal(sysmeta@serialVersion, 1) doc <- xmlParseDoc("../testfiles/sysmeta-v2-repfalse.xml", asText=FALSE) expect_match(xmlValue(xmlRoot(doc)[["identifier"]]), testid) xml <- xmlRoot(doc) @@ -67,7 +66,7 @@ test_that("XML SystemMetadata parsing works", { # Parse v2.0 system metadata, checking parsing when missing numReplicas testid <- "arctic-data.9794.1" sysmeta <- new("SystemMetadata") - expect_that(sysmeta@serialVersion, equals(1)) + expect_equal(sysmeta@serialVersion, 1) doc <- xmlParseDoc("../testfiles/sysmeta-v2-repfalse-zero-reps.xml", asText=FALSE) expect_match(xmlValue(xmlRoot(doc)[["identifier"]]), testid) xml <- xmlRoot(doc) @@ -80,7 +79,7 @@ test_that("XML SystemMetadata serialization works", { library(XML) testid <- "doi:10.xxyy/AA/tesdoc123456789" sysmeta <- new("SystemMetadata") - expect_that(sysmeta@serialVersion, equals(1)) + expect_equal(sysmeta@serialVersion, 1) xml <- xmlParseDoc("../testfiles/sysmeta.xml", asText=FALSE) expect_match(xmlValue(xmlRoot(xml)[["identifier"]]), testid) sysmeta <- parseSystemMetadata(sysmeta, xmlRoot(xml)) @@ -124,7 +123,7 @@ test_that("SystemMetadata XML constructor works", { xml <- xmlRoot(doc) sysmeta <- SystemMetadata(xmlRoot(xml)) expect_match(sysmeta@identifier, testid) - expect_that(nrow(sysmeta@accessPolicy), equals(5)) + expect_equal(nrow(sysmeta@accessPolicy), 5) expect_match(as.character(sysmeta@accessPolicy$permission[[1]]), "read") expect_true(sysmeta@archived) csattrs <- xmlAttrs(xml[["checksum"]]) @@ -142,22 +141,22 @@ test_that("SystemMetadata validation works", { expect_true(isValid) sysmeta <- new("SystemMetadata", identifier="foo", checksum="jdhdjhfd", rightsHolder="ff") errors <- validate(sysmeta) - expect_that(length(errors), equals(2)) + expect_equal(length(errors), 2) }) test_that("SystemMetadata accessPolicy can be constructed and changed", { apolicy=data.frame(list("public", "read")) colnames(apolicy) <- c("subject", "permission") sysmeta <- new("SystemMetadata", identifier="foo", formatId="text/csv", size=59, checksum="jdhdjhfd", rightsHolder="ff", accessPolicy=apolicy) - expect_that(sysmeta@serialVersion, equals(1)) - expect_that(nrow(sysmeta@accessPolicy), equals(1)) + expect_equal(sysmeta@serialVersion, 1) + expect_equal(nrow(sysmeta@accessPolicy), 1) expect_match(as.character(sysmeta@accessPolicy$permission[[1]]), "read") sysmeta <- addAccessRule(sysmeta, "foo", "write") - expect_that(nrow(sysmeta@accessPolicy), equals(2)) + expect_equal(nrow(sysmeta@accessPolicy), 2) # Try to add same rule again and make sure it didn't get duplicated sysmeta <- addAccessRule(sysmeta, "foo", "write") - expect_that(nrow(sysmeta@accessPolicy), equals(2)) + expect_equal(nrow(sysmeta@accessPolicy), 2) expect_match(as.character(sysmeta@accessPolicy$permission[[2]]), "write") expect_true(hasAccessRule(sysmeta, "foo", "write")) apolicy=data.frame(subject=c("bar", "baz"), permission= c("changePermission", "write")) @@ -167,7 +166,7 @@ test_that("SystemMetadata accessPolicy can be constructed and changed", { expect_true(hasAccessRule(sysmeta, "bar", "changePermission")) expect_true(hasAccessRule(sysmeta, "baz", "write")) expect_true(!hasAccessRule(sysmeta, "baz", "changePermission")) - expect_that(nrow(sysmeta@accessPolicy), equals(4)) + expect_equal(nrow(sysmeta@accessPolicy), 4) expect_match(as.character(sysmeta@accessPolicy$permission[[4]]), "write") expect_match(as.character(sysmeta@accessPolicy$subject[[4]]), "baz") }) diff --git a/inst/tests/test_DataObject.R b/inst/tests/test_DataObject.R index 883915f..75be2a2 100644 --- a/inst/tests/test_DataObject.R +++ b/inst/tests/test_DataObject.R @@ -1,5 +1,3 @@ -context("DataObject") - test_that("datapack library loads", { expect_true(library(datapack, logical.return = TRUE)) }) @@ -15,27 +13,27 @@ test_that("DataObject constructors work", { # Test the constructor that builds a DataObject object do <- new("DataObject", identifier, data, filename="test.cvs", format=format, user=user, mnNodeId=node) - expect_that(class(do)[[1]], equals("DataObject")) - expect_that(do@sysmeta@serialVersion, equals(1)) - expect_that(do@sysmeta@identifier, equals(identifier)) - expect_that(do@sysmeta@submitter, equals(user)) - expect_that(do@sysmeta@size, equals(length(data))) - expect_that(length(do@data), equals(length(data))) - expect_that(getIdentifier(do), equals(identifier)) - expect_that(getFormatId(do), equals(format)) + expect_equal(class(do)[[1]], "DataObject") + expect_equal(do@sysmeta@serialVersion, 1) + expect_equal(do@sysmeta@identifier, identifier) + expect_equal(do@sysmeta@submitter, user) + expect_equal(do@sysmeta@size, length(data)) + expect_equal(length(do@data), length(data)) + expect_equal(getIdentifier(do), identifier) + expect_equal(getFormatId(do), format) sha1 <- digest(data, algo="sha1", serialize=FALSE, file=FALSE) sm <- new("SystemMetadata", identifier=identifier, formatId=format, size=length(data), submitter=user, rightsHolder=user, checksum=sha1, originMemberNode=node, authoritativeMemberNode=node) - expect_that(sm@identifier, equals(identifier)) + expect_equal(sm@identifier, identifier) # Now test the constructor that passes in SystemMetadata and data do <- new("DataObject", sm, data, filename="test.csv") - expect_that(do@sysmeta@serialVersion, equals(1)) - expect_that(do@sysmeta@identifier, equals(identifier)) - expect_that(do@sysmeta@submitter, equals(user)) - expect_that(do@sysmeta@size, equals(length(data))) - expect_that(length(do@data), equals(length(data))) - expect_that(getIdentifier(do), equals(identifier)) - expect_that(getFormatId(do), equals(format)) + expect_equal(do@sysmeta@serialVersion, 1) + expect_equal(do@sysmeta@identifier, identifier) + expect_equal(do@sysmeta@submitter, user) + expect_equal(do@sysmeta@size, length(data)) + expect_equal(length(do@data), length(data)) + expect_equal(getIdentifier(do), identifier) + expect_equal(getFormatId(do), format) # Now test the constructor that passes in SystemMetadata and a filename (not data) tf <- tempfile() @@ -44,13 +42,13 @@ test_that("DataObject constructors work", { close(con) sha1_file <- digest(tf, algo="sha1", serialize=FALSE, file=TRUE) do <- new("DataObject", sm, filename=tf) - expect_that(do@sysmeta@serialVersion, equals(1)) - expect_that(do@sysmeta@identifier, equals(identifier)) - expect_that(do@sysmeta@submitter, equals(user)) - expect_that(do@sysmeta@size, equals(length(data))) - expect_that(file.info(tf)$size, equals(length(data))) - expect_that(getIdentifier(do), equals(identifier)) - expect_that(getFormatId(do), equals(format)) + expect_equal(do@sysmeta@serialVersion, 1) + expect_equal(do@sysmeta@identifier, identifier) + expect_equal(do@sysmeta@submitter, user) + expect_equal(do@sysmeta@size, length(data)) + expect_equal(file.info(tf)$size, length(data)) + expect_equal(getIdentifier(do), identifier) + expect_equal(getFormatId(do), format) data2 <- getData(do) sha1_get_data <- digest(data2, algo="sha1", serialize=FALSE, file=FALSE) expect_match(sha1_get_data, sha1) @@ -59,11 +57,11 @@ test_that("DataObject constructors work", { # Test that the constructor works for a data path, with a few different forms targetPath="./data/rasters/test.csv" do <- new("DataObject", sm, data, filename="test.csv", targetPath=targetPath) - expect_that(do@targetPath, equals(targetPath)) + expect_equal(do@targetPath, targetPath) targetPath="data/rasters/test.csv" do <- new("DataObject", sm, data, filename="test.csv", targetPath=targetPath) - expect_that(do@targetPath, equals(targetPath)) + expect_equal(do@targetPath, targetPath) }) test_that("DataObject accessPolicy methods", { library(datapack) @@ -75,7 +73,7 @@ test_that("DataObject accessPolicy methods", { node <- "urn:node:KNB" do <- new("DataObject", identifier, data, format, user, node, filename="test.csv") - expect_that(class(do)[[1]], equals("DataObject")) + expect_equal(class(do)[[1]], "DataObject") # Public access should not be present at first canRead <- canRead(do, "uid=anybody,DC=somedomain,DC=org") diff --git a/inst/tests/test_DataPackage.R b/inst/tests/test_DataPackage.R index 6c7a36a..6da8593 100644 --- a/inst/tests/test_DataPackage.R +++ b/inst/tests/test_DataPackage.R @@ -1,5 +1,3 @@ -context("DataPackage") - test_that("datapack library loads", { expect_true(library(datapack, logical.return = TRUE)) }) @@ -33,16 +31,16 @@ test_that("datapack methods work", { node <- "urn:node:KNB" dpkg <- new("DataPackage") - expect_that(class(dpkg)[[1]], equals("DataPackage")) - expect_that(getSize(dpkg), equals(0)) + expect_equal(class(dpkg)[[1]], "DataPackage") + expect_equal(getSize(dpkg), 0) do <- new("DataObject", id1, data, format, user, node) dpkg <- addMember(dpkg, do) - expect_that(getSize(dpkg), equals(1)) - expect_that(getIdentifiers(dpkg)[[1]], equals(id1)) - expect_that(containsId(dpkg, id1), equals(TRUE)) - expect_that(containsId(dpkg, "bad_id"), equals(FALSE)) + expect_equal(getSize(dpkg), 1) + expect_equal(getIdentifiers(dpkg)[[1]], id1) + expect_true(containsId(dpkg, id1)) + expect_equal(containsId(dpkg, "bad_id"), FALSE) rdata <- getData(dpkg, id1) - expect_that(length(rdata), equals(length(data))) + expect_equal(length(rdata), length(data)) nodata <- getData(dpkg, "bad_id") expect_null(nodata) rdo <- getMember(dpkg, id1) @@ -50,12 +48,12 @@ test_that("datapack methods work", { expect_match(getIdentifier(do), id1) do2 <- new("DataObject", id2, data, format, user, node) dpkg <- addMember(dpkg, do2) - expect_that(getSize(dpkg), equals(2)) - expect_that(getIdentifiers(dpkg)[[1]], equals(id1)) - expect_that(getIdentifiers(dpkg)[[2]], equals(id2)) + expect_equal(getSize(dpkg), 2) + expect_equal(getIdentifiers(dpkg)[[1]], id1) + expect_equal(getIdentifiers(dpkg)[[2]], id2) removeMember(dpkg, id1) - expect_that(getSize(dpkg), equals(1)) - expect_that(containsId(dpkg, id1), equals(FALSE)) + expect_equal(getSize(dpkg), 1) + expect_false(containsId(dpkg, id1)) rm(do) rm(do2) rm(dpkg) @@ -83,17 +81,17 @@ test_that("datapack methods work", { #dpkg <- addMember(dpkg, md) do <- new("DataObject", id1, data, format, user, node) dpkg <- addMember(dpkg, do, md) - expect_that(getSize(dpkg), equals(2)) - expect_that(containsId(dpkg, id1), equals(TRUE)) - expect_that(containsId(dpkg, mdId), equals(TRUE)) + expect_equal(getSize(dpkg), 2) + expect_true(containsId(dpkg, id1)) + expect_true(containsId(dpkg, mdId)) # Test that the addMember() function adds the 'documents' relationship if a metadata object is # specified relations <- getRelationships(dpkg) expect_match(relations[relations$subject == id1, 'predicate'], "isDocumentedBy") - expect_that(relations[relations$subject == id1, 'object'], equals(mdId)) + expect_equal(relations[relations$subject == id1, 'object'], mdId) expect_match(relations[relations$subject == mdId, 'predicate'], "documents") - expect_that(relations[relations$subject == mdId, 'object'], equals(id1)) + expect_equal(relations[relations$subject == mdId, 'object'], id1) }) test_that("InsertRelationship methods work", { @@ -117,9 +115,9 @@ test_that("InsertRelationship methods work", { dp <- insertRelationship(dp, subjectID=mdId, objectIDs=c(doId1, doId2)) relations <- getRelationships(dp, quiet=quietOn) # Test if the data frame with relationships was constructed correctly - expect_that(nrow(relations), equals(4)) - expect_that(relations[relations$object == doId1, 'subject'], equals(mdId)) - expect_that(relations[relations$object == doId2, 'subject'], equals(mdId)) + expect_equal(nrow(relations), 4) + expect_equal(relations[relations$object == doId1, 'subject'], mdId) + expect_equal(relations[relations$object == doId2, 'subject'], mdId) expect_match(relations[relations$subject == mdId, 'predicate'], 'documents') expect_match(relations[relations$subject == doId1, 'predicate'], 'isDocumentedBy') rm(dp) @@ -147,56 +145,56 @@ test_that("InsertRelationship methods work", { dp <- insertRelationship(dp, subjectID=doId1, objectIDs=doId2, predicate="http://www.w3.org/ns/prov#wasDerivedFrom") # Test if the data frame with retrieved relationships was constructed correctly relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel)) + expect_equal(nrow(relations), nrel) expect_match(relations[relations$subject == doId1, 'predicate'], "wasDerivedFrom") - expect_that(relations[relations$subject == doId1, 'object'], equals(doId2)) - expect_that(relations[relations$subject == doId1, 'subjectType'], equals(as.character(NA))) - expect_that(relations[relations$subject == doId1, 'objectType'], equals(as.character(NA))) + expect_equal(relations[relations$subject == doId1, 'object'], doId2) + expect_equal(relations[relations$subject == doId1, 'subjectType'], as.character(NA)) + expect_equal(relations[relations$subject == doId1, 'objectType'], as.character(NA)) # Test assingment of subjectType, objectType dp <- insertRelationship(dp, subjectID="orcid.org/0000-0002-2192-403X", objectIDs="http://www.example.com/home", predicate="http://www.example.com/hadHome", subjectType="uri", objectType="literal") relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel <- nrel + 1)) + expect_equal(nrow(relations), nrel <- nrel + 1) expect_match(relations[relations$subject == "orcid.org/0000-0002-2192-403X", 'predicate'], "hadHome") expect_match(relations[relations$subject == "orcid.org/0000-0002-2192-403X", 'object'], "www.example.com/home") - expect_that(relations[relations$subject == "orcid.org/0000-0002-2192-403X", 'subjectType'], equals("uri")) - expect_that(relations[relations$subject == "orcid.org/0000-0002-2192-403X", 'objectType'], equals("literal")) + expect_equal(relations[relations$subject == "orcid.org/0000-0002-2192-403X", 'subjectType'], "uri") + expect_equal(relations[relations$subject == "orcid.org/0000-0002-2192-403X", 'objectType'], "literal") # Test that an unspecified objectType (where length(objetIDs) > length(objectTypes)) is set to as.character(NA) dp <- insertRelationship(dp, subjectID="urn:uuid:6186b15c-0a4b-4338-a091-1ea68d0fb72d", objectIDs=c("thing1", "thing2", "thing3"), predicate="http://www.myns.org/hadThing", subjectType="blank", objectTypes=c("literal", "literal")) relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel<-nrel + 3)) + expect_equal(nrow(relations), nrel<-nrel + 3) expect_match(relations[relations$object == "thing1", 'predicate'], "hadThing") expect_match(relations[relations$object == "thing1", 'subject'], "urn:uuid:6186b15c-0a4b-4338-a091-1ea68d0fb72d") - expect_that(relations[relations$object == "thing1", 'subjectType'], equals("blank")) - expect_that(relations[relations$object == "thing1", 'objectType'], equals("literal")) - expect_that(relations[relations$object == "thing2", 'subjectType'], equals("blank")) - expect_that(relations[relations$object == "thing2", 'objectType'], equals("literal")) - expect_that(relations[relations$object == "thing3", 'objectType'], equals(as.character(NA))) + expect_equal(relations[relations$object == "thing1", 'subjectType'], "blank") + expect_equal(relations[relations$object == "thing1", 'objectType'], "literal") + expect_equal(relations[relations$object == "thing2", 'subjectType'], "blank") + expect_equal(relations[relations$object == "thing2", 'objectType'], "literal") + expect_equal(relations[relations$object == "thing3", 'objectType'], as.character(NA)) # Multiple objectTypes, first one 'NA' dp <- insertRelationship(dp, subjectID="urn:uuid:ea00e863-861b-4253-9ed5-1c0568ee2373", objectIDs=c("thing4", "thing5"), predicate="http://www.myns.org/hadThing", subjectType="blank", objectTypes=c(NA, "literal")) relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel<-nrel + 2)) - expect_that(relations[relations$object == "thing4", 'objectType'], equals(as.character(NA))) - expect_that(relations[relations$object == "thing5", 'objectType'], equals("literal")) + expect_equal(nrow(relations), nrel<-nrel + 2) + expect_equal(relations[relations$object == "thing4", 'objectType'], as.character(NA)) + expect_equal(relations[relations$object == "thing5", 'objectType'], "literal") # Subject passed in as NA, which means create an "anonymous" blank node for these (software assigns the blank node id, not user) dp <- insertRelationship(dp, subjectID=as.character(NA), objectIDs="thing6", predicate="http://www.myns.org/wasThing", objectTypes="literal") relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel<-nrel + 1)) + expect_equal(nrow(relations), nrel<-nrel + 1) expect_match(relations[relations$object == "thing6", 'predicate'], "wasThing") - expect_that(relations[relations$object == "thing6", 'subjectType'], equals("blank")) + expect_equal(relations[relations$object == "thing6", 'subjectType'], "blank") # No objectID specified dp <- insertRelationship(dp, subjectID="urn:uuid:5743f16c-e038-4ef2-bcca-0418ff631a34", objectIDs=as.character(NA), predicate="http://www.myns.org/gaveThing") relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel <- nrel + 1)) + expect_equal(nrow(relations), nrel <- nrel + 1) expect_match(relations[relations$subject == "urn:uuid:5743f16c-e038-4ef2-bcca-0418ff631a34", 'predicate'], "gaveThing") - expect_that(relations[relations$subject == "urn:uuid:5743f16c-e038-4ef2-bcca-0418ff631a34", 'objectType'], equals("blank")) + expect_equal(relations[relations$subject == "urn:uuid:5743f16c-e038-4ef2-bcca-0418ff631a34", 'objectType'], "blank") # Specify dataTypeURIs dp <- insertRelationship(dp, subjectID="urn:uuid:abcd", objectIDs="Wed Mar 18 06:26:44 PDT 2015", @@ -204,10 +202,10 @@ test_that("InsertRelationship methods work", { objectTypes="literal", dataTypeURIs="http://www.w3.org/2001/XMLSchema#string") relations <- getRelationships(dp, quiet=quietOn) - expect_that(nrow(relations), equals(nrel <- nrel + 1)) + expect_equal(nrow(relations), nrel <- nrel + 1) expect_match(relations[relations$subject == "urn:uuid:abcd", 'dataTypeURI'], "string") - expect_that(relations[relations$subject == "urn:uuid:abcd", 'subjectType'], equals("uri")) - expect_that(relations[relations$subject == "urn:uuid:abcd", 'objectType'], equals("literal")) + expect_equal(relations[relations$subject == "urn:uuid:abcd", 'subjectType'], "uri") + expect_equal(relations[relations$subject == "urn:uuid:abcd", 'objectType'], "literal") expect_match(relations[relations$subject == "urn:uuid:abcd", 'predicate'], "startedAt") rm(dp) @@ -220,8 +218,8 @@ test_that("InsertRelationship methods work", { relations <- getRelationships(dp, quiet=quietOn) # Test if the data frame with retrieved relationships was constructed correctly - expect_that(nrow(relations), equals(3)) - expect_that(nrow(relations[relations$object == datapack:::provONEdata,]), equals(2)) + expect_equal(nrow(relations), 3) + expect_equal(nrow(relations[relations$object == datapack:::provONEdata,]), 2) expect_match(relations[relations$predicate == datapack:::provWasDerivedFrom, 'subject'], derived) expect_equal(relations[relations$predicate == datapack:::provWasDerivedFrom, 'object'], source) }) @@ -249,15 +247,15 @@ test_that("removeRelationships method works", { subjectType="uri", objectType="literal") # Now check if deleting various relationships results in the right number of rows - expect_that(nrow(getRelationships(dp)), equals(6)) + expect_equal(nrow(getRelationships(dp)), 6) dp <- removeRelationships(dp, predicate='http://myns.org/wasThing') - expect_that(nrow(getRelationships(dp)), equals(5)) + expect_equal(nrow(getRelationships(dp)), 5) dp <- removeRelationships(dp, subjectID='orcid.org/0000-0002-2192-403X') - expect_that(nrow(getRelationships(dp)), equals(4)) + expect_equal(nrow(getRelationships(dp)), 4) dp <- removeRelationships(dp, subjectID='https://myns.org/subject1', predicate='http://myns.org/hadThing') - expect_that(nrow(getRelationships(dp)), equals(2)) + expect_equal(nrow(getRelationships(dp)), 2) dp <- removeRelationships(dp) - expect_that(nrow(getRelationships(dp)), equals(0)) + expect_equal(nrow(getRelationships(dp)), 0) }) @@ -301,7 +299,7 @@ test_that("Package serialization works", { status <- serializePackage(dp, filePath, id=serializationId) expect_true(file.exists(filePath)) found <- grep("wasDerivedFrom", readLines(filePath)) - expect_that(found, is_more_than(0)) + expect_gt(found, 0) unlink(filePath) # Use R serialize/unserialize functions on entire datapackage @@ -345,7 +343,7 @@ test_that("Package serialization works with minimal DataPackage", { status <- serializePackage(dp, filePath, id=serializationId) expect_true(file.exists(filePath)) found <- grep(mdId, readLines(filePath)) - expect_that(found, is_more_than(0)) + expect_gt(found, 0) unlink(filePath) # Compare relationships rels <- getRelationships(dp) @@ -384,11 +382,11 @@ test_that("BagIt serialization works", { "' dp <- new("DataPackage") - mdId <- "scimetaId" + mdId <- "metadataId" doInId <- "scidataId" doOutId <- paste0("urn:uuid:", UUIDgenerate()) executionId <- "execution1" - + user <- "smith" data <- charToRaw("1,2,3\n4,5,6") doInFilePath = "myDir/textFile1.csv" @@ -589,8 +587,8 @@ test_that("Adding provenance relationships to a DataPackage via describeWorkflow relations <- getRelationships(dp, quiet=quietOn) # Test if the data frame with retrieved relationships was constructed correctly - expect_that(nrow(relations), equals(3)) - expect_that(nrow(relations[relations$object == datapack:::provONEdata,]), equals(2)) + expect_equal(nrow(relations), 3) + expect_equal(nrow(relations[relations$object == datapack:::provONEdata,]), 2) expect_equal(relations[relations$predicate == datapack:::provWasDerivedFrom, 'subject'], derived) expect_equal(relations[relations$predicate == datapack:::provWasDerivedFrom, 'object'], source) })