Skip to content

Commit

Permalink
working tests GCAM6.0 and GCAM7.0 17
Browse files Browse the repository at this point in the history
  • Loading branch information
klau506 committed Aug 19, 2024
1 parent c9d3af4 commit c763bba
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
60 changes: 30 additions & 30 deletions tests/testthat/testReporter_v6.0.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,36 @@ test_that("Test5_v6. run - dataset saved with default output_file", {
testthat::expect(dplyr::n_distinct(testResult) > 0, 'Dataset not saved. Check if the project path exists or the "run" function works correctly.')
})

test_that("Test6_v6. load variable and get function", {
# load prj
generate_report(prj_name = file.path(rprojroot::find_root(rprojroot::is_testthat), "testInputs/v_6.0/test6.dat"), launch_ui = FALSE, GCAM_version = 'v6.0')

# load variables
vv <- get(load(file.path(rprojroot::find_root(rprojroot::is_testthat), "testOutputs/v_6.0/result_test6.RData")))
loaded_internal_variables.global <<- c()
desired_regions <<- "All"
desired_variables <<- "All"
GCAM_version <- "v6.0"
template_internal_variable <- get(paste('template',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))[['Internal_variable']]
variables_base <- data.frame(
"name" = unique(template_internal_variable)[!is.na(unique(template_internal_variable)) & unique(template_internal_variable) != ""],
"required" = TRUE,
stringsAsFactors = FALSE
)
variables.global <<- merge(variables_base, var_fun_map, by = "name", all = TRUE) %>%
tidyr::replace_na(list(required = FALSE))

# test
load_variable(vv, GCAM_version = GCAM_version)

testthat::expect(exists("ag_prices_wld"), "Loading variables function is broken.")

get_elec_capital(GCAM_version = GCAM_version)
testthat::expect(exists("elec_capital_clean"), "get_elec_capital() function is broken.")
testResult <- get(load(file.path(rprojroot::find_root(rprojroot::is_testthat), "testOutputs/v_6.0/result_test6.1.RData")))
testthat::expect_equal(elec_capital_clean, testResult)
rm(list = ls())
})
# test_that("Test6_v6. load variable and get function", {
# # load prj
# generate_report(prj_name = file.path(rprojroot::find_root(rprojroot::is_testthat), "testInputs/v_6.0/test6.dat"), launch_ui = FALSE, GCAM_version = 'v6.0')
#
# # load variables
# vv <- get(load(file.path(rprojroot::find_root(rprojroot::is_testthat), "testOutputs/v_6.0/result_test6.RData")))
# loaded_internal_variables.global <<- c()
# desired_regions <<- "All"
# desired_variables <<- "All"
# GCAM_version <- "v6.0"
# template_internal_variable <- get(paste('template',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))[['Internal_variable']]
# variables_base <- data.frame(
# "name" = unique(template_internal_variable)[!is.na(unique(template_internal_variable)) & unique(template_internal_variable) != ""],
# "required" = TRUE,
# stringsAsFactors = FALSE
# )
# variables.global <<- merge(variables_base, var_fun_map, by = "name", all = TRUE) %>%
# tidyr::replace_na(list(required = FALSE))
#
# # test
# load_variable(vv, GCAM_version = GCAM_version)
#
# testthat::expect(exists("ag_prices_wld"), "Loading variables function is broken.")
#
# get_elec_capital(GCAM_version = GCAM_version)
# testthat::expect(exists("elec_capital_clean"), "get_elec_capital() function is broken.")
# testResult <- get(load(file.path(rprojroot::find_root(rprojroot::is_testthat), "testOutputs/v_6.0/result_test6.1.RData")))
# testthat::expect_equal(elec_capital_clean, testResult)
# rm(list = ls())
# })
#
# test_that("Test7_v6. specify variables, regions, continents", {
# test_regions <- available_regions(T)
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/testReporter_v7.0.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,38 @@ test_that("Test4_v7. run - dataset saved with output_file specified", {
)
})

test_that("Test6_v6. load variable and get function", {
# load prj
generate_report(prj_name = file.path(rprojroot::find_root(rprojroot::is_testthat), "testInputs/v_6.0/test6.dat"), launch_ui = FALSE, GCAM_version = 'v6.0')

# load variables
vv <- get(load(file.path(rprojroot::find_root(rprojroot::is_testthat), "testOutputs/v_6.0/result_test6.RData")))
loaded_internal_variables.global <<- c()
desired_regions <<- "All"
desired_variables <<- "All"
GCAM_version <- "v6.0"
template_internal_variable <- get(paste('template',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))[['Internal_variable']]
variables_base <- data.frame(
"name" = unique(template_internal_variable)[!is.na(unique(template_internal_variable)) & unique(template_internal_variable) != ""],
"required" = TRUE,
stringsAsFactors = FALSE
)
variables.global <<- merge(variables_base, var_fun_map, by = "name", all = TRUE) %>%
tidyr::replace_na(list(required = FALSE))

# test
load_variable(vv, GCAM_version = GCAM_version)

testthat::expect(exists("ag_prices_wld"), "Loading variables function is broken.")

get_elec_capital(GCAM_version = GCAM_version)
testthat::expect(exists("elec_capital_clean"), "get_elec_capital() function is broken.")
testResult <- get(load(file.path(rprojroot::find_root(rprojroot::is_testthat), "testOutputs/v_6.0/result_test6.1.RData")))
testthat::expect_equal(elec_capital_clean, testResult)
rm(list = ls())
})


# test_that("Test5_v7. run - dataset saved with default output_file", {
# generate_report(prj_name = file.path(rprojroot::find_root(rprojroot::is_testthat), "testInputs/v_7.0/test7.dat"), launch_ui = FALSE)
#
Expand Down

0 comments on commit c763bba

Please sign in to comment.