Skip to content

Commit 1560e1e

Browse files
committed
Use expect_true(is_ggplot(.)) instead of expect_s3_class(., "ggplot")
1 parent f7950c2 commit 1560e1e

File tree

4 files changed

+170
-134
lines changed

4 files changed

+170
-134
lines changed

tests/testthat/test_plotDistributions.R

Lines changed: 84 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32,78 +32,99 @@ test_that("plotDistributions fails with incorrect arguments", {
3232

3333
test_that("plotDistributions works as expected", {
3434
## Defaults
35-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
36-
groupBy = NULL, plotType = "density",
37-
facet = FALSE, pseudocount = 0), "ggplot")
35+
expect_true(ggplot2::is_ggplot(
36+
plotDistributions(se = se, selAssay = "counts",
37+
groupBy = NULL, plotType = "density",
38+
facet = FALSE, pseudocount = 0)))
3839

3940
## Change plot type
40-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
41-
groupBy = NULL, plotType = "histogram",
42-
facet = FALSE, pseudocount = 0), "ggplot")
43-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
44-
groupBy = NULL, plotType = "knee",
45-
facet = FALSE, pseudocount = 0), "ggplot")
41+
expect_true(ggplot2::is_ggplot(
42+
plotDistributions(se = se, selAssay = "counts",
43+
groupBy = NULL, plotType = "histogram",
44+
facet = FALSE, pseudocount = 0)))
45+
expect_true(ggplot2::is_ggplot(
46+
plotDistributions(se = se, selAssay = "counts",
47+
groupBy = NULL, plotType = "knee",
48+
facet = FALSE, pseudocount = 0)))
4649

4750
## groupBy Name
48-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
49-
groupBy = "Name", plotType = "density",
50-
facet = FALSE, pseudocount = 0), "ggplot")
51-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
52-
groupBy = "Name", plotType = "histogram",
53-
facet = FALSE, pseudocount = 0), "ggplot")
54-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
55-
groupBy = "Name", plotType = "knee",
56-
facet = FALSE, pseudocount = 0), "ggplot")
51+
expect_true(ggplot2::is_ggplot(
52+
plotDistributions(se = se, selAssay = "counts",
53+
groupBy = "Name", plotType = "density",
54+
facet = FALSE, pseudocount = 0)))
55+
expect_true(ggplot2::is_ggplot(
56+
plotDistributions(se = se, selAssay = "counts",
57+
groupBy = "Name", plotType = "histogram",
58+
facet = FALSE, pseudocount = 0)))
59+
expect_true(ggplot2::is_ggplot(
60+
plotDistributions(se = se, selAssay = "counts",
61+
groupBy = "Name", plotType = "knee",
62+
facet = FALSE, pseudocount = 0)))
5763

5864
## groupBy Condition
59-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
60-
groupBy = "Condition", plotType = "density",
61-
facet = FALSE, pseudocount = 0), "ggplot")
62-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
63-
groupBy = "Condition", plotType = "histogram",
64-
facet = FALSE, pseudocount = 0), "ggplot")
65-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
66-
groupBy = "Condition", plotType = "knee",
67-
facet = FALSE, pseudocount = 0), "ggplot")
65+
expect_true(ggplot2::is_ggplot(
66+
plotDistributions(se = se, selAssay = "counts",
67+
groupBy = "Condition", plotType = "density",
68+
facet = FALSE, pseudocount = 0)))
69+
expect_true(ggplot2::is_ggplot(
70+
plotDistributions(se = se, selAssay = "counts",
71+
groupBy = "Condition", plotType = "histogram",
72+
facet = FALSE, pseudocount = 0)))
73+
expect_true(ggplot2::is_ggplot(
74+
plotDistributions(se = se, selAssay = "counts",
75+
groupBy = "Condition", plotType = "knee",
76+
facet = FALSE, pseudocount = 0)))
6877

