-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
…json-2 Add tests for json_reader function and sample json data
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"mpg":21,"cyl":6,"disp":160,"hp":110,"drat":3.9,"wt":2.62,"qsec":16.46,"vs":0,"am":1,"gear":4,"carb":4},{"mpg":21,"cyl":6,"disp":160,"hp":110,"drat":3.9,"wt":2.875,"qsec":17.02,"vs":0,"am":1,"gear":4,"carb":4},{"mpg":22.8,"cyl":4,"disp":108,"hp":93,"drat":3.85,"wt":2.32,"qsec":18.61,"vs":1,"am":1,"gear":4,"carb":1},{"mpg":21.4,"cyl":6,"disp":258,"hp":110,"drat":3.08,"wt":3.215,"qsec":19.44,"vs":1,"am":0,"gear":3,"carb":1},{"mpg":18.7,"cyl":8,"disp":360,"hp":175,"drat":3.15,"wt":3.44,"qsec":17.02,"vs":0,"am":0,"gear":3,"carb":2},{"mpg":18.1,"cyl":6,"disp":225,"hp":105,"drat":2.76,"wt":3.46,"qsec":20.22,"vs":1,"am":0,"gear":3,"carb":1}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
test_path <- "custom_data/mtcars.json" | ||
target <- tibble::as_tibble(head(mtcars)) | ||
|
||
test_that("json_reader can read in a simple dataset", { | ||
test <- json_reader(test_path) | ||
expect_s3_class(test, "tbl_df") | ||
expect_equal( | ||
colnames(test), | ||
colnames(target) | ||
) | ||
attributes(test)$spec <- NULL | ||
attributes(test)$problems <- NULL | ||
expect_equal( | ||
test, | ||
target | ||
) | ||
}) | ||
|
||
test_that("json_reader verbosity is controlled as expected", { | ||
expect_gte( | ||
length(capture.output(tmp <- json_reader(test_path, verbose = TRUE), | ||
type = "message" | ||
)), | ||
1 | ||
) | ||
expect_equal( | ||
length(capture.output(tmp <- json_reader(test_path, verbose = FALSE), | ||
type = "message" | ||
)), | ||
0 | ||
) | ||
}) | ||
|
||
test_that("json_reader fails as expected when given a file that doesn't exist", { | ||
expect_error(json_reader("nonsense.json", verbose = FALSE)) | ||
}) |