<commit_before># A complete set of daymetr unit tests
# to ensure that code changes do not break
# the functionality and download behaviour.
# This allows checks to see if server paths
# are still ok, and if overall the functions
# don't act up.

# standard pixel extraction test both single
# location and batch processing
test_that("pixel location download check",{
  
  # download the data
  df = try(download_daymet(start = 1980,
                           end = 1980,
                           internal = TRUE,
                           silent = TRUE))
  
  # download verbose and external
  df_ext = try(download_daymet(start = 1980,
                           end = 1980,
                           internal = FALSE,
                           path = tempdir(),
                           silent = FALSE))
  
  # download out of range data
  df_range = try(download_daymet(start = 1970,
                                 end = 1980,
                                 internal = TRUE,
                                 silent = TRUE))
  
  # create demo locations
  locations = data.frame(site = c("site1", "site2"),
                         lat = rep(36.0133, 2),
                         lon = rep(-84.2625, 2))
  
  # write csv to file
  write.table(locations, paste0(tempdir(),"/locations.csv"),
              sep = ",",
              col.names = TRUE,
              row.names = FALSE,
              quote = FALSE)
  
  # download out of range data
  df_batch = try(download_daymet_batch(file_location = paste0(tempdir(),
                                                              "/locations.csv"),
                                       start = 1980,
                                       end = 1980,
                                       internal = TRUE,
                                       silent = TRUE))
  
  # see if any of the runs failed
  check = !inherits(df, "try-error") &
          inherits(df_range,"try-error") &
          !inherits(df_ext, "try-error") &
          !inherits(df_batch, "try-error")
          
  # check if no error occured
  expect_true(check)
})

# # bounding box tile downloads
# test_that("download tiles by bounding box",{
#   
#   # download out of range data
#   df_bbox = try(download_daymet_tiles(location = c(18.9103,
#                                                    -114.6109,
#                                                    18.6703,
#                                                    -114.2181),
#                                       start = 1980,
#                                       end = 1980,
#                                       param = "tmin",
#                                       path = tempdir(),
#                                       silent = TRUE))
#   
#   # download by tile number for all data
#   df_tile_nr = try(download_daymet_tiles(tiles = 9753,
#                                       start = 1980,
#                                       end = 1980,
#                                       param = "ALL",
#                                       path = tempdir(),
#                                       silent = TRUE))
#   
#   # download out of range data
#   df_bbox_corrupt = try(download_daymet_tiles(location = c(18.9103,
#                                                            -114.6109,
#                                                            18.6703),
#                                               start = 1980,
#                                               end = 1980,
#                                               param = "tmin",
#                                               path = tempdir(),
#                                               silent = TRUE))
#   
#   # see if any of the runs failed
#   check = !inherits(df_bbox, "try-error") &
#           !inherits(df_tile_nr, "try-error") #&
#           #inherits(df_bbox_corrupt, "try-error")
#   
#   # check if no error occured
#   expect_true(check)
# })


# check single tile download and conversion to geotiff
test_that("tile download and format conversion checks",{
  
  # download the data
  try(download_daymet_ncss(param = "tmin",<commit_msg>bbox download set to silent = FALSE -- resolving Travis CI testthat issues?<commit_after># A complete set of daymetr unit tests
# to ensure that code changes do not break
# the functionality and download behaviour.
# This allows checks to see if server paths
# are still ok, and if overall the functions
# don't act up.

# standard pixel extraction test both single
# location and batch processing
test_that("pixel location download check",{
  
  # download the data
  df = try(download_daymet(start = 1980,
                           end = 1980,
                           internal = TRUE,
                           silent = TRUE))
  
  # download verbose and external
  df_ext = try(download_daymet(start = 1980,
                           end = 1980,
                           internal = FALSE,
                           path = tempdir(),
                           silent = FALSE))
  
  # download out of range data
  df_range = try(download_daymet(start = 1970,
                                 end = 1980,
                                 internal = TRUE,
                                 silent = TRUE))
  
  # create demo locations
  locations = data.frame(site = c("site1", "site2"),
                         lat = rep(36.0133, 2),
                         lon = rep(-84.2625, 2))
  
  # write csv to file
  write.table(locations, paste0(tempdir(),"/locations.csv"),
              sep = ",",
              col.names = TRUE,
              row.names = FALSE,
              quote = FALSE)
  
  # download out of range data
  df_batch = try(download_daymet_batch(file_location = paste0(tempdir(),
                                                              "/locations.csv"),
                                       start = 1980,
                                       end = 1980,
                                       internal = TRUE,
                                       silent = TRUE))
  
  # see if any of the runs failed
  check = !inherits(df, "try-error") &
          inherits(df_range,"try-error") &
          !inherits(df_ext, "try-error") &
          !inherits(df_batch, "try-error")
          
  # check if no error occured
  expect_true(check)
})

# bounding box tile downloads
test_that("download tiles by bounding box",{

  # download out of range data
  df_bbox = try(download_daymet_tiles(location = c(18.9103,
                                                   -114.6109,
                                                   18.6703,
                                                   -114.2181),
                                      start = 1980,
                                      end = 1980,
                                      param = "tmin",
                                      path = tempdir(),
                                      silent = FALSE))

  # download by tile number for all data
  df_tile_nr = try(download_daymet_tiles(tiles = 9753,
                                      start = 1980,
                                      end = 1980,
                                      param = "ALL",
                                      path = tempdir(),
                                      silent = FALSE))

  # download out of range data
  df_bbox_corrupt = try(download_daymet_tiles(location = c(18.9103,
                                                           -114.6109,
                                                           18.6703),
                                              start = 1980,
                                              end = 1980,
                                              param = "tmin",
                                              path = tempdir(),
                                              silent = FALSE))

  # see if any of the runs failed
  check = !inherits(df_bbox, "try-error") &
          !inherits(df_tile_nr, "try-error") &
          inherits(df_bbox_corrupt, "try-error")

  # check if no error occured
  expect_true(check)
})


# check single tile download and conversion to geotiff
test_that("tile download and format conversion checks",{
  
  # download the data
  try(download_daymet_ncss(param = "tmin",
{'fraction_non_alphanumeric': 0.08000969814522972, 'fraction_numerical': 0.029821796581403808, 'mean_word_length': 1.0048602673147022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 133, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '641458', 'n_tokens_mistral': 2128, 'n_tokens_neox': 1889, 'n_words': 545}