Skip to content

Commit

Permalink
Merge pull request #392 from atheo89/rstudio-test
Browse files Browse the repository at this point in the history
Add more test cases for R Studio notebook
  • Loading branch information
openshift-merge-bot[bot] authored Feb 9, 2024
2 parents daa9aaf + 75bd4a7 commit 395be20
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
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")
}

0 comments on commit 395be20

Please sign in to comment.