Skip to content

Commit

Permalink
Organized covr usage
Browse files Browse the repository at this point in the history
Removed the check for covr in tests and set environment variable NOT_CRAN to not skip the tests when running covr.
  • Loading branch information
wilsonfreitas committed Aug 16, 2022
1 parent 9494eda commit 2f34e07
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 95 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [main, master]

env:
NOT_CRAN: true

name: test-coverage

jobs:
Expand Down
7 changes: 2 additions & 5 deletions R/addin-display-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,5 @@ display_template <- function() {
height = 900
)

# dont call shiny when in covr
if (!covr::in_covr()) {
shiny::runGadget(app, viewer = viewer, stopOnCancel = TRUE)
}
}
shiny::runGadget(app, viewer = viewer, stopOnCancel = TRUE)
}
7 changes: 2 additions & 5 deletions R/addin-show-templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ show_templates <- function() {
app <- shiny::shinyApp(ui = ui, server = server)
viewer <- shiny::dialogViewer("rb3 Templates", width = 1200, height = 900)

# dont call shiny when in covr
if (!covr::in_covr()) {
shiny::runGadget(app, viewer = viewer, stopOnCancel = TRUE)
}
}
shiny::runGadget(app, viewer = viewer, stopOnCancel = TRUE)
}
10 changes: 0 additions & 10 deletions tests/testthat/test-addin.R

This file was deleted.

6 changes: 2 additions & 4 deletions tests/testthat/test-bdin.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

test_that("read file using filename to find template", {
if (!covr::in_covr()) {
skip_on_cran()
}
skip_on_cran()

f <- system.file("extdata/big-files/BDIN.zip", package = "rb3")
f <- copy_file_to_temp(f)
Expand All @@ -11,4 +9,4 @@ test_that("read file using filename to find template", {
res <- read_marketdata(f)
expect_s3_class(res, "parts")
expect_s3_class(res[[1]], "data.frame")
})
})
8 changes: 3 additions & 5 deletions tests/testthat/test-cdi.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
test_that("cdi", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}
skip_on_cran()
skip_if_offline()

# first call
cdi_1 <- cdi_get()
Expand All @@ -15,4 +13,4 @@ test_that("cdi", {

idi <- idi_get()
expect_true(nrow(idi) > 0)
})
})
7 changes: 3 additions & 4 deletions tests/testthat/test-cdiidi.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
if (!covr::in_covr()) {
skip_on_cran()
}

skip_on_cran()

test_that("it should download cdi/idi file", {
f <- download_marketdata("CDIIDI")
Expand All @@ -26,4 +25,4 @@ test_that("it should get idi index", {
df <- idi_get()
expect_s3_class(df$refdate, "Date")
expect_true(is(df$IDI, "numeric"))
})
})
6 changes: 2 additions & 4 deletions tests/testthat/test-cotahist.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}
skip_on_cran()
skip_if_offline()

if (Sys.info()["sysname"] == "Linux") {
httr::set_config(httr::config(ssl_verifypeer = FALSE))
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-downloaders.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

if (!covr::in_covr()) {
skip_on_cran()
}
skip_on_cran()
skip_if_offline()

if (Sys.info()["sysname"] == "Linux") {
httr::set_config(httr::config(ssl_verifypeer = FALSE))
Expand Down Expand Up @@ -92,4 +91,4 @@ test_that("it should company_cash_dividends_download ", {
trading_name = "AMBEVSA"
)
expect_true(f)
})
})
14 changes: 5 additions & 9 deletions tests/testthat/test-futures.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

test_that("it should get futures data with futures_mget", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}
skip_on_cran()
skip_if_offline()

first_date <- Sys.Date() - 5
last_date <- Sys.Date()
Expand All @@ -24,10 +22,8 @@ test_that("it should get futures data with futures_mget", {
})

test_that("it should get futures data with futures_get", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}
skip_on_cran()
skip_if_offline()

refdate <- bizdays::offset(Sys.Date(), -1, "Brazil/ANBIMA")

Expand Down Expand Up @@ -79,4 +75,4 @@ test_that("it should test maturity2date", {
maturity2date(c("F22", "AGO2")),
c(as.Date("2022-01-01"), as.Date("2002-08-01"))
)
})
})
7 changes: 3 additions & 4 deletions tests/testthat/test-indexes.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

skip_on_cran()
skip_if_offline()

test_that("it should get index composition", {
x <- index_comp_get("IBOV")
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-readers.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
test_that("it should read options_open_interest_read", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}
skip_on_cran()
skip_if_offline()

f <- system.file("extdata/big-files/OpcoesAcoesEmAberto.zip",
package = "rb3"
Expand Down Expand Up @@ -59,4 +57,4 @@ test_that("it should read company_cash_dividends_reader", {
f <- copy_file_to_temp(f)
df <- suppressWarnings(read_marketdata(f, "GetListedCashDividends"))
expect_s3_class(df, "data.frame")
})
})
40 changes: 4 additions & 36 deletions tests/testthat/test-yc.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

skip_on_cran()
skip_if_offline()

test_df <- function(df_in) {
expect_true(nrow(df_in) > 0)
expect_true(ncol(df_in) > 0)
Expand All @@ -8,11 +11,6 @@ test_df <- function(df_in) {
}

test_that("Test of yc_mget function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

first_date <- Sys.Date() - 50
last_date <- Sys.Date()

Expand All @@ -37,11 +35,6 @@ test_that("Test of yc_mget function", {
})

test_that("Test of yc_get function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

refdate <- bizdays::offset(Sys.Date(), -30, "Brazil/ANBIMA")

# first call (no cache)
Expand All @@ -58,11 +51,6 @@ test_that("Test of yc_get function", {
})

test_that("Test of yc_ipca_mget function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

first_date <- Sys.Date() - 10
last_date <- Sys.Date()

Expand All @@ -87,11 +75,6 @@ test_that("Test of yc_ipca_mget function", {
})

test_that("Test of yc_ipca_get function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

refdate <- bizdays::offset(Sys.Date(), -30, "Brazil/ANBIMA")

# first call (no cache)
Expand All @@ -108,11 +91,6 @@ test_that("Test of yc_ipca_get function", {
})

test_that("Test of yc_usd_mget function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

first_date <- Sys.Date() - 10
last_date <- Sys.Date()

Expand All @@ -137,11 +115,6 @@ test_that("Test of yc_usd_mget function", {
})

test_that("Test of yc_usd_get function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

refdate <- bizdays::offset(Sys.Date(), -30, "Brazil/ANBIMA")

# first call (no cache)
Expand All @@ -158,11 +131,6 @@ test_that("Test of yc_usd_get function", {
})

test_that("Test of yc_superset function", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

refdate <- bizdays::offset(Sys.Date(), -30, "Brazil/ANBIMA")

fut <- futures_get(refdate)
Expand All @@ -178,4 +146,4 @@ test_that("Test of yc_superset function", {
df <- yc_ipca_superset(yc, fut)
expect_true(exists("symbol", df))
expect_true(anyNA(df$symbol))
})
})

0 comments on commit 2f34e07

Please sign in to comment.