From 4ffc22e65cd885aab18beae0b96cd4e90fd1177f Mon Sep 17 00:00:00 2001 From: eviecarter33 Date: Thu, 17 Oct 2024 08:41:53 +0100 Subject: [PATCH] change duplicated file function and test (CI issue) --- R/gen_tibble.R | 4 ++-- tests/testthat/test_gen_tibble.R | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/R/gen_tibble.R b/R/gen_tibble.R index c0576160..b7efe37b 100644 --- a/R/gen_tibble.R +++ b/R/gen_tibble.R @@ -510,7 +510,7 @@ change_duplicated_file_name <- function(file){ if(file.exists(bk) && !file.exists(rds)){ - version <- 1 + version <- 2 base_name <- basename(file) @@ -533,7 +533,7 @@ change_duplicated_file_name <- function(file){ return(new_file) } else if (file.exists(bk) && file.exists(rds)){ - version <- 1 + version <- 2 base_name <- basename(file) diff --git a/tests/testthat/test_gen_tibble.R b/tests/testthat/test_gen_tibble.R index 58fb40bc..1f505312 100644 --- a/tests/testthat/test_gen_tibble.R +++ b/tests/testthat/test_gen_tibble.R @@ -436,24 +436,29 @@ test_gt <- gen_tibble(x = test_genotypes, loci = test_loci, test_that("versioning if .bk already exists",{ + # get the gt filenames files <- gt_get_file_names(test_gt) - file.remove(files[1]) + # remove the .rds + expect_true(file.remove(files[1])) file <- gsub(".bk","",files[2],) + # create gt using the same backingfile name test_gt <- gen_tibble(x = test_genotypes, loci = test_loci, indiv_meta = test_indiv_meta, quiet = TRUE, backingfile = file) + # get new file names new_files <- gt_get_file_names(test_gt) - expect_equal(new_files[2], paste0(file,"_v1.bk")) + # new_files has the same name as original file, plus a version extension + expect_equal(new_files[2], paste0(file,"_v2.bk")) - file.remove(new_files[1]) - - file.exists(new_files[1]) - file.exists(new_files[2]) + # 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, @@ -461,7 +466,7 @@ test_that("versioning if .bk already exists",{ new_version_files <- gt_get_file_names(test_gt) - expect_equal(new_version_files[2], paste0(file,"_v2.bk")) + expect_equal(new_version_files[2], paste0(file,"_v3.bk")) })