Skip to content

Commit

Permalink
Fixes #1261 throw an error if data is not utf-8 encoded (#1265)
Browse files Browse the repository at this point in the history
* Fixes #1261 throw an error if data is not utf-8 encoded

* Test dictionaries had non utf-8 characters
  • Loading branch information
pchelle authored Sep 6, 2024
1 parent 252a166 commit f736335
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 6 deletions.
1 change: 1 addition & 0 deletions R/utilities-observed-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ readObservedDataFile <- function(fileName,
header = TRUE,
encoding = "UTF-8") {
validateFileExists(fileName)
validateIsFileUTF8(fileName)
# Get function with the most appropriate reading defaults
readObservedData <- getReaderFunction(fileName)
observedData <- readObservedData(
Expand Down
330 changes: 330 additions & 0 deletions tests/data/input-data/non-utf8.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/data/input-data/tpDictionary-ill-defined-unit.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ tad,timeprofile,TAD,h,,,
age,covariate,AGE,year(s),Age,Organism|Age,
wght,covariate,WGHT,kg,Body weight,Organism|Weight,
hght,covariate,HGHT,cm,Height,Organism|Height,
bmi,covariate,BMI,kg/m,BMI,Organism|BMI,
bmi,covariate,BMI,kg/m²,BMI,Organism|BMI,
gender,covariate,SEX,,SEX,Gender,Make sure 1=male 2= female
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ tad,timeprofile,TAD,h,,,
age,covariate,AGE,year(s),Age,Organism|Age,
wght,covariate,WGHT,kg,Body weight,Organism|Weight,
hght,covariate,HGHT,cm,Height,Organism|Height,
bmi,covariate,BMI,kg/m,BMI,Organism|BMI,
bmi,covariate,BMI,kg/m²,BMI,Organism|BMI,
gender,covariate,SEX,,SEX,Gender,Make sure 1=male 2= female
2 changes: 1 addition & 1 deletion tests/data/input-data/tpDictionary-lloq.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ lloq,timeprofile,LOQ,µmol/l,,,
age,covariate,AGE,year(s),Age,Organism|Age,
wght,covariate,WGHT,kg,Body weight,Organism|Weight,
hght,covariate,HGHT,cm,Height,Organism|Height,
bmi,covariate,BMI,kg/m,BMI,Organism|BMI,
bmi,covariate,BMI,kg/m²,BMI,Organism|BMI,
gender,covariate,SEX,,SEX,Gender,Make sure 1=male 2= female
2 changes: 1 addition & 1 deletion tests/data/input-data/tpDictionary-unit-in-obs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ tad,timeprofile,TAD,h,,,
age,covariate,AGE,year(s),Age,Organism|Age,
wght,covariate,WGHT,kg,Body weight,Organism|Weight,
hght,covariate,HGHT,cm,Height,Organism|Height,
bmi,covariate,BMI,kg/m,BMI,Organism|BMI,
bmi,covariate,BMI,kg/m²,BMI,Organism|BMI,
gender,covariate,SEX,,SEX,Gender,Make sure 1=male 2= female
2 changes: 1 addition & 1 deletion tests/data/input-data/tpDictionary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ tad,timeprofile,TAD,h,,,
age,covariate,AGE,year(s),Age,Organism|Age,
wght,covariate,WGHT,kg,Body weight,Organism|Weight,
hght,covariate,HGHT,cm,Height,Organism|Height,
bmi,covariate,BMI,kg/m,BMI,Organism|BMI,
bmi,covariate,BMI,kg/m²,BMI,Organism|BMI,
gender,covariate,SEX,,SEX,Gender,Make sure 1=male 2= female
8 changes: 7 additions & 1 deletion tests/testthat/test-observed-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ test_that("readObservedDataFile can correctly guess separator and read csv and t
expect_equal(testDataFrame, txtData, tolerance = comparisonTolerance())
})

test_that("readObservedDataFile: unexistant file throw error", {
test_that("readObservedDataFile: throws an error for unexistant files", {
expect_error(readObservedDataFile("testFile10.csv"))
})

test_that("readObservedDataFile throws an error for non UTF-8 files", {
expect_error(
readObservedDataFile(getTestDataFilePath("input-data/non-utf8.txt"))
)
})

test_that("readObservedDataFile throw an error if columns are inconsistent", {
expect_error(
readObservedDataFile(getTestDataFilePath("input-data/error-data.csv"))
Expand Down

0 comments on commit f736335

Please sign in to comment.