Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
steffilazerte authored Feb 5, 2025
2 parents f9fa89d + 71338ae commit 3acb895
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R/weather.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ weather_dl <- function(station_ids,
}

if(is.null(end)) {
s.end <- Sys.Date()
s.end <- Sys.Date()
} else {
s.end <- as.Date(end)
if(s.end > Sys.Date()) s.end <- Sys.Date()
s.end <- as.Date(end)
}
msg.end <- as.character(s.end)

Expand Down Expand Up @@ -337,7 +336,11 @@ weather_dl <- function(station_ids,
}

if(length(end_dates) > 0 & !quiet) {
if(all(station_ids %in% missing)) type <- "all" else type <- "some"
if(all(station_ids %in% missing)) {
type <- "all"
} else {
type <- "some"
}

message(paste0("The end dates (", msg.end, ") are earlier than the ",
"start dates (", msg.start, ") for ", type, " stations (",
Expand Down
61 changes: 61 additions & 0 deletions tests/testthat/test_07_weather_args.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,64 @@ test_that("weather_dl() month string_as = NULL", {
})

})


test_that("weather_dl() (invalid start day) returns error when start is not a valid date day", {
skip_on_cran()

vcr::use_cassette("weather_month_5401", {
expect_error(weather_dl(station_ids = 5401,
start = "2017-01-99",
end = "2017-05-01",
interval = "month", format = FALSE),
"'start' and 'end' must be either a standard date format ")
})
})

test_that("weather_dl() (invalid start string) returns error when start is not a valid date string", {
skip_on_cran()

vcr::use_cassette("weather_month_5401", {
expect_error(weather_dl(station_ids = 5401,
start = "2017-01-NN",
end = "2017-05-01",
interval = "month", format = FALSE),
"'start' and 'end' must be either a standard date format ")
})
})

test_that("weather_dl() (invalid end day) returns error when end is not a valid date day", {
skip_on_cran()
vcr::use_cassette("weather_month_5401", {
expect_error(weather_dl(station_ids = 5401,
start = "2017-01-01",
end = "2017-04-99",
interval = "month", format = FALSE),
"'start' and 'end' must be either a standard date format ")
})
})


test_that("weather_dl() (invalid end string) verifies error return when end is not a valid date string", {
skip_on_cran()
vcr::use_cassette("weather_month_5401", {
expect_error(weather_dl(station_ids = 5401,
start = "2017-01-01",
end = "2017-04-NN",
interval = "month", format = FALSE),
"'start' and 'end' must be either a standard date format ")
})
})


test_that("weather_dl() (invalid stn) verifies error return when defunct stn", {
skip_on_cran()
vcr::use_cassette("weather_month_5401", {
expect_error(weather_dl(station_ids = 5401,
start = "2017-01-01",
end = "2017-05-01",
stn = "invalid defunct",
interval = "month", format = FALSE),
"`stn` is defunct, to use an updated stations data frame use ")
})
})

0 comments on commit 3acb895

Please sign in to comment.