Skip to content

Commit

Permalink
fix expect_error warning about the error class
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejiang committed Dec 10, 2019
1 parent 719ca7d commit de1b072
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
24 changes: 12 additions & 12 deletions tests/testthat/GatingHierarchy-testSuite.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ test_that(".isCompensated",
test_that("getNodeInd ",{

#invalid numeric indexing
expect_error(flowWorkspace:::.getNodeInd(gh, 2), "string")
expect_error(flowWorkspace:::.getNodeInd(gh, 2), "string", class = "Rcpp::not_compatible")

#invalid node name
expect_error(flowWorkspace:::.getNodeInd(gh, "singlet"), "singlet not found")
expect_error(flowWorkspace:::.getNodeInd(gh, "singlet"), "singlet not found", class = "std::domain_error")

#valid unique node name
expect_equal(flowWorkspace:::.getNodeInd(gh, "singlets"), 3)
Expand All @@ -29,10 +29,10 @@ test_that("getNodeInd ",{
expect_equal(flowWorkspace:::.getNodeInd(gh, "CD8/38- DR+"), 15)

#non-unqiue partial path
expect_error(flowWorkspace:::.getNodeInd(gh, "/38- DR+"), "not found")
expect_error(flowWorkspace:::.getNodeInd(gh, "/38- DR+"), "not found", class = "std::domain_error")

#non-unique node name indexing
expect_error(flowWorkspace:::.getNodeInd(gh, "38- DR+"), "is ambiguous within the gating tree")
expect_error(flowWorkspace:::.getNodeInd(gh, "38- DR+"), "is ambiguous within the gating tree", class = "std::domain_error")

#dealing with root
expect_equal(flowWorkspace:::.getNodeInd(gh, "/not debris"), 2)
Expand Down Expand Up @@ -214,9 +214,9 @@ test_that("gs_pop_get_parent",{

expect_equal(gs_pop_get_parent(gh, "not debris/singlets"), "/not debris")

expect_error(gs_pop_get_parent(gh, "singlet"), "singlet not found")
expect_error(gs_pop_get_parent(gh, "singlet"), "singlet not found", class = "std::domain_error")

expect_error(gs_pop_get_parent(gh, "root"), "0 :parent not found!")
expect_error(gs_pop_get_parent(gh, "root"), "0 :parent not found!", class = "std::domain_error")

})

Expand All @@ -228,9 +228,9 @@ test_that("gs_pop_get_children",{
expect_equal(gs_pop_get_children(gh, "singlets"), "/not debris/singlets/CD3+")


expect_error(gs_pop_get_children(gh, "singlet"), "singlet not found")
expect_error(gs_pop_get_children(gh, "singlet"), "singlet not found", class = "std::domain_error")

expect_error(gs_pop_get_children(gh, "38- DR+"), "ambiguous")
expect_error(gs_pop_get_children(gh, "38- DR+"), "ambiguous", class = "std::domain_error")

expect_equal(gs_pop_get_children(gh, "CD4/38- DR+"), character(0))

Expand All @@ -244,9 +244,9 @@ test_that("gs_pop_get_children",{

test_that(".getPopStat",{

expect_error(flowWorkspace:::.getPopStat(gh, 3), "string")
expect_error(flowWorkspace:::.getPopStat(gh, 3), "string", class = "Rcpp::not_compatible")

expect_error(flowWorkspace:::.getPopStat(gh, "singlet"), "not found")
expect_error(flowWorkspace:::.getPopStat(gh, "singlet"), "not found", class = "std::domain_error")

expect_equal(flowWorkspace:::.getPopStat(gh, "singlets"), list(openCyto = c(percent = 9.487789e-01, count = 8.702200e+04)
, xml = c(percent = 9.488988e-01, count = 8.703300e+04)
Expand All @@ -270,7 +270,7 @@ test_that("gh_pop_get_proportion",{

expect_equal(gh_pop_get_proportion(gh, "singlets", xml = TRUE), 0.9488988, tol = 1e-7)

expect_error(gh_pop_get_proportion(gh, "singlet"), "singlet not found")
expect_error(gh_pop_get_proportion(gh, "singlet"), "singlet not found", class = "std::domain_error")
})

test_that("gh_pop_get_count",{
Expand All @@ -281,7 +281,7 @@ test_that("gh_pop_get_count",{

expect_equal(gh_pop_get_stats(gh, "singlets", xml = TRUE)[[2]], 87033)

expect_error(gh_pop_get_stats(gh, "singlet"), "singlet not found")
expect_error(gh_pop_get_stats(gh, "singlet"), "singlet not found", class = "std::domain_error")
})


Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/GatingSetList-testSuite.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("GatingSetList constructor", {
#different colnames
chnnls <- colnames(gs_cyto_data(gs_clone))
chnnls[1] <- "FSC-H"
expect_error(colnames(gs_cyto_data(gs_clone)) <- chnnls, "already")
expect_error(colnames(gs_cyto_data(gs_clone)) <- chnnls, "already", class = "std::domain_error")
chnnls[1] <- "F"
colnames(gs_cyto_data(gs_clone)) <- chnnls
expect_error(GatingSetList(list(gs, gs_clone)), "colnames of flowSets don't match")
Expand Down Expand Up @@ -181,7 +181,7 @@ test_that("save_gslist /load_gslist", {
expect_true(setequal(list.files(tmp), expectRes))

# can't cp the h5 file to the dest tmp since it is already present
expect_error(save_gslist(gslist, tmp), regexp = "File exists")
expect_error(save_gslist(gslist, tmp), regexp = "File exists", class = "boost::filesystem::filesystem_error")
# set cdf flag to skip h5
expect_message(save_gslist(gslist, tmp, cdf = "skip"), regexp = "Done")
expect_true(setequal(list.files(tmp), expectRes))
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/cytoframe-suite.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test_that("write permission", {
rm(cf1)
invisible(gc())
cf2 <- load_cytoframe_from_h5(h5file)
expect_error(exprs(cf2)[1,1] <- 2, "read-only")
expect_error(exprs(cf2)[1,1] <- 2, "read-only", class = "std::domain_error")
cf_unlock(cf2)
exprs(cf2)[1,1] <- 2
expect_equivalent(exprs(cf2)[1,1], 2)
Expand All @@ -87,8 +87,8 @@ test_that("lock", {
expect_equivalent(exprs(cf1)[1,1], 3)
#lock it
cf_lock(cf1)
expect_error(exprs(cf1)[1,1] <- 4, "read-only")
expect_error(keyword(cf1)[["TUBE NAME"]] <- "dd", "read-only")
expect_error(exprs(cf1)[1,1] <- 4, "read-only", class = "std::domain_error")
expect_error(keyword(cf1)[["TUBE NAME"]] <- "dd", "read-only", class = "std::domain_error")
expect_equivalent(exprs(cf1)[1,1], 3)
cf_unlock(cf1)
exprs(cf1)[1,1] <- 4
Expand Down Expand Up @@ -134,8 +134,8 @@ test_that("exprs<-", {
expect_true(all(exprs(cf1)[1:10, 1:10] == 0))
expect_false(all(exprs(cf)[1:10, 1:10] == 0))

expect_error(exprs(cf1) <- exprs(cf1)[1:10, ] , "size")
expect_error(exprs(cf1) <- exprs(cf1)[, 1:2] , "size")
expect_error(exprs(cf1) <- exprs(cf1)[1:10, ] , "size", class = "std::domain_error")
expect_error(exprs(cf1) <- exprs(cf1)[, 1:2] , "size", class = "std::domain_error")

})

Expand Down Expand Up @@ -169,7 +169,7 @@ test_that("colnames<-", {
#TODO:change the order of colnames
coln <- colnames(cf1)
cf2 <- cf1[, coln[2:1]]
expect_error(colnames(cf2) <- newColNames, "colname already exists")
expect_error(colnames(cf2) <- newColNames, "colname already exists", class = "std::domain_error")
cf_swap_colnames(cf2, "c1", "c2")
expect_equivalent(unlist(keyword(cf2)[c("$P1N", "$P2N")]), rev(newColNames))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-add.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ test_that("add factor vector", {
expect_equal(gh_pop_get_count(gs[[1]], "clusterA_Q5"),0)

expect_error(gs_pop_add(gs, fac.list, parent = "rectangle", name = "clusterA")
, "exist")
, "exist", class = "std::domain_error")

#retrieve clustering results
expect_error(gh_get_cluster_labels(gs[[1]], "rectangle", "cluster"), "No clustering results")
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("save GatingSet to archive",
expect_that(gs, is_a("GatingSet"))
expect_setequal(colnames(pData(gs)), colnames(pd))
expect_message(save_gs(gs, path = tmp), "Done")
expect_error(save_gs(gs[1], path = tmp), "doesn't match")
expect_error(save_gs(gs[1], path = tmp), "doesn't match", class = "std::domain_error")

cdf <- list.files(tmp, ".h5", full.names = TRUE)
expect_equal(identifier(gs), id)
Expand All @@ -33,10 +33,10 @@ test_that("save GatingSet to archive",
#restore id
identifier(gs) <- id
file.copy(cdf, file.path(tmp, "redundant.nc"))
expect_error(save_gs(gs, path = tmp), "Not a valid")
expect_error(save_gs(gs, path = tmp), "Not a valid", class = "std::domain_error")

expect_error(colnames(gs_cyto_data(gs))[1] <- "dd" , "read-only")
expect_error(exprs(get_cytoframe_from_cs(gs_cyto_data(gs), 1))[1,1] <- 0, "read-only")
expect_error(colnames(gs_cyto_data(gs))[1] <- "dd" , "read-only", class = "std::domain_error")
expect_error(exprs(get_cytoframe_from_cs(gs_cyto_data(gs), 1))[1,1] <- 0, "read-only", class = "std::domain_error")

})
## it is placed here because trans may get cleared later on by cloning process
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-compensate.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ test_that("compensate & transform a GatingSet", {

# unmatched names
names(comp)[1] <- "dd"
expect_error(compensate(gs, comp), regexp = "compensation not found")
expect_error(compensate(gs, comp), regexp = "compensation not found", class = "std::domain_error")

#unmatched length
comp <- comp[1:3]
expect_error(compensate(gs, comp), regexp = "compensation not found ")
expect_error(compensate(gs, comp), regexp = "compensation not found ", class = "std::domain_error")

#modify comp[5]
comp <- sapply(sampleNames(gs), function(sn)comp.mat, simplify = FALSE)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-cytoset.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ test_that("sampleNames<-", {
is_equal_flowFrame(cs[sn][[1]], nc[[1]])

newNames <- c("s2", "s2")
expect_error(sampleNames(nc) <- newNames, "exists")
expect_error(sampleNames(nc) <- newNames, "exists", class = "std::range_error")

#replace the single subsetted fs
nc <- nc["s2"]
Expand Down Expand Up @@ -203,7 +203,7 @@ test_that("colnames<-", {
colnames(nc) <- newColNames
newColNames <- rev(newColNames)
expect_equivalent(unlist(keyword(nc[[1]])[c("$P1N", "$P2N")]), newColNames)
expect_error(colnames(nc) <- newColNames, "colname already exists")
expect_error(colnames(nc) <- newColNames, "colname already exists", class = "std::domain_error")
cs_swap_colnames(nc, "c1", "c2")
expect_equal(colnames(nc), newColNames)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-moveNode.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ test_that("gh_pop_move", {
old.parent <- gs_pop_get_parent(gh, "CD4")

new.parent <- "CD4"
expect_error(gh_pop_move(gh, "CD4", new.parent), "itself")
expect_error(gh_pop_move(gh, "CD4", new.parent), "itself", class = "std::domain_error")

new.parent <- "CD4/CCR7- 45RA+"
expect_error(gh_pop_move(gh, "CD4", new.parent), "descendants")
expect_error(gh_pop_move(gh, "CD4", new.parent), "descendants", class = "std::domain_error")

new.parent <- "singlets"
suppressMessages(gh_pop_move(gh, "CD4", new.parent))
Expand Down

0 comments on commit de1b072

Please sign in to comment.