11# Tests for frictionless datapackage.json
2+ # datapackage.json lives at repo root (not in installed package) per Frictionless spec.
23
34test_that(" datapackage.json exists and is valid JSON" , {
4- pkg_path <- system.file(" metadata" , " datapackage.json" , package = " betydata" )
5- expect_true(file.exists(pkg_path ))
6-
7- dp <- jsonlite :: read_json(pkg_path )
5+ pkg_root <- testthat :: test_path(" .." , " .." )
6+ dp_path <- file.path(pkg_root , " datapackage.json" )
7+ skip_if_not(file.exists(dp_path ),
8+ " datapackage.json not found at repo root (skipped in installed package)" )
9+
10+ dp <- jsonlite :: read_json(dp_path )
811 expect_true(" name" %in% names(dp ))
912 expect_equal(dp $ name , " betydata" )
1013})
1114
1215test_that(" datapackage.json lists all datasets" , {
13- pkg_path <- system.file(" metadata" , " datapackage.json" , package = " betydata" )
14- dp <- jsonlite :: read_json(pkg_path )
15-
16+ pkg_root <- testthat :: test_path(" .." , " .." )
17+ dp_path <- file.path(pkg_root , " datapackage.json" )
18+ skip_if_not(file.exists(dp_path ),
19+ " datapackage.json not found at repo root (skipped in installed package)" )
20+
21+ dp <- jsonlite :: read_json(dp_path )
1622 resource_names <- vapply(dp $ resources , function (r ) r $ name , character (1 ))
17-
23+
1824 expected <- c(" traitsview" , " species" , " sites" , " variables" , " citations" ,
1925 " pfts" , " priors" , " cultivars" , " methods" , " treatments" )
2026 expect_true(all(expected %in% resource_names ))
2127})
2228
2329test_that(" traitsview schema fields match actual columns" , {
24- pkg_path <- system.file(" metadata" , " datapackage.json" , package = " betydata" )
25- dp <- jsonlite :: read_json(pkg_path )
26-
30+ pkg_root <- testthat :: test_path(" .." , " .." )
31+ dp_path <- file.path(pkg_root , " datapackage.json" )
32+ skip_if_not(file.exists(dp_path ),
33+ " datapackage.json not found at repo root (skipped in installed package)" )
34+
35+ dp <- jsonlite :: read_json(dp_path )
2736 tv_resource <- Filter(function (r ) r $ name == " traitsview" , dp $ resources )[[1 ]]
2837 schema_fields <- vapply(tv_resource $ schema $ fields , function (f ) f $ name , character (1 ))
29-
38+
3039 data(" traitsview" , package = " betydata" )
3140 expect_equal(sort(schema_fields ), sort(names(traitsview )))
32- })
41+ })
0 commit comments