From 1828ce4b8fd653e81601e1450cf580c505846c32 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Wed, 11 Dec 2024 11:42:08 +0000 Subject: [PATCH 1/2] Add withr wrappers for verbose envar. --- tests/testthat/test-process_repos.R | 38 ++++++++++++++--------------- tests/testthat/test-set_repos.R | 23 ++++++++--------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tests/testthat/test-process_repos.R b/tests/testthat/test-process_repos.R index fc8767a..2735cb9 100644 --- a/tests/testthat/test-process_repos.R +++ b/tests/testthat/test-process_repos.R @@ -1,22 +1,22 @@ test_that("process_repos() returns results with repo metadata", { - verbose_off() + withr::with_envvar(new = c("GITAI_VERBOSE" = FALSE), { + my_project <- initialize_project("gitai_test_project") |> + set_github_repos( + repos = c("r-world-devs/GitStats", "openpharma/DataFakeR") + ) |> + add_files(files = "README.md") |> + set_llm() |> + set_prompt(system_prompt = "Summarize the user content if one sentence.") + results <- my_project |> process_repos() - my_project <- initialize_project("gitai_test_project") |> - set_github_repos( - repos = c("r-world-devs/GitStats", "openpharma/DataFakeR") - ) |> - add_files(files = "README.md") |> - set_llm() |> - set_prompt(system_prompt = "Summarize the user content if one sentence.") - results <- my_project |> process_repos() - - expect_true(is.list(results)) - expect_equal(c("GitStats", "DataFakeR"), names(results)) - expect_true( - results |> - purrr::map(~ nchar(.x$text) > 10) |> - unlist() |> - all() - ) - results |> purrr::walk(~ expect_true("metadata" %in% names(.))) + expect_true(is.list(results)) + expect_equal(c("GitStats", "DataFakeR"), names(results)) + expect_true( + results |> + purrr::map(~ nchar(.x$text) > 10) |> + unlist() |> + all() + ) + results |> purrr::walk(~ expect_true("metadata" %in% names(.))) + }) }) diff --git a/tests/testthat/test-set_repos.R b/tests/testthat/test-set_repos.R index d6f3e3c..b6ae5bb 100644 --- a/tests/testthat/test-set_repos.R +++ b/tests/testthat/test-set_repos.R @@ -1,15 +1,16 @@ test_that("set_*_repos creates GitStats object inside GitAI with repos set", { - verbose_off() - my_project <- initialize_project("gitai_test_project") + withr::with_envvar(new = c("GITAI_VERBOSE" = FALSE), { + my_project <- initialize_project("gitai_test_project") - my_project <- my_project |> - set_github_repos(repos = c("r-world-devs/GitStats", "openpharma/DataFakeR")) - expect_true("GitStats" %in% class(my_project$gitstats)) + my_project <- my_project |> + set_github_repos(repos = c("r-world-devs/GitStats", "openpharma/DataFakeR")) + expect_true("GitStats" %in% class(my_project$gitstats)) - my_project <- my_project |> - set_gitlab_repos(repos = "mbtests/gitstatstesting") - expect_length( - my_project$gitstats$.__enclos_env__$private$hosts, - 2 - ) + my_project <- my_project |> + set_gitlab_repos(repos = "mbtests/gitstatstesting") + expect_length( + my_project$gitstats$.__enclos_env__$private$hosts, + 2 + ) + }) }) From 0c7ab89bbd77c74fd53acf4a0c9c144ca753ff8c Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Wed, 11 Dec 2024 11:56:51 +0000 Subject: [PATCH 2/2] Update after review, fix checks with setting withr in suggests. --- DESCRIPTION | 3 ++- tests/testthat/test-process_repos.R | 37 ++++++++++++++--------------- tests/testthat/test-set_repos.R | 23 +++++++++--------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9e4d4e2..ed07f05 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,6 +26,7 @@ Imports: rlang, glue Suggests: - testthat (>= 3.0.0) + testthat (>= 3.0.0), + withr Config/testthat/edition: 3 Config/testthat/parallel: true diff --git a/tests/testthat/test-process_repos.R b/tests/testthat/test-process_repos.R index 2735cb9..d833f48 100644 --- a/tests/testthat/test-process_repos.R +++ b/tests/testthat/test-process_repos.R @@ -1,22 +1,21 @@ test_that("process_repos() returns results with repo metadata", { - withr::with_envvar(new = c("GITAI_VERBOSE" = FALSE), { - my_project <- initialize_project("gitai_test_project") |> - set_github_repos( - repos = c("r-world-devs/GitStats", "openpharma/DataFakeR") - ) |> - add_files(files = "README.md") |> - set_llm() |> - set_prompt(system_prompt = "Summarize the user content if one sentence.") - results <- my_project |> process_repos() + withr::local_envvar(new = c("GITAI_VERBOSE" = FALSE)) + my_project <- initialize_project("gitai_test_project") |> + set_github_repos( + repos = c("r-world-devs/GitStats", "openpharma/DataFakeR") + ) |> + add_files(files = "README.md") |> + set_llm() |> + set_prompt(system_prompt = "Summarize the user content if one sentence.") + results <- my_project |> process_repos() - expect_true(is.list(results)) - expect_equal(c("GitStats", "DataFakeR"), names(results)) - expect_true( - results |> - purrr::map(~ nchar(.x$text) > 10) |> - unlist() |> - all() - ) - results |> purrr::walk(~ expect_true("metadata" %in% names(.))) - }) + expect_true(is.list(results)) + expect_equal(c("GitStats", "DataFakeR"), names(results)) + expect_true( + results |> + purrr::map(~ nchar(.x$text) > 10) |> + unlist() |> + all() + ) + results |> purrr::walk(~ expect_true("metadata" %in% names(.))) }) diff --git a/tests/testthat/test-set_repos.R b/tests/testthat/test-set_repos.R index b6ae5bb..377bb93 100644 --- a/tests/testthat/test-set_repos.R +++ b/tests/testthat/test-set_repos.R @@ -1,16 +1,15 @@ test_that("set_*_repos creates GitStats object inside GitAI with repos set", { - withr::with_envvar(new = c("GITAI_VERBOSE" = FALSE), { - my_project <- initialize_project("gitai_test_project") + withr::local_envvar(new = c("GITAI_VERBOSE" = FALSE)) + my_project <- initialize_project("gitai_test_project") - my_project <- my_project |> - set_github_repos(repos = c("r-world-devs/GitStats", "openpharma/DataFakeR")) - expect_true("GitStats" %in% class(my_project$gitstats)) + my_project <- my_project |> + set_github_repos(repos = c("r-world-devs/GitStats", "openpharma/DataFakeR")) + expect_true("GitStats" %in% class(my_project$gitstats)) - my_project <- my_project |> - set_gitlab_repos(repos = "mbtests/gitstatstesting") - expect_length( - my_project$gitstats$.__enclos_env__$private$hosts, - 2 - ) - }) + my_project <- my_project |> + set_gitlab_repos(repos = "mbtests/gitstatstesting") + expect_length( + my_project$gitstats$.__enclos_env__$private$hosts, + 2 + ) })