Skip to content

Commit

Permalink
Merge pull request #28 from lfagliano/i-will-break-stuff
Browse files Browse the repository at this point in the history
breaking stufffff
  • Loading branch information
lfagliano authored May 14, 2024
2 parents 15ec11b + c79ee8d commit 59db336
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 63 deletions.
14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@
.Rhistory
.RData
.Ruserdata
.DS_Store
inst/doc
/doc/
/Meta/
docs
.Renviron
.Rprofile
vault
vault/secret-keys.R
gadm36_NGA_1_sp.rds
trackdown_uploads.R
.RDataTmp
test.r
.Renviorn
.Renviron
.DS_Store
Binary file removed inst/coverage_test-17-07_mid.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/acledR-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions man/acled_api.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/acled_deletions_api.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/acled_transform_interaction.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/acled_transform_longer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/acled_transform_wider.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/acled_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 11 additions & 25 deletions tests/testthat/test-acled_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("names of columns are correct", {
## test if event_type filters work----
test_that("event_type filters work or not",{

expect_equal(unique(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
expect_equal(unique(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31", country = "Argentina",
event_type = "Protests", prompt = F, acled_access = F, log = F)$event_type), "Protests" )

Expand All @@ -29,35 +29,21 @@ test_that("country days are calculated as expected",{
mutate(t_end = lubridate::ymd("2021-01-01"),
unit_test = t_end - ymd(paste0(start_year, "-01-01")))

argentina_test_call <- acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
argentina_test_call <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina", start_date="1998-01-01",
end_date = "2021-01-01",prompt = F, acled_access = F, log = T)

expect_equal(argentina_test_call$time, argentina_country_days$unit_test)

})

# This works locally, but fails on devtools::check() and covr::package_coverge, but not on devtools::test() and simple execution.
# local({
#
# local_mocked_bindings(menu = function(choices,title=NULL) 2)
#
# test_that("Users can stop a call if they need to", {
#
# expect_snapshot(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
# start_date="2022-01-01",end_date = "2022-12-31",countries = "Argentina",
# prompt = T, acled_access = F, log = F), error = T)
# })
#
# }) # test on whether they can cancel

local({

local_mocked_bindings(menu = function(choices,title=NULL) 1)

test_that("Users continue call", {

expect_equal(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
expect_equal(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
prompt = T, acled_access = F, log = F), acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
Expand Down Expand Up @@ -112,7 +98,7 @@ local({

test_that("A user can stop a call when the provided timestamp is not recognized",{

expect_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
timestamp = "muchachos", prompt = F, acled_access = F, log = F), regexp = "User requested")
})
Expand All @@ -124,7 +110,7 @@ local({

test_that("A user can ignore the provided timestamp if it is not recognized",{

expect_no_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
expect_no_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
timestamp = "muchachos", prompt = F, acled_access = F, log = F))
})
Expand Down Expand Up @@ -171,20 +157,20 @@ test_that("Population columns are being received", {
## Error when someone requests a region that does not exist----

test_that("Error prompted when region does not exist", {
expect_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",regions = "Narnia",
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = "Narnia",
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F), regexp = "One or more requested region names not in the ACLED country list.")
})

test_that("Error when region number does not exist", {
expect_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",regions = 420,
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = 420,
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F),
regexp = "One or more requested region numbers not in the ACLED country list")
})


## Errors when a country requested doesnt exists ----
test_that("Error when one of two countries are wrong",{
expect_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",country = c("Argentia","Bolivia"),
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),country = c("Argentia","Bolivia"),
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F),
regexp = "One or more of the requested *")})

Expand All @@ -206,7 +192,7 @@ test_that("acled_api() throws an error when called with invalid arguments", {
"Country is not a valid option. Please utilize \"country\", without capitalizing")


expect_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
Region = "North America",
start_date="2022-01-01",
end_date = "2022-12-31",
Expand All @@ -215,7 +201,7 @@ test_that("acled_api() throws an error when called with invalid arguments", {
log = F), regexp=
"Region is not a valid option. Please utilize \"regions\"")

expect_error(acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
Regions = "North America",
start_date="2022-01-01",
end_date = "2022-12-31",
Expand Down Expand Up @@ -272,7 +258,7 @@ test_that("Users gets an error when acled_access is False, but no key or email a
# Test error if start_date is after end_date ----
test_that("start_date is after end_date", {
expect_error(
acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina",
start_date="2022-01-01",
end_date = "2021-01-01",
Expand Down

0 comments on commit 59db336

Please sign in to comment.