Skip to content

Commit

Permalink
Add local unit tests for 'job_info'. Exclude from GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Eagles committed Oct 13, 2023
1 parent 1314607 commit 353732e
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/testthat/test-job_info.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# All tests here are tested locally and not as part of the usual GHA CI
# workflow, since SLURM isn't available on the cloud machines

test_that(
"job_info_null_user_partition",
{
# Don't test on GHA, where SLURM isn't available
skip_on_ci()

job_df = job_info(user = NULL, partition = NULL)

# Memory should be defined for a user's jobs
any_mem_na = job_df |>
filter(user == Sys.getenv("USER")) |>
select(max_rss_gb, max_vmem_gb) |>
is.na() |>
any()
expect_equal(any_mem_na, FALSE)

# Most columns should never have NA values
any_other_na = job_df |>
select(
job_id, user, name, partition, cpus, requested_mem_gb, status
) |>
is.na() |>
any()
expect_equal(any_other_na, FALSE)

# There should be more than one user and partition since user = NULL
# and partition = NULL (well, except in extremely unlikely cases)
expect_equal(length(unique(job_df$user)) > 1, TRUE)
expect_equal(length(unique(job_df$partition)) > 1, TRUE)
}
)

test_that(
"job_info_data_types",
{
# Don't test on GHA, where SLURM isn't available
skip_on_ci()

job_df = job_info(user = NULL, partition = NULL)

# Compare expected vs. actual data types for each expected column
expected_types = c(
job_id = 'numeric', max_rss_gb = 'numeric', max_vmem_gb = 'numeric',
user = 'character', array_task_id = 'integer', name = 'character',
partition = 'factor', cpus = 'integer',
requested_mem_gb = 'numeric', status = 'factor'
)
expected_types = unname(expected_types[colnames(job_df)])

actual_types = job_df |>
summarize_all(class) |>
as.character()

expect_equal(expected_types, actual_types)
}
)

test_that(
"job_info_defined_user_partition",
{
# Don't test on GHA, where SLURM isn't available
skip_on_ci()

job_df = job_info(user = Sys.getenv("USER"), partition = "shared")
expect_equal(unique(job_df$user), Sys.getenv("USER"))
expect_equal(unique(job_df$partition), factor("shared"))
}
)

0 comments on commit 353732e

Please sign in to comment.