Skip to content

Commit

Permalink
Add tests and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
klau506 committed Mar 20, 2024
1 parent a4ed18e commit 54c0250
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 173 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: build

on:
push:
branches:
- main

jobs:
R-CMD:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: 'devel', cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GH_RFASSTUI_TOKEN}}

steps:
- uses: actions/checkout@v1
- uses: r-lib/actions/setup-r@v2-branch
with:
r-version: '3.6'
- uses: r-lib/actions/setup-pandoc@v2-branch
- uses: r-lib/actions/setup-tinytex@v2-branch

- name: Install libraries
if: startsWith(matrix.config.os, 'ubuntu')
run: |
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev libmagick++-dev libavfilter-dev libharfbuzz-dev libfribidi-dev
- name: Install dependencies
run: |
install.packages(c("remotes","rcmdcheck"), repos = "https://cloud.r-project.org")
remotes::install_deps(dependencies = TRUE)
remotes::install_github("JGCRI/rpackageutils")
shell: Rscript {0}

- name: Check
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--ignore-vignettes", "--no-build-vignettes"), build_args = c("--no-manual", "--ignore-vignettes", "--no-build-vignettes"), error_on = "error")
shell: Rscript {0}
48 changes: 48 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: test-coverage

on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{secrets.GH_GCAMREPORT_TOKEN}}

steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v2-branch
with:
r-version: '4.1.0'
- uses: r-lib/actions/setup-pandoc@v2-branch
- uses: r-lib/actions/setup-tinytex@v2-branch
- uses: actions/download-artifact@v2

- name: Cache R packages
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Ubuntu config
run: |
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev libssl-dev libxml2-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev libmagick++-dev libavfilter-dev
- name: Install dependencies
run: |
install.packages(c("remotes","rcmdcheck","covr"), repos = "https://cloud.r-project.org")
remotes::install_github("JGCRI/rpackageutils")
remotes::install_deps(dependencies = TRUE)
shell: Rscript {0}

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: bc3LC/rfasstui
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(data_query)
export(fill_queries)
export(get_example_prj)
export(get_globalCapabilities)
export(get_globalCustomColorScales)
Expand Down
4 changes: 0 additions & 4 deletions R/set_globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ get_globalCapabilities <- function() {
globalCapabilities[['agriculture_rev_loss']] <- 'agriculture_rev_loss'
attr(globalCapabilities[['agriculture_rev_loss']], 'longName') <- "Agriculture revenue loss"

# # "Economic impacts" TODO
# globalCapabilities[['economy']] <- c('VSL')
# attr(globalCapabilities[['economy']], 'longName') <- "Economic imipacts"


return(globalCapabilities)
}
93 changes: 0 additions & 93 deletions R/user_prj_creation.R

This file was deleted.

6 changes: 3 additions & 3 deletions inst/rfasstui/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ server <- function(input, output, session)
# Add nonCO2 query manually (it is too big to use the usual method)
prj <- rfasstui::fill_queries(prj, db_path, db_name, prj_name, scen_name,
query_path, query_file)
prj <- rfasst::fill_queries(prj, db_path, db_name, prj_name, scenarios,
query_path, queries = 'queries_rfasst_nonCO2.xml')
# Save the project
rgcam::saveProject(prj, file = file.path('output',prj_name))")
rgcam::saveProject(prj, file = prj_name)")
})


Expand Down
34 changes: 0 additions & 34 deletions man/data_query.Rd

This file was deleted.

37 changes: 0 additions & 37 deletions man/fill_queries.Rd

This file was deleted.

4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(rfasstui)

test_check("rfasstui")
91 changes: 91 additions & 0 deletions tests/testthat/test-globals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
library(rfasst)


context("globals")


test_that("globals: color SSP scale", {

globalSSPColorScales <- get_globalSSPColorScales()

testthat::expect_equal(globalSSPColorScales,
c("GCAM_SSP1" = "#5DBFDE", "GCAM_SSP2" = "#5CB95C", "GCAM_SSP3" = "#FBAB33",
"GCAM_SSP4" ="#D7534E", "GCAM_SSP5" ="#9E49D1"))

})