6978
## Facet
70-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
71-
groupBy = NULL, plotType = "density",
72-
facet = TRUE, pseudocount = 0), "ggplot")
73-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
74-
groupBy = NULL, plotType = "histogram",
75-
facet = TRUE, pseudocount = 0), "ggplot")
76-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
77-
groupBy = NULL, plotType = "knee",
78-
facet = TRUE, pseudocount = 0), "ggplot")
79-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
80-
groupBy = "Name", plotType = "density",
81-
facet = TRUE, pseudocount = 0), "ggplot")
82-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
83-
groupBy = "Name", plotType = "histogram",
84-
facet = TRUE, pseudocount = 0), "ggplot")
85-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
86-
groupBy = "Name", plotType = "knee",
87-
facet = TRUE, pseudocount = 0), "ggplot")
88-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
89-
groupBy = "Condition", plotType = "density",
90-
facet = TRUE, pseudocount = 0), "ggplot")
91-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
92-
groupBy = "Condition", plotType = "histogram",
93-
facet = TRUE, pseudocount = 0), "ggplot")
94-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
95-
groupBy = "Condition", plotType = "knee",
96-
facet = TRUE, pseudocount = 0), "ggplot")
79+
expect_true(ggplot2::is_ggplot(
80+
plotDistributions(se = se, selAssay = "counts",
81+
groupBy = NULL, plotType = "density",
82+
facet = TRUE, pseudocount = 0)))
83+
expect_true(ggplot2::is_ggplot(
84+
plotDistributions(se = se, selAssay = "counts",
85+
groupBy = NULL, plotType = "histogram",
86+
facet = TRUE, pseudocount = 0)))
87+
expect_true(ggplot2::is_ggplot(
88+
plotDistributions(se = se, selAssay = "counts",
89+
groupBy = NULL, plotType = "knee",
90+
facet = TRUE, pseudocount = 0)))
91+
expect_true(ggplot2::is_ggplot(
92+
plotDistributions(se = se, selAssay = "counts",
93+
groupBy = "Name", plotType = "density",
94+
facet = TRUE, pseudocount = 0)))
95+
expect_true(ggplot2::is_ggplot(
96+
plotDistributions(se = se, selAssay = "counts",
97+
groupBy = "Name", plotType = "histogram",
98+
facet = TRUE, pseudocount = 0)))
99+
expect_true(ggplot2::is_ggplot(
100+
plotDistributions(se = se, selAssay = "counts",
101+
groupBy = "Name", plotType = "knee",
102+
facet = TRUE, pseudocount = 0)))
103+
expect_true(ggplot2::is_ggplot(
104+
plotDistributions(se = se, selAssay = "counts",
105+
groupBy = "Condition", plotType = "density",
106+
facet = TRUE, pseudocount = 0)))
107+
expect_true(ggplot2::is_ggplot(
108+
plotDistributions(se = se, selAssay = "counts",
109+
groupBy = "Condition", plotType = "histogram",
110+
facet = TRUE, pseudocount = 0)))
111+
expect_true(ggplot2::is_ggplot(
112+
plotDistributions(se = se, selAssay = "counts",
113+
groupBy = "Condition", plotType = "knee",
114+
facet = TRUE, pseudocount = 0)))
97115

98116
## Increase pseudocount
99-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
100-
groupBy = "Condition", plotType = "density",
101-
facet = FALSE, pseudocount = 2), "ggplot")
102-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
103-
groupBy = "Condition", plotType = "histogram",
104-
facet = FALSE, pseudocount = 3), "ggplot")
105-
expect_s3_class(plotDistributions(se = se, selAssay = "counts",
106-
groupBy = "Condition", plotType = "knee",
107-
facet = FALSE, pseudocount = 4), "ggplot")
117+
expect_true(ggplot2::is_ggplot(
118+
plotDistributions(se = se, selAssay = "counts",
119+
groupBy = "Condition", plotType = "density",
120+
facet = FALSE, pseudocount = 2)))
121+
expect_true(ggplot2::is_ggplot(
122+
plotDistributions(se = se, selAssay = "counts",
123+
groupBy = "Condition", plotType = "histogram",
124+
facet = FALSE, pseudocount = 3)))
125+
expect_true(ggplot2::is_ggplot(
126+
plotDistributions(se = se, selAssay = "counts",
127+
groupBy = "Condition", plotType = "knee",
128+
facet = FALSE, pseudocount = 4)))
108129

109130
})

tests/testthat/test_plotFiltering.R

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,69 +36,80 @@ test_that("plotFiltering fails with incorrect arguments", {
3636

3737
test_that("plotFiltering works with correct arguments", {
3838
## Defaults
39-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
40-
onlyActiveFilters = FALSE,
41-
displayNumbers = TRUE, numberSize = 4,
42-
plotType = "remaining", facetBy = "sample"), "ggplot")
39+
expect_true(ggplot2::is_ggplot(
40+
plotFiltering(se = se, valueType = "reads",
41+
onlyActiveFilters = FALSE,
42+
displayNumbers = TRUE, numberSize = 4,
43+
plotType = "remaining", facetBy = "sample")))
4344

4445
## Fractions
45-
expect_s3_class(plotFiltering(se = se, valueType = "fractions",
46-
onlyActiveFilters = FALSE,
47-
displayNumbers = TRUE, numberSize = 4,
48-
plotType = "remaining", facetBy = "sample"), "ggplot")
46+
expect_true(ggplot2::is_ggplot(
47+
plotFiltering(se = se, valueType = "fractions",
48+
onlyActiveFilters = FALSE,
49+
displayNumbers = TRUE, numberSize = 4,
50+
plotType = "remaining", facetBy = "sample")))
4951

5052
## Only active filters
51-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
52-
onlyActiveFilters = TRUE,
53-
displayNumbers = TRUE, numberSize = 4,
54-
plotType = "remaining", facetBy = "sample"), "ggplot")
53+
expect_true(ggplot2::is_ggplot(
54+
plotFiltering(se = se, valueType = "reads",
55+
onlyActiveFilters = TRUE,
56+
displayNumbers = TRUE, numberSize = 4,
57+
plotType = "remaining", facetBy = "sample")))
5558

