Skip to content

Commit

Permalink
set locale in helpers.R to ensure the consistent string order in test…
Browse files Browse the repository at this point in the history
… cases across different machines (especially when test_results.rds is updated)
  • Loading branch information
mikejiang committed Jul 21, 2020
1 parent dae9275 commit 4062928
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# saveRDS(test_results_all, "tests/testthat/test_results.rds")
# test_results_all <- readRDS("tests/testthat/test_results.rds")
test_results_all <- readRDS("test_results.rds")
Sys.setlocale("LC_COLLATE", "C")#ensure the consistent string order across different machines (especially when test_results.rds is updated by someone)
25 changes: 9 additions & 16 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@ test_that("cf_get_panel", {


test_that("keywords insertion", {
locale <- Sys.getlocale("LC_COLLATE")
Sys.setlocale("LC_COLLATE", "en_US.UTF-8")#so that the character ordering is the same as the interactive console

test_results_keys <- test_results[["keywords"]]
check_res <- cqc_check_keyword(cqc_data)
expect_is(check_res, "cqc_check_keyword")

#sort strings because devtool::test() run yields different order from the interactive session
# check_res$keyword <- sort(check_res$keyword)
# test_results_keys[["check"]][["result"]]$keyword <- sort(test_results_keys[["check"]][["result"]]$keyword)
expect_equivalent(check_res, test_results_keys[["check"]][["result"]])

match_result <- cqc_match(check_res, ref = 3)
Expand All @@ -54,7 +48,6 @@ test_that("keywords insertion", {
cqc_fix(match_result)
expect_equivalent(cqc_check(cqc_data, "keyword"), test_results_keys[["check"]][["fixed_result"]])

Sys.setlocale("LC_COLLATE", locale)#restore
})
test_that("cqc_check_gate", {
test_results_gate <- test_results[["gate"]]
Expand Down Expand Up @@ -139,7 +132,7 @@ test_that("cqc_check_panel", {
match_res <- cqc_match(groups, ref = 1)
cqc_fix(match_res)
groups <- cqc_check(cqc_data, "panel")

# Panel check still shows non-overlapping scatter channels (handled in next test block)
expect_equivalent(groups, test_results_panel[["check"]][["fixed_result"]])
groups <- cqc_check(cqc_data, "channel")
Expand All @@ -166,11 +159,11 @@ test_that("cqc_check_channel", {
})

test_that("missing_markers", {

skip_if_not(require(flowWorkspaceData))

test_results_missing <- test_results[["missing_markers"]]

# Construct case with missing markers to be filled in by panel check aligned on channels
cs <- load_cytoset_from_fcs(list.files(system.file("extdata", package = "flowWorkspaceData"), pattern = "a2004", full.names = TRUE))
drop_cols <- which(grepl("-A", colnames(cs)))
Expand All @@ -179,21 +172,21 @@ test_that("missing_markers", {
names(empty_markers) <- colnames(cs)[5:12]
markernames(cs[[2]]) <- empty_markers
cqc_data <- cqc_cf_list(cytoset_to_list(cs))

# Test error message for case where no samples have values to match up
# This could happen if the user chooses the wrong ref in the example below
expect_error(cqc_check(cqc_cf_list(cytoset_to_list(cs[2])), type = "panel", by = "channel"), "No markers available for panel check")

# Check should show 2 groups due to missing markers
check_res <- cqc_check(cqc_data, type = "panel", by = "channel")
expect_equivalent(check_res, test_results_missing[["pre_check"]])

# Match to the sample with channels present and apply fix
match_res <- cqc_match(check_res, ref = 1)
expect_equivalent(match_res, test_results_missing[["match"]])

cqc_fix(match_res)

check_res <- cqc_check(cqc_data, type = "panel", by = "channel")
expect_equivalent(check_res, test_results_missing[["post_fix_check"]])
})
Binary file modified tests/testthat/test_results.rds
Binary file not shown.

0 comments on commit 4062928

Please sign in to comment.