test_that("globals: color custom scale", {

globalCustomColorScales <- get_globalCustomColorScales()

testthat::expect_equal(globalCustomColorScales,
c("#5DBFDE","#5CB95C","#FBAB33","#D7534E","#9E49D1"))

})


test_that("globals: get example prj", {

globalExamplePrj <- get_example_prj()

testthat::expect_equal(globalExamplePrj,
get(load(file.path(rprojroot::find_root(rprojroot::is_testthat),"test_results","globalExamplePrj.RData"))))

})

test_that("globals: get queries", {

globalQueries <- get_queries()

testthat::expect_equal(globalQueries,
get(load(file.path(rprojroot::find_root(rprojroot::is_testthat),"test_results","globalQueries.RData"))))

})


test_that("globals: global capabilities", {

globalCapabilities <- get_globalCapabilities()

expect_equal(globalCapabilities[['emissions_bc']][1], 'emissions_bc')
expect_equal(attributes(globalCapabilities[['emissions_bc']])$longName, 'BC emissions')

expect_equal(globalCapabilities[['emissions_nh3']][1], 'emissions_nh3')
expect_equal(attributes(globalCapabilities[['emissions_nh3']])$longName, 'NH3 emissions')

expect_equal(globalCapabilities[['emissions_nmvoc']][1], 'emissions_nmvoc')
expect_equal(attributes(globalCapabilities[['emissions_nmvoc']])$longName, 'NMVOC emissions')

expect_equal(globalCapabilities[['emissions_nox']][1], 'emissions_nox')
expect_equal(attributes(globalCapabilities[['emissions_nox']])$longName, 'NOx emissions')

expect_equal(globalCapabilities[['emissions_pom']][1], 'emissions_pom')
expect_equal(attributes(globalCapabilities[['emissions_pom']])$longName, 'POM emissions')

expect_equal(globalCapabilities[['emissions_so2']][1], 'emissions_so2')
expect_equal(attributes(globalCapabilities[['emissions_so2']])$longName, 'SO2 emissions')

expect_equal(globalCapabilities[['concentration_pm25']][1], 'concentration_pm25')
expect_equal(attributes(globalCapabilities[['concentration_pm25']])$longName, 'PM25 concentration')

expect_equal(globalCapabilities[['concentration_o3']][1], 'concentration_o3')
expect_equal(attributes(globalCapabilities[['concentration_o3']])$longName, 'O3 concentration')

expect_equal(globalCapabilities[['health_deaths_pm25']][1], 'health_deaths_pm25')
expect_equal(attributes(globalCapabilities[['health_deaths_pm25']])$longName, 'Premature deaths due to PM25')

expect_equal(globalCapabilities[['health_deaths_o3']][1], 'health_deaths_o3')
expect_equal(attributes(globalCapabilities[['health_deaths_o3']])$longName, 'Premature deaths due to O3')

expect_equal(globalCapabilities[['health_deaths_total']][1], 'health_deaths_total')
expect_equal(attributes(globalCapabilities[['health_deaths_total']])$longName, 'Total premature deaths')

expect_equal(globalCapabilities[['agriculture_ryl_mi']][1], 'agriculture_ryl_mi')
expect_equal(attributes(globalCapabilities[['agriculture_ryl_mi']])$longName, 'Agriculture relative yield loss')

expect_equal(globalCapabilities[['agriculture_prod_loss']][1], 'agriculture_prod_loss')
expect_equal(attributes(globalCapabilities[['agriculture_prod_loss']])$longName, 'Agriculture production loss')

expect_equal(globalCapabilities[['agriculture_rev_loss']][1], 'agriculture_rev_loss')
expect_equal(attributes(globalCapabilities[['agriculture_rev_loss']])$longName, 'Agriculture revenue loss')
})
Loading

0 comments on commit 54c0250

Please sign in to comment.