-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4149fde
commit df65c04
Showing
6 changed files
with
114 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
sas_username <- "u63378825" | ||
test_number <- ceiling(runif(1, 0, 10000000)) # helps make sure CI tests don't interfere with one another | ||
sas_connect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
test_that("test connection", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
|
||
expect_no_error(sas_connect()) | ||
"connected connection" | ||
expect_no_error(chk_connection()) | ||
|
||
expect_no_error(sas_connect("oda")) | ||
"disconnection" | ||
expect_message(sas_disconnect(), "SAS Connection terminated.") | ||
expect_null(sas_get_session()) | ||
|
||
expect_no_error(sas_get_session()) | ||
"disconnected connection" | ||
expect_error(chk_connection(), "No active SAS session.") | ||
|
||
expect_no_error(sas_disconnect()) | ||
"connection" | ||
expect_message(sas_connect(), "SAS Connection established.") | ||
expect_s3_class(sas_get_session(), c("saspy.sasbase.SASsession", "python.builtin.object")) | ||
|
||
expect_error(sas_disconnect()) | ||
|
||
expect_error(sas_get_session()) | ||
"specifying connection config" | ||
expect_message(sas_connect("oda"), "SAS Connection established.") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
test_that("SAS to R data.frame", { | ||
test_that("Back and forth", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
|
||
sas_connect() | ||
|
||
iris_sas <- sas_to_r("iris", "sashelp") | ||
|
||
# processing to get SAS and R data frames the same | ||
data(iris) | ||
names(iris_sas) <- c("Species", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width") | ||
iris_sas <- iris_sas[c(2:5, 1)] | ||
iris <- iris[order(iris$Species, iris$Sepal.Length, iris$Sepal.Width, iris$Petal.Length, iris$Petal.Width), ] | ||
iris_sas <- iris_sas[order(iris_sas$Species, iris_sas$Sepal.Length, iris_sas$Sepal.Width, iris_sas$Petal.Length, iris_sas$Petal.Width), ] | ||
iris_sas[1:4] <- iris_sas[1:4] / 10 | ||
iris$Species <- as.character(iris$Species) | ||
iris_sas$Species <- tolower(iris_sas$Species) | ||
rownames(iris) <- NULL | ||
rownames(iris_sas) <- NULL | ||
|
||
expect_equal(iris, iris_sas) | ||
|
||
sas_disconnect() | ||
}) | ||
|
||
test_that("R to SAS data.frame", { | ||
skip_if_offline() | ||
|
||
sas_connect() | ||
|
||
data(iris) | ||
r_to_sas(iris, "iris") | ||
iris_sas <- sas_to_r("iris") | ||
|
||
# processing to get SAS and R data frames the same | ||
attr(iris_sas, "pandas.index") <- NULL | ||
iris$Species <- as.character(iris$Species) | ||
|
||
expect_equal(iris, iris_sas) | ||
|
||
sas_disconnect() | ||
|
||
df_all <- data.frame( | ||
a = c(1, 2.5, NA), | ||
b = c(1:2, NA), | ||
c = c(T, F, NA), | ||
d = c("a", "b", NA), | ||
e = factor(c("a", "b", NA)), | ||
f = as.Date("2015-12-09") + c(1:2, NA), | ||
g = as.POSIXct("2015-12-09 10:51:34.5678", tz = "UTC") + c(1:2, NA), | ||
h = I(as.list(c(1:2, NA))), | ||
i = I(list(list(1, 2:3), list(4:6), list(NA))) | ||
) | ||
|
||
"list columns: R to SAS" | ||
expect_error(r_to_sas(df_all, "df"), "must only have logical, integer, double, factor, character, POSIXct, or Date class columns") | ||
|
||
"valid columns: R to SAS" | ||
df <- df_all[!sapply(df_all, is.list)] | ||
expect_equal(r_to_sas(df, "df"), df) | ||
|
||
"rownames: R to SAS" | ||
rownames(df) <- paste("row", 1:3) | ||
expect_warning(r_to_sas(df, "df"), "rownames will not be transferred as a column") | ||
rownames(df) <- NULL | ||
|
||
"back to R check" | ||
df_from_sas <- sas_to_r("df") | ||
df_from_sas$f <- as.Date(as.POSIXct(df_from_sas$f, tz = "UTC")) | ||
df_from_sas$g <- as.POSIXct(df_from_sas$g, tz = "UTC") | ||
df$c <- as.double(df$c) | ||
df$e <- as.character(df$e) | ||
expect_equal(df_from_sas, df) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
test_that("uploading and downloading to SAS", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
skip_if(sas_get_session()$sascfg$name != "oda") | ||
|
||
local_path <- tempfile(pattern="temp", fileext=".sas") | ||
local_name <- basename(local_path) | ||
sas_path <- paste0("~/", local_name) | ||
|
||
"no file exists upload" | ||
expect_error(sas_file_upload(local_path, sas_path), "must specify an existing file") | ||
|
||
"file exists upload" | ||
cat("PROC MEANS DATA = sashelp.cars; RUN;", file = local_path) | ||
expect_true(sas_file_upload(local_path, sas_path)) | ||
expect_true(sas_file_exists(sas_path)) | ||
|
||
"file download" | ||
file.remove(local_path) | ||
expect_true(sas_file_download(sas_path, local_path)) | ||
expect_true(file.exists(local_path)) | ||
}) | ||
|
||
test_that("removing file from SAS", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
skip_if(sas_get_session()$sascfg$name != "oda") | ||
|
||
local_path <- tempfile(pattern="temp", fileext=".sas") | ||
local_name <- basename(local_path) | ||
sas_path <- paste0("~/", local_name) | ||
|
||
"no file exists removal" | ||
expect_warning(sas_file_remove(sas_path)) | ||
|
||
"file exists removal" | ||
cat("PROC MEANS DATA = sashelp.cars; RUN;", file = local_path) | ||
sas_file_upload(local_path, sas_path) | ||
expect_true(sas_file_remove(sas_path)) | ||
expect_false(sas_file_exists(sas_path)) | ||
}) | ||
|
||
|
||
test_that("copying file on SAS", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
skip_if(sas_get_session()$sascfg$name != "oda") | ||
|
||
local_path <- tempfile(pattern="temp", fileext=".sas") | ||
local_name <- basename(local_path) | ||
sas_path <- paste0("~/", local_name) | ||
sas_copy_path <- gsub(".sas", "_copy.sas", sas_path, fixed = TRUE) | ||
|
||
"no file exists copy" | ||
expect_warning(sas_file_copy(sas_path, sas_copy_path)) | ||
|
||
"file exists copy" | ||
cat("PROC MEANS DATA = sashelp.cars; RUN;", file = local_path) | ||
sas_file_upload(local_path, sas_path) | ||
expect_true(sas_file_copy(sas_path, sas_copy_path)) | ||
expect_true(sas_file_exists(sas_path)) | ||
expect_true(sas_file_exists(sas_copy_path)) | ||
|
||
# clean up | ||
sas_file_remove(sas_path) | ||
sas_file_remove(sas_copy_path) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.