11
22test_that(" Translation from long to short names works" , {
3- guide <- read_guide(test_path(" testdata /guide_competition_1_0.yml" ))
3+ guide <- read_guide(test_path(" fixtures /guide_competition_1_0.yml" ))
44 expect_equal(long_to_shortnames(" Version" , guide $ translations ), " template.version" )
55})
66
@@ -10,7 +10,7 @@ test_that("Function long_to_short yields correct result for missing translations
1010})
1111
1212test_that(" Function short_to_longnames works" , {
13- guide <- read_guide(test_path(" testdata /guide_competition_1_0.yml" ))
13+ guide <- read_guide(test_path(" fixtures /guide_competition_1_0.yml" ))
1414 expect_equal(short_to_longnames(" template.version" , guide $ translations ), " Version" )
1515})
1616
@@ -20,66 +20,87 @@ test_that("Function short_to_long yields correct result for missing translations
2020})
2121
2222test_that(" reading a single key-value pair works" , {
23- expect_no_error(read_keyvalue(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' description' , range = " A2:B2" ))
23+ expect_no_error(read_keyvalue(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' description' , range = " A2:B2" ))
2424 expected_result <- list (' template.version' = ' 9.3' )
25- guide <- read_guide(test_path(" testdata /guide_competition_1_0.yml" ))
26- expect_equal(read_keyvalue(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' description' , range = " A2:B2" , translate = TRUE ,
25+ guide <- read_guide(test_path(" fixtures /guide_competition_1_0.yml" ))
26+ expect_equal(read_keyvalue(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' description' , range = " A2:B2" , translate = TRUE ,
2727 translations = guide $ translations ), expected_result )
2828})
2929
3030test_that(" reading and coercing key-value pairs works" , {
3131 expected_result_single <- list (' max.spread' = 0.2 )
32- guide <- read_guide(test_path(" testdata /guide_competition_1_0.yml" ))
33- expect_equal(read_keyvalue(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' _parameters' , range = " A24:B24" ,
32+ guide <- read_guide(test_path(" fixtures /guide_competition_1_0.yml" ))
33+ expect_equal(read_keyvalue(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' _parameters' , range = " A24:B24" ,
3434 translate = FALSE , translations = guide $ translations , atomicclass = " numeric" ), expected_result_single )
3535 expected_result_multiple <- list (' ic0.min' = 65 , ic0.max = 135 )
36- expect_equal(read_keyvalue(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' _parameters' , range = " A27:B28" ,
36+ expect_equal(read_keyvalue(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' _parameters' , range = " A27:B28" ,
3737 translate = FALSE , translations = guide $ translations , atomicclass = " numeric" ), expected_result_multiple )
3838})
3939
4040test_that(" reading multiple key-value pairs works" , {
4141 expected_result <- list (' studyID' = ' MyProject' , ' exptID' = ' TTRfitc-020' , ' plateID' = ' 1' , ' instrID' = ' Instr1' )
42- expect_no_error(read_keyvalue(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' description' , range = " A10:B13" ))
43- guide <- read_guide(test_path(" testdata /guide_competition_1_0.yml" ))
44- expect_equal(read_keyvalue(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' description' , range = " A10:B13" , translate = TRUE ,
42+ expect_no_error(read_keyvalue(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' description' , range = " A10:B13" ))
43+ guide <- read_guide(test_path(" fixtures /guide_competition_1_0.yml" ))
44+ expect_equal(read_keyvalue(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' description' , range = " A10:B13" , translate = TRUE ,
4545 translations = guide $ translations ), expected_result )
4646})
4747
4848test_that(" Reading cells works" , {
4949 variables <- list (list (name = " spread.itm1" , cell = " G6" ),
5050 list (name = " spread.itm2" , cell = " G33" ))
5151 result <- list (spread.itm1 = " 0.0463713477851084" , spread.itm2 = " 0.0154571159283695" )
52- expect_no_error(read_cells(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' BGfluo' , variables = variables ))
53- expect_equal(read_cells(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' BGfluo' , variables = variables ), result )
52+ expect_no_error(read_cells(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' BGfluo' , variables = variables ))
53+ expect_equal(read_cells(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' BGfluo' , variables = variables ), result )
5454})
5555
5656test_that(" reading a table works" , {
57- expect_no_error(read_table(drfile = test_path(' testdata /test1.xlsx' ), sheet = ' _data' , range = " A101:B111" ))
57+ expect_no_error(read_table(drfile = test_path(' fixtures /test1.xlsx' ), sheet = ' _data' , range = " A101:B111" ))
5858})
5959
6060test_that(" Function read_data works" , {
61- guide <- read_guide(test_path(" testdata /guide_competition_1_0.yml" ))
62- expect_no_error(read_data(drfile = test_path(' testdata /test1.xlsx' ), guide = guide ))
63- expect_no_error(read_data(drfile = test_path(' testdata /test1.xlsx' ), guide = test_path(" testdata /guide_competition_1_0.yml" )))
61+ guide <- read_guide(test_path(" fixtures /guide_competition_1_0.yml" ))
62+ expect_no_error(read_data(drfile = test_path(' fixtures /test1.xlsx' ), guide = guide ))
63+ expect_no_error(read_data(drfile = test_path(' fixtures /test1.xlsx' ), guide = test_path(" fixtures /guide_competition_1_0.yml" )))
6464})
6565
6666
6767# test_that("Function read_data using guide with two plates returns two plates", {
68- # guide <- read_guide(test_path("testdata /goodguides/guide_with_two_plates.yaml"))
69- # result <- read_data(drfile = test_path('testdata /test1.xlsx'), guide = guide)
68+ # guide <- read_guide(test_path("fixtures /goodguides/guide_with_two_plates.yaml"))
69+ # result <- read_data(drfile = test_path('fixtures /test1.xlsx'), guide = guide)
7070# expect_equal(length(result$platedata), 2)
7171# })
7272
7373# test_that("Function read_data using guide split table returns single table", {
74- # # guide <- read_guide(test_path("testdata /goodguides/guide_with_split_table.yml"))
75- # # result <- read_data(drfile = test_path('testdata /test2.xlsx'), guide = guide)
74+ # # guide <- read_guide(test_path("fixtures /goodguides/guide_with_split_table.yml"))
75+ # # result <- read_data(drfile = test_path('fixtures /test2.xlsx'), guide = guide)
7676# # expect_equal(length(result$table), 1)
7777# })
7878
7979test_that(" Version incompatibilities yield an error." , {
80- guide <- read_guide(test_path(" testdata /erroneousguides/conflicting_min_version.yml" ))
81- expect_error(read_data(drfile = test_path(' testdata /test1.xlsx' ), guide = guide ))
82- guide <- read_guide(test_path(" testdata /erroneousguides/conflicting_max_version.yml" ))
83- expect_error(read_data(drfile = test_path(' testdata /test1.xlsx' ), guide = guide ))
80+ guide <- read_guide(test_path(" fixtures /erroneousguides/conflicting_min_version.yml" ))
81+ expect_error(read_data(drfile = test_path(' fixtures /test1.xlsx' ), guide = guide ))
82+ guide <- read_guide(test_path(" fixtures /erroneousguides/conflicting_max_version.yml" ))
83+ expect_error(read_data(drfile = test_path(' fixtures /test1.xlsx' ), guide = guide ))
8484})
8585
86+ # testing reading of dates
87+ test_that(" Reading key-value pairs with different atomic classes yields correct results" , {
88+ excel_file <- test_path(" fixtures/test0.xlsx" )
89+ sheet <- " kvpairs"
90+ expect_no_error(
91+ result <- read_keyvalue(
92+ drfile = excel_file , sheet = sheet , range = " A2:B4" ,
93+ translate = FALSE , atomicclass = c(" character" ," character" ," numeric" )
94+ )
95+ )
96+ expect_equal(result , list (char1 = " 9.3" , char2 = " test" , num1 = 1.2 ))
97+ expect_no_error(
98+ result <- read_keyvalue(
99+ drfile = excel_file , sheet = sheet , range = " A7:B7" ,
100+ translate = FALSE , atomicclass = c(" character" )
101+ )
102+ )
103+ expect_equal(
104+ result , list (char1 = " 9.3" )
105+ )
106+ })
0 commit comments