Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve animint2pages by automatically taking screenshot of the animint #131

Merged
merged 47 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
73d540f
Chromote session nit
siddhesh195 Jun 12, 2024
a3e9ae5
Update DESCRIPTION
siddhesh195 Jun 18, 2024
c0e6f23
Update tests.yaml
siddhesh195 Jun 18, 2024
492fd17
Update z_pages.R
siddhesh195 Jun 19, 2024
a466f94
Update z_pages.R
siddhesh195 Jun 21, 2024
fde4ea0
corrected variable name
siddhesh195 Jun 21, 2024
d3617dc
changed from captureScreenshot() to screenshot()
siddhesh195 Jun 23, 2024
de2a97f
added new test to check screenshot in ghpages
siddhesh195 Jun 24, 2024
348cd0e
corrected hardcoded repo owner name to actual repo owner during the test
siddhesh195 Jun 24, 2024
6872e8d
corrected hardcoded repo name to actual repo name during the test
siddhesh195 Jun 24, 2024
bfc1b89
test if gh-pages branch exist
siddhesh195 Jun 24, 2024
a358ad3
saved screenshot to local directory
siddhesh195 Jun 24, 2024
07596ac
Add file name screenshot.png to the path to query
siddhesh195 Jun 24, 2024
fc2bdca
Remove try..catch
siddhesh195 Jun 24, 2024
04d28e2
Add gh to suggests and tests.yaml
siddhesh195 Jun 24, 2024
439dd85
Load library gh
siddhesh195 Jun 24, 2024
de1e12c
code for server pointing to temp directory
siddhesh195 Jun 29, 2024
80c2da3
added magick in suggests
siddhesh195 Jun 29, 2024
1ec415b
added magick in suggests
siddhesh195 Jun 30, 2024
c1f5560
testing on github actions
siddhesh195 Jul 1, 2024
12941ab
Use random port Ids to solve mac error
siddhesh195 Jul 1, 2024
2653f9b
added cropping feature
siddhesh195 Jul 3, 2024
5a2523f
start common server and copy new files to it's directory
siddhesh195 Jul 4, 2024
1f834d1
removed cropping feature for debugging
siddhesh195 Jul 4, 2024
1bf1937
pass server directory into animint2dir
siddhesh195 Jul 4, 2024
baabd4f
fixed server error, updated version, added NEWS
siddhesh195 Jul 6, 2024
dec0650
corrected name of the function
siddhesh195 Jul 10, 2024
8241ea8
removed duplicate lines and whitespaces
siddhesh195 Jul 12, 2024
7569a7c
Merge branch 'master' into screenshot-animint2pages
siddhesh195 Aug 29, 2024
de42e29
removed empty line
siddhesh195 Aug 29, 2024
82c998c
removed empty line
siddhesh195 Aug 29, 2024
20bd120
screenshot excludes widgets
Aug 29, 2024
fc23ea2
animint2pages example add title, source, color
Aug 29, 2024
75bf982
added empty line and space
siddhesh195 Aug 29, 2024
c6e28c7
Merge branch 'master' into screenshot-animint2pages
siddhesh195 Aug 31, 2024
3b98e9c
test passes without persistent server
tdhock Sep 1, 2024
c7dca84
Remove empty lines
siddhesh195 Sep 14, 2024
b12a42f
Refactor to reuse start_server
siddhesh195 Sep 15, 2024
445cbc4
Delete persistent server
siddhesh195 Sep 15, 2024
2603e3b
Stop the server after capturing screensjot
siddhesh195 Sep 17, 2024
0d88a28
Merge branch 'master' into screenshot-animint2pages
siddhesh195 Sep 17, 2024
9375dca
Increment version
siddhesh195 Sep 18, 2024
87e3324
Merge branch 'screenshot-animint2pages' of https://github.com/animint…
siddhesh195 Sep 18, 2024
1b81662
Delete stop_binary, check that package is loaded before taking screen…
siddhesh195 Sep 19, 2024
1f7e933
Fix test error
siddhesh195 Sep 19, 2024
f336ee4
removed additional arguments
siddhesh195 Sep 29, 2024
3338cf5
Rename stop_server to stop_servr
siddhesh195 Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions tests/testthat/test-compiler-ghpages.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
acontext("GitHub Pages")
library(gh)
server <- function() {
out.dir <- tempfile()
dir.create(out.dir, showWarnings=FALSE, recursive=TRUE)
portNum <- 8080
normDir <- normalizePath(out.dir, winslash = "/", mustWork = TRUE)
code = sprintf("servr::httd(dir='%s', port=%d)", normDir,portNum)
system2("Rscript", c("-e", shQuote(code)), wait = FALSE)
return(list(output.dir = normDir))
}

