Skip to content

Commit 6091c6a

Browse files
committed
Address test-coverage #40 warnings and errors
1 parent b29162c commit 6091c6a

File tree

10 files changed

+38
-24
lines changed

10 files changed

+38
-24
lines changed

tests/testthat/helper-ggplot.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
is_ggplot <- if (exists("is_ggplot", envir = asNamespace("ggplot2"), inherits = FALSE)) {
2+
get("is_ggplot", envir = asNamespace("ggplot2"), inherits = FALSE)
3+
} else {
4+
function(x) inherits(x, "ggplot")
5+
}

tests/testthat/test-create-report.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ test_that("test overall functionalities", {
2020
output_file = file_name, output_dir = dir_name,
2121
config = list("plot_correlation" = list(), "plot_prcomp" = list()),
2222
report_title = "5/6: Detect 0 complete rows", quiet = TRUE)
23-
create_report(airquality, y = "Ozone", plotly = TRUE, report_title = "6/6: Create report with plotly", quiet = TRUE)
2423
create_report(iris, output_file = file_name, output_dir = dir_name, quiet = TRUE)
2524
expect_true(file.exists(file_dir))
2625
expect_gte(file.info(file_dir)$size, 100000)
2726
if (file.exists(file_dir)) expect_true(file.remove(file_dir))
2827
})
2928

