Skip to content

Commit

Permalink
moved test_that block
Browse files Browse the repository at this point in the history
  • Loading branch information
meetagrawal09 committed Sep 26, 2023
1 parent ce327b9 commit 92d1d38
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ test_download_AmerifluxLBL <- function(start_date, end_date, sitename, lat.in, l
lon.in = lon.in,
sitename = sitename
)
})

# checking if the file is downloaded
test_that("Downloaded files are present at the desired location", {
expect_true(file.exists(paste0(tmpdir, "/AMF_US-Akn_BASE_HH_6-5.csv")))
})

test_that("Downloaded data files have the right format", {
firstline <- system(paste0("head -4 ", paste0(tmpdir, "/AMF_US-Akn_BASE_HH_6-5.csv")), intern = TRUE)
lastline <- system(paste0("tail -1 ", paste0(tmpdir, "/AMF_US-Akn_BASE_HH_6-5.csv")), intern = TRUE)

# checking if first line of CSV has the sitename
expect_true(grepl(sitename, firstline[1]))

# fourth and last row checked to contain non-alphabetical data since these are used to verify start and end dates
expect_false(grepl("[A-Za-z]", firstline[4]))
expect_false(grepl("[A-Za-z]", lastline[1]))
# checking if the file is downloaded
test_that("Downloaded files are present at the desired location", {
expect_true(file.exists(paste0(tmpdir, "/AMF_US-Akn_BASE_HH_6-5.csv")))
})

test_that("Downloaded data files have the right format", {
firstline <- system(paste0("head -4 ", paste0(tmpdir, "/AMF_US-Akn_BASE_HH_6-5.csv")), intern = TRUE)
lastline <- system(paste0("tail -1 ", paste0(tmpdir, "/AMF_US-Akn_BASE_HH_6-5.csv")), intern = TRUE)

# checking if first line of CSV has the sitename
expect_true(grepl(sitename, firstline[1]))

# fourth and last row checked to contain non-alphabetical data since these are used to verify start and end dates
expect_false(grepl("[A-Za-z]", firstline[4]))
expect_false(grepl("[A-Za-z]", lastline[1]))
})
})
}

Expand Down
74 changes: 37 additions & 37 deletions modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,51 +37,51 @@ test_download_ERA5 <- function(start_date, end_date, lat.in, lon.in, product_typ
product_types = product_types,
reticulate_python = reticulate_python
)
})

test_that("All the required files are downloaded and stored at desired location", {
expect_true(file.exists(paste0(tmpdir, "/era5.2m_dewpoint_temperature.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.2m_temperature.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.10m_u_component_of_wind.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.10m_v_component_of_wind.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.surface_pressure.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.surface_solar_radiation_downwards.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.surface_thermal_radiation_downwards.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.total_precipitation.nc")))
})

test_that("All the required files are downloaded and stored at desired location", {
expect_true(file.exists(paste0(tmpdir, "/era5.2m_dewpoint_temperature.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.2m_temperature.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.10m_u_component_of_wind.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.10m_v_component_of_wind.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.surface_pressure.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.surface_solar_radiation_downwards.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.surface_thermal_radiation_downwards.nc")))
expect_true(file.exists(paste0(tmpdir, "/era5.total_precipitation.nc")))
})

test_that("All ERA5 data files have the correct variable units", {
nc <- nc_open(paste0(tmpdir, "/era5.2m_dewpoint_temperature.nc"))
expect_equal(nc$var$d2m$units, "K")
nc_close(nc)
test_that("All ERA5 data files have the correct variable units", {
nc <- nc_open(paste0(tmpdir, "/era5.2m_dewpoint_temperature.nc"))
expect_equal(nc$var$d2m$units, "K")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.2m_temperature.nc"))
expect_equal(nc$var$t2m$units, "K")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.2m_temperature.nc"))
expect_equal(nc$var$t2m$units, "K")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.10m_u_component_of_wind.nc"))
expect_equal(nc$var$u10$units, "m s**-1")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.10m_u_component_of_wind.nc"))
expect_equal(nc$var$u10$units, "m s**-1")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.10m_v_component_of_wind.nc"))
expect_equal(nc$var$v10$units, "m s**-1")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.10m_v_component_of_wind.nc"))
expect_equal(nc$var$v10$units, "m s**-1")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.surface_pressure.nc"))
expect_equal(nc$var$sp$units, "Pa")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.surface_pressure.nc"))
expect_equal(nc$var$sp$units, "Pa")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.surface_solar_radiation_downwards.nc"))
expect_equal(nc$var$ssrd$units, "J m**-2")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.surface_solar_radiation_downwards.nc"))
expect_equal(nc$var$ssrd$units, "J m**-2")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.surface_thermal_radiation_downwards.nc"))
expect_equal(nc$var$strd$units, "J m**-2")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.surface_thermal_radiation_downwards.nc"))
expect_equal(nc$var$strd$units, "J m**-2")
nc_close(nc)

nc <- nc_open(paste0(tmpdir, "/era5.total_precipitation.nc"))
expect_equal(nc$var$tp$units, "m")
nc_close(nc)
nc <- nc_open(paste0(tmpdir, "/era5.total_precipitation.nc"))
expect_equal(nc$var$tp$units, "m")
nc_close(nc)
})
})
}

Expand Down

0 comments on commit 92d1d38

Please sign in to comment.