-
Notifications
You must be signed in to change notification settings - Fork 1
/
csvw-tests-helpers.R
53 lines (43 loc) · 1.59 KB
/
csvw-tests-helpers.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# https://w3c.github.io/csvw/tests/
run_entry <- function(entry) {
csvw <- read_csvw(entry$action, metadata=entry$option$metadata)
actual <- csvw_to_list(csvw)
list(csvw=csvw, actual=actual)
}
name_test <- function(entry) {
test_name <- paste0(entry$id, " - ", entry$name, "; action: ", entry$action)
if(!is.null(entry$option$metadata)) {
test_name <- paste0(test_name, ", metadata: ", entry$option$metadata)
}
if(!is.null(entry$result)) {
test_name <- paste0(test_name, ", result: ", entry$result)
}
test_name
}
find_entry <- function(id) {
csvw_test_path <- "../csvw-tests"
orig_dir <- setwd(csvw_test_path)
on.exit(setwd(orig_dir), add=T, after=F)
test_manifest <- jsonlite::read_json(file.path(csvw_test_path, "manifest-json.jsonld"))
entry <- test_manifest$entries[[which(sapply(test_manifest$entries, function(x) x$id == id))]]
entry
}
# convenience function for loading-up an entry to explore a failing test
run_entry_in_dev <- function(n=NULL, id=NULL) {
orig_op <- options(csvwr_base_uri="http://www.w3.org/2013/csvw/tests/",
csvwr_compatibility_mode=T)
on.exit(options(orig_op), add=T, after=F)
csvw_test_path <- "tests/csvw-tests"
orig_dir <- setwd(csvw_test_path)
on.exit(setwd(orig_dir), add=T, after=F)
entries <- c("manifest-json.jsonld","manifest-validation.jsonld") %>%
purrr::map(function(f) { jsonlite::read_json(f)$entries }) %>%
do.call(what="c")
if(!is.null(id)) {
n <- which(sapply(entries, function(x) x$id == id))
}
entry <- entries[[n]]
print(entry$name)
print(entry$comment)
run_entry(entry)
}