Skip to content

Commit

Permalink
tests use config.list
Browse files Browse the repository at this point in the history
  • Loading branch information
Miachol committed May 24, 2017
1 parent da4f2c1 commit 10afb8d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ get.config.value <- function(file = "", value = NULL, config = "", config.list =
config.list <- config.list[[config]]
attr(config.list, "config") <- config
attr(config.list, "configtype") <- get.config.type(file, ...)
attr(config.list, "file") <- normalizePath(file, mustWork = FALSE)
attr(config.list, "file") <- normalizePath(file, "/", mustWork = FALSE)
} else {
config.list <- config.list[[config]][[value]]
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [![Build Status](https://travis-ci.org/Miachol/configr.svg)](https://travis-ci.org/Miachol/configr) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://en.wikipedia.org/wiki/MIT_License) [![CRAN](http://www.r-pkg.org/badges/version/configr)](https://cran.r-project.org/package=configr) [![Downloads](http://cranlogs.r-pkg.org/badges/configr?color=brightgreen)](http://www.r-pkg.org/pkg/configr) [![codecov](https://codecov.io/github/Miachol/configr/branch/master/graphs/badge.svg)](https://codecov.io/github/Miachol/configr)
# [![Build Status](https://travis-ci.org/Miachol/configr.svg)](https://travis-ci.org/Miachol/configr) [![CRAN](http://www.r-pkg.org/badges/version/configr)](https://cran.r-project.org/package=configr) [![Downloads](http://cranlogs.r-pkg.org/badges/configr?color=brightgreen)](http://www.r-pkg.org/pkg/configr) [![codecov](https://codecov.io/github/Miachol/configr/branch/master/graphs/badge.svg)](https://codecov.io/github/Miachol/configr)

configr package
==============
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_a_configtype.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ config.yaml <- system.file("extdata", "config.yaml", package = "configr")
config.ini <- system.file("extdata", "config.ini", package = "configr")
config.toml <- system.file("extdata", "config.toml", package = "configr")
config.error <- system.file("extdata", "config.error.yaml", package = "configr")
config.list <- list(json = config.json, yaml = config.yaml, ini = config.ini, toml = config.toml)

test_that("Configtype Specificity", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("x <- get.config.type(config.%s)", i, i)
eval(parse(text = rcmd.text))
x <- get.config.type(config.list[[i]])
expect_that(x, equals(i))

x <- NULL
Expand Down
26 changes: 7 additions & 19 deletions tests/testthat/test_b_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ config.yaml <- system.file("extdata", "config.yaml", package = "configr")
config.ini <- system.file("extdata", "config.ini", package = "configr")
config.toml <- system.file("extdata", "config.toml", package = "configr")
config.error.toml <- system.file("extdata", "config.error.toml", package = "configr")
config.list <- list(json = config.json, yaml = config.yaml, ini = config.ini, toml = config.toml)

test_that("read.config Function", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("x <- read.config(config.%s)", i)
eval(parse(text = rcmd.text))
x <- read.config(config.list[[i]])
expect_that(is.list(x) && length(x) >= 1, equals(TRUE))
}
})

test_that("read.config using extra.list parse", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("x <- read.config(config.%s, extra.list = list(debug = \"TRUE\"))",
i)
eval(parse(text = rcmd.text))
x <- read.config(config.list[[i]], extra.list = list(debug = "TRUE"))
expect_that(is.list(x) && length(x) >= 1, equals(TRUE))
parsed.value <- x$default$debug
expect_that(parsed.value, equals("TRUE {{debug2}}"))
Expand All @@ -30,26 +26,20 @@ test_that("read.config using extra.list parse", {
test_that("eval.config Function", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("config.path <- config.%s; x <- eval.config(file = config.%s)",
i, i)
eval(parse(text = rcmd.text))
x <- eval.config(file = config.list[[i]])
expect_that(is.list(x) && length(x) >= 1, equals(TRUE))
expect_that(attributes(x)$config, equals("default"))
expect_that(attributes(x)$configtype, equals(i))
file.attr <- attributes(x)$file
expect_that(is.character(file.attr), equals(TRUE))
expect_that(file.attr, equals(config.path))
expect_that(file.attr, equals(config.list[[i]]))
}
})

test_that("eval.config using extra.list parse", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("x <- eval.config(file = config.%s, extra.list = list(debug = \"TRUE\"))",
i)
eval(parse(text = rcmd.text))
x <- eval.config(file = config.list[[i]], extra.list = list(debug = "TRUE"))
expect_that(is.list(x) && length(x) >= 1, equals(TRUE))
parsed.value <- x$debug
expect_that(parsed.value, equals("TRUE {{debug2}}"))
Expand All @@ -59,9 +49,7 @@ test_that("eval.config using extra.list parse", {
test_that("eval.config.sections Function", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("x <- eval.config.sections(file = config.%s)", i)
eval(parse(text = rcmd.text))
x <- eval.config.sections(config.list[[i]])
expect_that(length(x) > 1, equals(TRUE))
expect_that("default" %in% x, equals(TRUE))
}
Expand Down
13 changes: 4 additions & 9 deletions tests/testthat/test_c_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ config.yaml <- system.file("extdata", "config.yaml", package = "configr")
config.ini <- system.file("extdata", "config.ini", package = "configr")
config.toml <- system.file("extdata", "config.toml", package = "configr")
config.error.toml <- system.file("extdata", "config.error.toml", package = "configr")
config.list <- list(json = config.json, yaml = config.yaml, ini = config.ini, toml = config.toml)

test_that("config.list.merge Function", {
list.left <- list(a = c(123, 123), b = c(4, 5, 6))
Expand All @@ -14,17 +15,11 @@ test_that("config.list.merge Function", {
test_that("eval.config.merge Function", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
x <- NULL
rcmd.text <- sprintf("x <- eval.config.merge(file = config.%s)", i)
eval(parse(text = rcmd.text))
x <- eval.config.merge(file = config.list[[i]])
expect_that(attributes(x)$config, equals(eval.config.sections(attributes(x)$file)))
rcmd.text <- sprintf("x <- eval.config.merge(file = config.%s, sections = \"comments\")",
i)
eval(parse(text = rcmd.text))
x <- eval.config.merge(file = config.list[[i]], sections = "comments")
expect_that(attributes(x)$config, equals("comments"))
rcmd.text <- sprintf("x <- eval.config.merge(file = config.%s, sections = c(\"default\", \"comments\"))",
i)
eval(parse(text = rcmd.text))
x <- eval.config.merge(file = config.list[[i]], sections = c("default", "comments"))
expect_that(attributes(x)$config, equals(c("default", "comments")))
}
})
Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test_e_convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ config.json <- system.file("extdata", "config.json", package = "configr")
config.yaml <- system.file("extdata", "config.yaml", package = "configr")
config.ini <- system.file("extdata", "config.ini", package = "configr")
config.toml <- system.file("extdata", "config.toml", package = "configr")

config.list <- list(json = config.json, yaml = config.yaml, ini = config.ini, toml = config.toml)
test_that("convert.config Function", {
config.opts <- c("json", "ini", "yaml", "toml")
for (i in config.opts) {
for (j in config.opts[!config.opts %in% c(i, "toml")]) {
out.fn <- sprintf("%s/test.convert.%s", tempdir(), j)
rcmd.text <- sprintf("x <- convert.config(file = config.%s, out.file = \"%s\", convert.to = \"%s\")",
i, out.fn, j)
eval(parse(text = rcmd.text))
x <- convert.config(file = config.list[[i]], out.file = out.fn, convert.to = j)
expect_that(x, equals(TRUE))
expect_that(get.config.type(out.fn), equals(j))
}
Expand Down

0 comments on commit 10afb8d

Please sign in to comment.