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

Add more test cases for R Studio notebook #392

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 26 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -431,22 +431,45 @@ validate-codeserver-image: bin/kubectl
.PHONY: validate-rstudio-image
validate-rstudio-image: bin/kubectl
$(eval NOTEBOOK_NAME := $(subst .,-,$(subst cuda-,,$*)))
$(info # Running tests for $(NOTEBOOK_NAME) code-server image...)
$(info # Running tests for $(NOTEBOOK_NAME) RStudio Server image...)
$(KUBECTL_BIN) wait --for=condition=ready pod rstudio-pod --timeout=300s
@required_commands=$(REQUIRED_R_STUDIO_IMAGE_COMMANDS) ; \
if [[ $$image == "" ]] ; then \
echo "Usage: make validate-rstudio-image image=<container-image-name>" ; \
exit 1 ; \
fi ; \
echo "=> Checking container image $$image for package intallation..." ; \
$(KUBECTL_BIN) exec -it rstudio-pod -- mkdir -p /opt/app-root/src/R/temp-library > /dev/null 2>&1 ; \
$(KUBECTL_BIN) exec rstudio-pod -- R -e "install.packages('tinytex', lib='/opt/app-root/src/R/temp-library')" > /dev/null 2>&1 ; \
if [ $$? -eq 0 ]; then \
echo "Tinytex installation successful!"; \
else \
echo "Error: Tinytex installation failed."; \
fi; \
for cmd in $$required_commands ; do \
echo "=> Checking container image $$image for $$cmd..." ; \
$(KUBECTL_BIN) exec rstudio-pod which $$cmd > /dev/null 2>&1 ; \
if [ $$? -ne 0 ]; then \
echo "ERROR: Container image $$image does not meet criteria for command: $$cmd" ; \
if [ $$? -eq 0 ]; then \
echo "$$cmd executed successfuly!"; \
else \
echo "ERROR: Container image $$image does not meet criteria for command: $$cmd" ; \
fail=1; \
continue; \
fi; \
done ; \
echo "=> Fetching R script from URL and executing on the container..."; \
curl -sSL -o test_script.R "${NOTEBOOK_REPO_BRANCH_BASE}/rstudio/c9s-python-3.9/test/test_script.R" > /dev/null 2>&1 ; \
$(KUBECTL_BIN) cp test_script.R rstudio-pod:/opt/app-root/src/test_script.R > /dev/null 2>&1; \
$(KUBECTL_BIN) exec rstudio-pod -- Rscript /opt/app-root/src/test_script.R > /dev/null 2>&1 ; \
if [ $$? -eq 0 ]; then \
echo "R script executed successfully!"; \
rm test_script.R ; \
else \
echo "Error: R script failed."; \
fail=1; \
continue; \
fi; \


# This is only for the workflow action
.PHONY: refresh-pipfilelock-files
Expand Down
23 changes: 23 additions & 0 deletions rstudio/c9s-python-3.9/test/test_script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Set a seed for reproducibility
set.seed(123)

# Generate a random dataset
x <- rnorm(100)
data <- data.frame(
x = x,
y = 2 * x + rnorm(100)
)
if ("x" %in% colnames(data) && is.numeric(data$x) &&
"y" %in% colnames(data) && is.numeric(data$y)) {
# Compute basic statistics
mean_x <- mean(data$x, na.rm = TRUE)
mean_y <- mean(data$y, na.rm = TRUE)
correlation <- cor(data$x, data$y, use = "complete.obs")
# Print the statistics
cat("Mean of x:", mean_x, "\n")
cat("Mean of y:", mean_y, "\n")
cat("Correlation between x and y:", correlation, "\n")

} else {
cat("Error: Columns 'x' and 'y' must be numeric and exist in the dataset.\n")
}
Loading