Skip to content

Commit

Permalink
test error by switching order of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eviecarter33 committed Dec 13, 2024
1 parent f642a8b commit 8f1f94b
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions tests/testthat/test_gen_tibble_versioning.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

test_that("versioning if .bk already exists",{
test_that("versioning updates correctly through gt_order_loci",{
test_indiv_meta <- data.frame (id=c("a","b","c"),
population = c("pop1","pop1","pop2"))
test_genotypes <- rbind(c(1,1,0,1,1,0),
Expand All @@ -17,15 +16,8 @@ test_that("versioning if .bk already exists",{

# get the gt filenames
files <- gt_get_file_names(test_gt)
# remove the .rds
expect_true(file.remove(files[1]))

# remove extension
file <- gsub(".bk","",files[2])

# check the directory
tempfile_dir <- dirname(file)
expect_true(dir.exists(tempfile_dir))

# create gt using the same backingfile name
test_gt <- gen_tibble(x = test_genotypes, loci = test_loci,
indiv_meta = test_indiv_meta, quiet = TRUE,
Expand All @@ -34,25 +26,18 @@ test_that("versioning if .bk already exists",{
# get new file names
new_files <- gt_get_file_names(test_gt)

# new_files has the same name as original file, plus a version extension
expect_equal(new_files[2], paste0(file,"_v2.bk"))

# repeating the process creates another version
expect_true(file.remove(new_files[1]))
expect_false(file.exists(new_files[1]))
expect_true(file.exists(new_files[2]))

test_gt <- gen_tibble(x = test_genotypes, loci = test_loci,
indiv_meta = test_indiv_meta, quiet = TRUE,
backingfile = file)

new_version_files <- gt_get_file_names(test_gt)

expect_equal(new_version_files[2], paste0(file,"_v3.bk"))
# mess with the loci table
test_gt <- test_gt %>% select_loci(c(2,4,5,1,6))
test_gt <- gt_order_loci(test_gt, use_current_table = FALSE, quiet = TRUE)
gt_save(test_gt, quiet = TRUE)

# check file names
expect_equal(gt_get_file_names(test_gt)[1], paste0(file,"_v3.rds"))
expect_equal(gt_get_file_names(test_gt)[2], paste0(file,"_v3.bk"))
})

test_that("versioning updates correctly through gt_order_loci",{

test_that("versioning if .bk already exists",{
test_indiv_meta <- data.frame (id=c("a","b","c"),
population = c("pop1","pop1","pop2"))
test_genotypes <- rbind(c(1,1,0,1,1,0),
Expand All @@ -70,8 +55,15 @@ test_that("versioning updates correctly through gt_order_loci",{

# get the gt filenames
files <- gt_get_file_names(test_gt)
# remove extension
# remove the .rds
expect_true(file.remove(files[1]))

file <- gsub(".bk","",files[2])

# check the directory
tempfile_dir <- dirname(file)
expect_true(dir.exists(tempfile_dir))

# create gt using the same backingfile name
test_gt <- gen_tibble(x = test_genotypes, loci = test_loci,
indiv_meta = test_indiv_meta, quiet = TRUE,
Expand All @@ -80,13 +72,20 @@ test_that("versioning updates correctly through gt_order_loci",{
# get new file names
new_files <- gt_get_file_names(test_gt)

# mess with the loci table
test_gt <- test_gt %>% select_loci(c(2,4,5,1,6))
test_gt <- gt_order_loci(test_gt, use_current_table = FALSE, quiet = TRUE)
gt_save(test_gt, quiet = TRUE)
# new_files has the same name as original file, plus a version extension
expect_equal(new_files[2], paste0(file,"_v2.bk"))

# check file names
expect_equal(gt_get_file_names(test_gt)[1], paste0(file,"_v3.rds"))
expect_equal(gt_get_file_names(test_gt)[2], paste0(file,"_v3.bk"))
})
# repeating the process creates another version
expect_true(file.remove(new_files[1]))
expect_false(file.exists(new_files[1]))
expect_true(file.exists(new_files[2]))

test_gt <- gen_tibble(x = test_genotypes, loci = test_loci,
indiv_meta = test_indiv_meta, quiet = TRUE,
backingfile = file)

new_version_files <- gt_get_file_names(test_gt)

expect_equal(new_version_files[2], paste0(file,"_v3.bk"))

})

0 comments on commit 8f1f94b

Please sign in to comment.