Skip to content

Commit

Permalink
Merge pull request #86 from dfe-analytical-services/development
Browse files Browse the repository at this point in the history
Fix error: Can't subset columns that don't exist
  • Loading branch information
cjrace authored Apr 5, 2023
2 parents 4b02fcd + ce02bb7 commit 31086e2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions R/mainTests.r
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,10 @@ country_combinations <- function(data) {
# check that there is a 1:1 relationship between geography codes and names

lower_level_geog_names <- geography_matrix[9:12, 2:3] %>% as.character() # skipping school/prov as they have legit duplicates
lower_level_geog_levels <- geography_matrix[9:12, 1] %>% as.character()

other_geography_duplicates <- function(data) {
if (!any(lower_level_geog_names %in% names(data))) {
if (!any(lower_level_geog_levels %in% unique(data$geographic_level))) {
output <- list(
"message" = "Lower-level geography data is not present in this data file.",
"result" = "IGNORE"
Expand Down Expand Up @@ -1593,9 +1594,10 @@ other_geography_duplicates <- function(data) {
# check that there is a 1:1 relationship between geography names and codes

lower_level_geog_names <- geography_matrix[9:12, 2:3] %>% as.character() # skipping school/prov as they have legit duplicates
lower_level_geog_levels <- geography_matrix[9:12, 1] %>% as.character()

other_geography_code_duplicates <- function(data) {
if (!any(lower_level_geog_names %in% names(data))) {
if (!any(lower_level_geog_levels %in% unique(data$geographic_level))) {
output <- list(
"message" = "Lower-level geography data is not present in this data file.",
"result" = "IGNORE"
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/sch_prov/school_with_trust.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
time_identifier,time_period,geographic_level,country_code,country_name,region_code,region_name,old_la_code,new_la_code,la_name,estab,school_laestab,school_urn,school_name,trust_name,academy_type,academy_open_date,school_type,headcount,perm_excl,perm_excl_rate,suspension,susp_rate,one_plus_susp,one_plus_susp_rate
Spring term,202122,School,E92000001,England,E13000001,Inner London,201,E09000001,City of London,3614,2013614,100000,The Aldgate School,z,z,z,State-funded primary,277,0,0,0,0,0,0
Autumn term,202122,School,E92000001,England,E13000001,Inner London,201,E09000001,City of London,3614,2013614,100000,The Aldgate School,z,z,z,State-funded primary,269,0,0,0,0,0,0
Autumn term,202122,School,E92000001,England,E13000001,Inner London,202,E09000007,Camden,2000,2022000,136807,St Luke's Church of England School,ST LUKE'S CHURCH OF ENGLAND SCHOOL,z,z,State-funded primary,101,0,0,0,0,0,0
Spring term,202122,School,E92000001,England,E13000001,Inner London,202,E09000007,Camden,2000,2022000,136807,St Luke's Church of England School,ST LUKE'S CHURCH OF ENGLAND SCHOOL,z,z,State-funded primary,102,0,0,0,0,0,0
Autumn term,202122,School,E92000001,England,E13000001,Inner London,202,E09000007,Camden,2001,2022001,139837,Abacus Belsize Primary School,ANTHEM SCHOOLS TRUST,z,z,State-funded secondary,156,0,0,0,0,0,0
Spring term,202122,School,E92000001,England,E13000001,Inner London,202,E09000007,Camden,2001,2022001,139837,Abacus Belsize Primary School,ANTHEM SCHOOLS TRUST,z,z,State-funded secondary,163,0,0,0,0,0,0
9 changes: 9 additions & 0 deletions tests/testthat/sch_prov/school_with_trust.meta.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
col_name,col_type,label,indicator_grouping,indicator_unit,indicator_dp,filter_hint,filter_grouping_column
school_type,Filter,School Type,,,,"State-funded primary, secondary and special",
headcount,Indicator,Headcount,,,0,,
perm_excl,Indicator,Permanent exclusions,,,0,,
perm_excl_rate,Indicator,Permanent exclusions (rate),,,2,,
suspension,Indicator,Suspensions,,,0,,
susp_rate,Indicator,Suspension (rate),,,2,,
one_plus_susp,Indicator,Pupil enrolments with one or more suspension,,,0,,
one_plus_susp_rate,Indicator,Pupil enrolments with one or moresuspension (rate),,,2,,
2 changes: 1 addition & 1 deletion tests/testthat/test-mainTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ test_that("other_geography_duplicates", {

# other_geography_code_duplicates -------------------------------------------------------------------------------------------------------

test_that("other_geography_duplicates", {
test_that("other_geography_code_duplicates", {
expect_equal(testIndividualTest(pathStart, "other_geography_code_duplicates"), "FAIL")
})

Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-screenFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ test_that("sch_filter_group", {
expect_equal(screeningOutput$results %>% filter(result == "FAIL") %>% nrow(), 0)
})

test_that("sch_with_trust_cols", {
screeningOutput <- testOther("../../tests/testthat/sch_prov/school_with_trust.csv")

expect_equal(screeningOutput$results %>% filter(test == "other_geography_duplicates") %>% pull(result) %>% unlist(use.names = FALSE), "IGNORE")
expect_equal(screeningOutput$results %>% filter(test == "other_geography_code_duplicates") %>% pull(result) %>% unlist(use.names = FALSE), "IGNORE")
})

test_that("not_sch_but_one_filter", {
screeningOutput <- testOther("../../tests/testthat/sch_prov/not_sch_but_one_filter.csv")

Expand Down

0 comments on commit 31086e2

Please sign in to comment.