5659
## Don't display numbers
57-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
58-
onlyActiveFilters = FALSE,
59-
displayNumbers = FALSE, numberSize = 4,
60-
plotType = "remaining", facetBy = "sample"), "ggplot")
60+
expect_true(ggplot2::is_ggplot(
61+
plotFiltering(se = se, valueType = "reads",
62+
onlyActiveFilters = FALSE,
63+
displayNumbers = FALSE, numberSize = 4,
64+
plotType = "remaining", facetBy = "sample")))
6165

6266
## Change size of displayed numbers
63-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
64-
onlyActiveFilters = FALSE,
65-
displayNumbers = FALSE, numberSize = 2,
66-
plotType = "remaining", facetBy = "sample"), "ggplot")
67+
expect_true(ggplot2::is_ggplot(
68+
plotFiltering(se = se, valueType = "reads",
69+
onlyActiveFilters = FALSE,
70+
displayNumbers = FALSE, numberSize = 2,
71+
plotType = "remaining", facetBy = "sample")))
6772

6873
## Reads + Filtered + Sample
69-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
70-
onlyActiveFilters = FALSE,
71-
displayNumbers = TRUE, numberSize = 4,
72-
plotType = "filtered", facetBy = "sample"), "ggplot")
74+
expect_true(ggplot2::is_ggplot(
75+
plotFiltering(se = se, valueType = "reads",
76+
onlyActiveFilters = FALSE,
77+
displayNumbers = TRUE, numberSize = 4,
78+
plotType = "filtered", facetBy = "sample")))
7379

7480
## Reads + Filtered + Step
75-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
76-
onlyActiveFilters = FALSE,
77-
displayNumbers = TRUE, numberSize = 4,
78-
plotType = "filtered", facetBy = "step"), "ggplot")
81+
expect_true(ggplot2::is_ggplot(
82+
plotFiltering(se = se, valueType = "reads",
83+
onlyActiveFilters = FALSE,
84+
displayNumbers = TRUE, numberSize = 4,
85+
plotType = "filtered", facetBy = "step")))
7986

8087
## Reads + Remaining + Step
81-
expect_s3_class(plotFiltering(se = se, valueType = "reads",
82-
onlyActiveFilters = FALSE,
83-
displayNumbers = TRUE, numberSize = 4,
84-
plotType = "remaining", facetBy = "step"), "ggplot")
88+
expect_true(ggplot2::is_ggplot(
89+
plotFiltering(se = se, valueType = "reads",
90+
onlyActiveFilters = FALSE,
91+
displayNumbers = TRUE, numberSize = 4,
92+
plotType = "remaining", facetBy = "step")))
8593

8694
## Fractions + Filtered + Sample
87-
expect_s3_class(plotFiltering(se = se, valueType = "fractions",
88-
onlyActiveFilters = FALSE,
89-
displayNumbers = TRUE, numberSize = 4,
90-
plotType = "filtered", facetBy = "sample"), "ggplot")
95+
expect_true(ggplot2::is_ggplot(
96+
plotFiltering(se = se, valueType = "fractions",
97+
onlyActiveFilters = FALSE,
98+
displayNumbers = TRUE, numberSize = 4,
99+
plotType = "filtered", facetBy = "sample")))
91100

92101
## Fractions + Filtered + Step
93-
expect_s3_class(plotFiltering(se = se, valueType = "fractions",
94-
onlyActiveFilters = FALSE,
95-
displayNumbers = TRUE, numberSize = 4,
96-
plotType = "filtered", facetBy = "step"), "ggplot")
102+
expect_true(ggplot2::is_ggplot(
103+
plotFiltering(se = se, valueType = "fractions",
104+
onlyActiveFilters = FALSE,
105+
displayNumbers = TRUE, numberSize = 4,
106+
plotType = "filtered", facetBy = "step")))
97107