s<-server()

library(animint2)
viz <- animint(
title="one to ten",
Expand All @@ -23,15 +10,15 @@ test_that("error for viz with no title", {
viz.no.title <- viz
viz.no.title$title <- NULL
expect_error({
animint2pages(viz.no.title, "no-title",server=s)
animint2pages(viz.no.title, "no-title")
siddhesh195 marked this conversation as resolved.
Show resolved Hide resolved
}, "plot.list does not contain option named title, which is required by animint2pages")
})

test_that("error for viz with no source", {
viz.no.source <- viz
viz.no.source$source <- NULL
expect_error({
animint2pages(viz.no.source, "no-source",server=s)
animint2pages(viz.no.source, "no-source")
}, "plot.list does not contain option named source, which is required by animint2pages")
})

Expand All @@ -58,6 +45,10 @@ test_that("animint2pages() returns list of meta-data", {
get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*tsv"))
tsv_files_created <- get_tsv(result_list)
expect_equal(length(tsv_files_created), 1)
expect_Capture <- function(L){
expect_gt(file.size(file.path(L$local_clone,"Capture.PNG")), 0)
}
expect_Capture(result_list)
## second run of animint2pages updates data viz.
viz.more <- viz
viz.more$five <- ggplot()+
Expand All @@ -67,21 +58,7 @@ test_that("animint2pages() returns list of meta-data", {
update_list <- animint2pages(viz.more, "animint2pages_test_repo", owner="animint-test")
tsv_files_updated <- get_tsv(update_list)
expect_equal(length(tsv_files_updated), 2)
})

test_that("check if animint2pages() successfully uploads screenshot", {

viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo",server=s)
split_viz_owner_repo <- strsplit(viz_owner_repo, "/")[[1]]
repo_owner <- split_viz_owner_repo[1]
repo_name <- split_viz_owner_repo[2]

file_exists <- {
gh("GET /repos/:owner/:repo/contents/:path",
owner = repo_owner, repo = repo_name, path = "Capture.PNG",ref ="gh-pages")
TRUE # If the call succeeds, the file exists
}
expect_true(file_exists, info = "The screenshot should exist in the repository.")
expect_Capture(update_list)
})

test_that("animint2pages raises an error if no GitHub token is present", {
Expand All @@ -97,7 +74,7 @@ test_that("animint2pages raises an error if no GitHub token is present", {
file.copy(config.file, config.old, overwrite = TRUE)
cat("[credential]\n\tusername = FOO", file=config.file, append=TRUE)
expect_error({
animint2pages(viz, github_repo = "test_repo",server=s)
animint2pages(viz, github_repo = "test_repo")
}, "A GitHub token is required to create and push to a new repository. \nTo create a GitHub token, follow these steps:\n1. Go to https://github.com/settings/tokens/new?scopes=repo&description=animint2pages\n2. Confirm your password if prompted.\n3. Ensure that the 'repo' scope is checked.\n4. Click 'Generate token' at the bottom of the page.\n5. Copy the generated token.\nAfter creating the token, you can set it up in your R environment by running: \nSys.setenv(GITHUB_PAT=\"yourGithubPAT\") \ngert::git_config_global_set(\"user.name\", \"yourUserName\") \ngert::git_config_global_set(\"user.email\", \"yourEmail\") \n", fixed=TRUE)
do.call(Sys.setenv, as.list(env.old))
file.copy(config.old, config.file, overwrite = TRUE)
Expand Down
Loading