29+
test_that("test create_report with plotly", {
30+
skip_on_cran()
31+
skip_if_not_installed("plotly")
32+
create_report(airquality, y = "Ozone", plotly = TRUE,
33+
output_file = file_name, output_dir = dir_name,
34+
report_title = "6/6: Create report with plotly", quiet = TRUE)
35+
expect_true(file.exists(file_dir))
36+
if (file.exists(file_dir)) expect_true(file.remove(file_dir))
37+
})
38+
3039
test_that("test if non-existing y throws an error", {
3140
skip_on_cran()
3241
expect_error(create_report(iris, y = "abc"))

tests/testthat/test-plot-bar.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ test_that("test return object", {
1414
plot_list <- plot_bar(diamonds)
1515
expect_is(plot_list, "list")
1616
expect_equal(names(plot_list), "page_1")
17-
expect_true(is.ggplot(plot_list[[1]]))
17+
expect_true(is_ggplot(plot_list[[1]]))
1818

1919
plot_list2 <- plot_bar(diamonds, nrow = 1L, ncol = 1L)
2020
expect_is(plot_list2, "list")
2121
expect_equal(names(plot_list2), c("page_1", "page_2", "page_3"))
22-
expect_true(all(vapply(plot_list2, is.ggplot, TRUE)))
22+
expect_true(all(vapply(plot_list2, is_ggplot, TRUE)))
2323
})
2424

2525
test_that("test binary categories", {

tests/testthat/test-plot-boxplot.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ test_that("test return object", {
88
boxplot_list <- plot_boxplot(iris, by = "Species")
99
expect_is(boxplot_list, "list")
1010
expect_equal(names(boxplot_list), "page_1")
11-
expect_true(is.ggplot(boxplot_list[[1]]))
11+
expect_true(is_ggplot(boxplot_list[[1]]))
1212

1313
boxplot_list2 <- plot_boxplot(iris, by = "Species", nrow = 1L, ncol = 1L)
1414
expect_is(boxplot_list2, "list")
1515
expect_equal(names(boxplot_list2), c("page_1", "page_2", "page_3", "page_4"))
16-
expect_true(all(vapply(boxplot_list2, is.ggplot, TRUE)))
16+
expect_true(all(vapply(boxplot_list2, is_ggplot, TRUE)))
1717
})

tests/testthat/test-plot-correlation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ test_that("test error messages", {
1919

2020
test_that("test return object", {
2121
plot_obj <- plot_correlation(iris)
22-
expect_true(is.ggplot(plot_obj))
22+
expect_true(is_ggplot(plot_obj))
2323
})

tests/testthat/test-plot-histogram-density.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ test_that("test return object", {
1010
histogram_list <- plot_histogram(iris)
1111
expect_is(histogram_list, "list")
1212
expect_equal(names(histogram_list), "page_1")
13-
expect_true(is.ggplot(histogram_list[[1]]))
13+
expect_true(is_ggplot(histogram_list[[1]]))
1414

1515
histogram_list2 <- plot_histogram(iris, nrow = 1L, ncol = 1L)
1616
expect_is(histogram_list2, "list")
1717
expect_equal(names(histogram_list2), c("page_1", "page_2", "page_3", "page_4"))
18-
expect_true(all(vapply(histogram_list2, is.ggplot, TRUE)))
18+
expect_true(all(vapply(histogram_list2, is_ggplot, TRUE)))
1919

2020
density_list <- plot_density(iris)
2121
expect_is(density_list, "list")
2222
expect_equal(names(density_list), "page_1")
23-
expect_true(is.ggplot(density_list[[1]]))
23+
expect_true(is_ggplot(density_list[[1]]))
2424

2525
density_list2 <- plot_density(iris, nrow = 1L, ncol = 1L)
2626
expect_is(density_list2, "list")
2727
expect_equal(names(density_list2), c("page_1", "page_2", "page_3", "page_4"))
28-
expect_true(all(vapply(density_list2, is.ggplot, TRUE)))
28+
expect_true(all(vapply(density_list2, is_ggplot, TRUE)))
2929
})
3030

3131
test_that("test binary categories and error messages", {

tests/testthat/test-plot-intro.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ context("plot intro")
22

33
test_that("test return object", {
44
plot_obj <- plot_intro(iris)
5-
expect_true(is.ggplot(plot_obj))
5+
expect_true(is_ggplot(plot_obj))
66
})

tests/testthat/test-plot-missing.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ context("plot missing data profile")
22

33
test_that("test return object", {
44
plot_obj <- plot_missing(airquality)
5-
expect_true(is.ggplot(plot_obj))
5+
expect_true(is_ggplot(plot_obj))
66
})

tests/testthat/test-plot-scatterplot.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ test_that("test return object", {
1111
scatterplot_list <- plot_scatterplot(iris, by = "Species")
1212
expect_is(scatterplot_list, "list")
1313
expect_equal(names(scatterplot_list), "page_1")
14-
expect_true(is.ggplot(scatterplot_list[[1]]))
14+
expect_true(is_ggplot(scatterplot_list[[1]]))
1515

1616
scatterplot_list2 <- plot_scatterplot(iris, by = "Species", nrow = 1L, ncol = 1L)
1717
expect_is(scatterplot_list2, "list")
1818
expect_equal(names(scatterplot_list2), c("page_1", "page_2", "page_3", "page_4"))
19-
expect_true(all(vapply(scatterplot_list2, is.ggplot, TRUE)))
19+
expect_true(all(vapply(scatterplot_list2, is_ggplot, TRUE)))
2020
})

tests/testthat/test-plotly.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ test_that("plotly = TRUE runs when plotly package is installed", {
1212
expect_silent(plot_histogram(iris, ncol = 2L, plotly = TRUE))
1313
out_hist <- plot_histogram(iris, ncol = 2L, plotly = TRUE)
1414
expect_is(out_hist, "list")
15-
expect_true(all(vapply(out_hist, is.ggplot, TRUE)))
15+
expect_true(all(vapply(out_hist, is_ggplot, TRUE)))
1616

1717
expect_silent(plot_density(iris, ncol = 2L, plotly = TRUE))
1818
out_dens <- plot_density(iris, ncol = 2L, plotly = TRUE)
1919
expect_is(out_dens, "list")
20-
expect_true(all(vapply(out_dens, is.ggplot, TRUE)))
20+
expect_true(all(vapply(out_dens, is_ggplot, TRUE)))
2121

2222
# Single-panel plots
2323
expect_silent(plot_missing(airquality, plotly = TRUE))
2424
out_miss <- plot_missing(airquality, plotly = TRUE)
25-
expect_true(is.ggplot(out_miss))
25+
expect_true(is_ggplot(out_miss))
2626

2727
expect_silent(plot_intro(iris, plotly = TRUE))
2828
out_intro <- plot_intro(iris, plotly = TRUE)
29-
expect_true(is.ggplot(out_intro))
29+
expect_true(is_ggplot(out_intro))
3030

3131
expect_silent(plot_correlation(iris, plotly = TRUE))
3232
out_cor <- plot_correlation(iris, plotly = TRUE)
33-
expect_true(is.ggplot(out_cor))
33+
expect_true(is_ggplot(out_cor))
3434
})
3535

3636
test_that("plotly = TRUE with plot_boxplot and plot_qq when plotly is installed", {
@@ -39,12 +39,12 @@ test_that("plotly = TRUE with plot_boxplot and plot_qq when plotly is installed"
3939
expect_silent(plot_boxplot(iris, by = "Species", ncol = 2L, plotly = TRUE))
4040
out_box <- plot_boxplot(iris, by = "Species", ncol = 2L, plotly = TRUE)
4141
expect_is(out_box, "list")
42-
expect_true(all(vapply(out_box, is.ggplot, TRUE)))
42+
expect_true(all(vapply(out_box, is_ggplot, TRUE)))
4343

4444
expect_silent(plot_qq(iris, ncol = 2L, plotly = TRUE))
4545
out_qq <- plot_qq(iris, ncol = 2L, plotly = TRUE)
4646
expect_is(out_qq, "list")
47-
expect_true(all(vapply(out_qq, is.ggplot, TRUE)))
47+
expect_true(all(vapply(out_qq, is_ggplot, TRUE)))
4848
})
4949

5050
test_that("plotly = TRUE throws informative error when plotly is not installed", {
@@ -69,11 +69,11 @@ test_that("plotly = FALSE is default and unchanged behavior", {
6969
# Regression: default remains static ggplot
7070
out_bar <- plot_bar(iris)
7171
expect_is(out_bar, "list")
72-
expect_true(is.ggplot(out_bar[[1]]))
72+
expect_true(is_ggplot(out_bar[[1]]))
7373

7474
out_miss <- plot_missing(airquality)
75-
expect_true(is.ggplot(out_miss))
75+
expect_true(is_ggplot(out_miss))
7676

7777
out_intro <- plot_intro(iris)
78-
expect_true(is.ggplot(out_intro))
78+
expect_true(is_ggplot(out_intro))
7979
})

0 commit comments

Comments
 (0)