98108
## Fractions + Remaining + Step
99-
expect_s3_class(plotFiltering(se = se, valueType = "fractions",
100-
onlyActiveFilters = FALSE,
101-
displayNumbers = TRUE, numberSize = 4,
102-
plotType = "remaining", facetBy = "step"), "ggplot")
109+
expect_true(ggplot2::is_ggplot(
110+
plotFiltering(se = se, valueType = "fractions",
111+
onlyActiveFilters = FALSE,
112+
displayNumbers = TRUE, numberSize = 4,
113+
plotType = "remaining", facetBy = "step")))
103114

104115
})

tests/testthat/test_plotResults.R

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,33 @@ test_that("plotResults functions work as expected", {
113113
pseudocount = 1, method = "limma",
114114
normMethod = "sum")
115115

116-
expect_s3_class(plotMeanDiff(res1), "ggplot")
117-
expect_s3_class(plotMeanDiff(res2), "ggplot")
118-
expect_s3_class(plotVolcano(res1), "ggplot")
119-
expect_s3_class(plotVolcano(res2), "ggplot")
120-
121-
expect_s3_class(plotMeanDiff(res1, meanCol = "logCPM", logFCCol = "logFC",
122-
padjCol = "FDR", padjThreshold = 0.1), "ggplot")
123-
expect_s3_class(plotMeanDiff(res2, meanCol = "AveExpr", logFCCol = "logFC",
124-
padjCol = "adj.P.Val", padjThreshold = 0.1), "ggplot")
125-
expect_s3_class(plotVolcano(res1, logFCCol = "logFC", pvalCol = "PValue",
126-
padjCol = "FDR", padjThreshold = 0.1), "ggplot")
127-
expect_s3_class(plotVolcano(res2, logFCCol = "logFC", pvalCol = "P.Value",
128-
padjCol = "adj.P.Val", padjThreshold = 0.1), "ggplot")
129-
130-
expect_s3_class(plotMeanDiff(res1, nTopToLabel = 5), "ggplot")
131-
expect_s3_class(plotMeanDiff(res2, nTopToLabel = 5), "ggplot")
132-
expect_s3_class(plotVolcano(res1, nTopToLabel = 5), "ggplot")
133-
expect_s3_class(plotVolcano(res2, nTopToLabel = 5), "ggplot")
134-
135-
expect_s3_class(plotMeanDiff(res1, pointSize = "large"), "ggplot")
136-
expect_s3_class(plotMeanDiff(res2, pointSize = "large"), "ggplot")
137-
expect_s3_class(plotVolcano(res1, pointSize = "large"), "ggplot")
138-
expect_s3_class(plotVolcano(res2, pointSize = "large"), "ggplot")
116+
expect_true(ggplot2::is_ggplot(plotMeanDiff(res1)))
117+
expect_true(ggplot2::is_ggplot(plotMeanDiff(res2)))
118+
expect_true(ggplot2::is_ggplot(plotVolcano(res1)))
119+
expect_true(ggplot2::is_ggplot(plotVolcano(res2)))
120+
121+
expect_true(ggplot2::is_ggplot(
122+
plotMeanDiff(res1, meanCol = "logCPM", logFCCol = "logFC",
123+
padjCol = "FDR", padjThreshold = 0.1)))
124+
expect_true(ggplot2::is_ggplot(
125+
plotMeanDiff(res2, meanCol = "AveExpr", logFCCol = "logFC",
126+
padjCol = "adj.P.Val", padjThreshold = 0.1)))
127+
expect_true(ggplot2::is_ggplot(
128+
plotVolcano(res1, logFCCol = "logFC", pvalCol = "PValue",
129+
padjCol = "FDR", padjThreshold = 0.1)))
130+
expect_true(ggplot2::is_ggplot(
131+
plotVolcano(res2, logFCCol = "logFC", pvalCol = "P.Value",
132+
padjCol = "adj.P.Val", padjThreshold = 0.1)))
133+
134+
expect_true(ggplot2::is_ggplot(plotMeanDiff(res1, nTopToLabel = 5)))
135+
expect_true(ggplot2::is_ggplot(plotMeanDiff(res2, nTopToLabel = 5)))
136+
expect_true(ggplot2::is_ggplot(plotVolcano(res1, nTopToLabel = 5)))
137+
expect_true(ggplot2::is_ggplot(plotVolcano(res2, nTopToLabel = 5)))
138+
139+
expect_true(ggplot2::is_ggplot(plotMeanDiff(res1, pointSize = "large")))
140+
expect_true(ggplot2::is_ggplot(plotMeanDiff(res2, pointSize = "large")))
141+
expect_true(ggplot2::is_ggplot(plotVolcano(res1, pointSize = "large")))
142+
expect_true(ggplot2::is_ggplot(plotVolcano(res2, pointSize = "large")))
139143

140144
## These tests won't run if the X11 display connection can not be opened
141145
# skip_if_not_installed("plotly")

0 commit comments

Comments
 (0)