Skip to content

Commit d7e25cf

Browse files
committed
use new test_that() style
1 parent 0d3f2ad commit d7e25cf

File tree

3 files changed

+128
-159
lines changed

3 files changed

+128
-159
lines changed

Diff for: tests/testthat/test_check_dbtable_variable.R

+123-152
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,136 @@
1-
context("check if a database table contains a variable")
2-
describe("check_dbtable_variable()", {
1+
test_that("checks if table is a single character", {
2+
skip_on_cran()
3+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
34
junk <- "junk"
45
table <- "location"
56
variable <- c("external_code", "description")
67
error <- TRUE
7-
it("checks if table is a single character", {
8-
skip_on_cran()
9-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
10-
channel <- connect_ut_db()
11-
expect_error(
12-
check_dbtable_variable(
13-
table = integer(0),
14-
variable = variable,
15-
channel = channel,
16-
error = error
17-
),
18-
"table is not a string"
19-
)
20-
expect_error(
21-
check_dbtable_variable(
22-
table = NA,
23-
variable = variable,
24-
channel = channel,
25-
error = error
26-
),
27-
"table is not a string"
28-
)
29-
expect_error(
30-
check_dbtable_variable(
31-
table = character(2),
32-
variable = variable,
33-
channel = channel,
34-
error = error
35-
),
36-
"table is not a string"
37-
)
38-
expect_error(
39-
check_dbtable_variable(
40-
table = character(0),
41-
variable = variable,
42-
channel = channel,
43-
error = error
44-
),
45-
"table is not a string"
46-
)
47-
DBI::dbDisconnect(channel)
48-
})
8+
channel <- connect_ut_db()
9+
expect_error(
10+
check_dbtable_variable(
11+
table = integer(0), variable = variable, channel = channel,
12+
error = error
13+
),
14+
"table is not a string"
15+
)
16+
expect_error(
17+
check_dbtable_variable(
18+
table = NA, variable = variable, channel = channel, error = error
19+
),
20+
"table is not a string"
21+
)
22+
expect_error(
23+
check_dbtable_variable(
24+
table = character(2), variable = variable, channel = channel,
25+
error = error
26+
),
27+
"table is not a string"
28+
)
29+
expect_error(
30+
check_dbtable_variable(
31+
table = character(0), variable = variable, channel = channel,
32+
error = error
33+
),
34+
"table is not a string"
35+
)
36+
DBI::dbDisconnect(channel)
37+
})
4938

50-
it("checks if table exists", {
51-
skip_on_cran()
52-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
53-
channel <- connect_ut_db()
54-
expect_that(
55-
check_dbtable_variable(
56-
table = junk,
57-
variable = variable,
58-
channel = channel,
59-
error = error
60-
),
61-
throws_error(
62-
sprintf(
63-
"Table\\(s\\) %s not found in schema public on database", #nolint: nonportable_path_linter, line_length_linter.
64-
junk
65-
)
66-
)
67-
)
68-
})
39+
test_that("checks if table exists", {
40+
skip_on_cran()
41+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
42+
junk <- "junk"
43+
table <- "location"
44+
variable <- c("external_code", "description")
45+
error <- TRUE
46+
channel <- connect_ut_db()
47+
expect_error(
48+
check_dbtable_variable(
49+
table = junk, variable = variable, channel = channel, error = error
50+
),
51+
sprintf("Table\\(s\\) %s not found in schema public on database", junk)
52+
)
53+
})
6954

70-
it("checks if channel is on ODBC connection", {
71-
skip_on_cran()
72-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
73-
channel <- connect_ut_db()
74-
expect_that(
75-
check_dbtable_variable(
76-
table = table,
77-
variable = variable,
78-
channel = junk,
79-
error = error
80-
),
81-
throws_error("channel does not inherit from class DBIConnection")
82-
)
83-
DBI::dbDisconnect(channel)
84-
})
55+
test_that("checks if channel is on ODBC connection", {
56+
skip_on_cran()
57+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
58+
junk <- "junk"
59+
table <- "location"
60+
variable <- c("external_code", "description")
61+
error <- TRUE
62+
channel <- connect_ut_db()
63+
expect_error(
64+
check_dbtable_variable(
65+
table = table, variable = variable, channel = junk, error = error
66+
),
67+
"channel does not inherit from class DBIConnection"
68+
)
69+
DBI::dbDisconnect(channel)
70+
})
8571

86-
it("checks if variable is a non-empty character without missing values", {
87-
skip_on_cran()
88-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
89-
channel <- connect_ut_db()
90-
expect_that(
91-
check_dbtable_variable(
92-
table = table,
93-
variable = integer(0),
94-
channel = channel,
95-
error = error
96-
),
97-
throws_error("variable must be character")
98-
)
99-
expect_that(
100-
check_dbtable_variable(
101-
table = table,
102-
variable = c(variable, NA),
103-
channel = channel,
104-
error = error
105-
),
106-
throws_error(
107-
"missing values in object"
108-
)
109-
)
110-
expect_that(
111-
check_dbtable_variable(
112-
table = table,
113-
variable = character(0),
114-
channel = channel,
115-
error = error
116-
),
117-
throws_error("'variable' must contain at least one value")
118-
)
119-
DBI::dbDisconnect(channel)
120-
})
72+
test_that(
73+
"checks if variable is a non-empty character without missing values", {
74+
skip_on_cran()
75+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
76+
junk <- "junk"
77+
table <- "location"
78+
variable <- c("external_code", "description")
79+
error <- TRUE
80+
channel <- connect_ut_db()
81+
expect_error(
82+
check_dbtable_variable(
83+
table = table, variable = integer(0), channel = channel, error = error
84+
),
85+
"variable must be character"
86+
)
87+
expect_error(
88+
check_dbtable_variable(
89+
table = table, variable = c(variable, NA), channel = channel,
90+
error = error
91+
),
92+
"missing values in object"
93+
)
94+
expect_error(
95+
check_dbtable_variable(
96+
table = table, variable = character(0), channel = channel, error = error
97+
),
98+
"'variable' must contain at least one value"
99+
)
100+
DBI::dbDisconnect(channel)
101+
})
121102

122-
it("gives correct output", {
123-
skip_on_cran()
124-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
125-
channel <- connect_ut_db()
126-
expect_true(
127-
check_dbtable_variable(
128-
table = table,
129-
variable = variable,
130-
channel = channel,
131-
error = error
132-
)
103+
test_that("gives correct output", {
104+
skip_on_cran()
105+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
106+
junk <- "junk"
107+
table <- "location"
108+
variable <- c("external_code", "description")
109+
error <- TRUE
110+
channel <- connect_ut_db()
111+
expect_true(
112+
check_dbtable_variable(
113+
table = table, variable = variable, channel = channel, error = error
133114
)
134-
expect_false(
135-
check_dbtable_variable(
136-
table = table,
137-
variable = junk,
138-
channel = channel,
139-
error = FALSE
140-
)
115+
)
116+
expect_false(
117+
check_dbtable_variable(
118+
table = table, variable = junk, channel = channel, error = FALSE
141119
)
142-
expect_false(
143-
check_dbtable_variable(
144-
table = table,
145-
variable = junk,
146-
channel = channel,
147-
error = FALSE
148-
)
120+
)
121+
expect_false(
122+
check_dbtable_variable(
123+
table = table, variable = junk, channel = channel, error = FALSE
149124
)
150-
expect_error(
151-
check_dbtable_variable(
152-
table = table,
153-
variable = junk,
154-
channel = channel,
155-
error = TRUE
156-
),
157-
paste0(
158-
"Variable\\(s\\) missing from '", table, "': ", #nolint: nonportable_path_linter, line_length_linter.
159-
paste(junk, collapse = ", ")
160-
)
125+
)
126+
expect_error(
127+
check_dbtable_variable(
128+
table = table, variable = junk, channel = channel, error = TRUE
129+
),
130+
paste0(
131+
"Variable\\(s\\) missing from '", table, "': ",
132+
paste(junk, collapse = ", ")
161133
)
162-
DBI::dbDisconnect(channel)
163-
})
164-
134+
)
135+
DBI::dbDisconnect(channel)
165136
})

Diff for: tests/testthat/test_check_id.R

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ describe("check_id()", {
1111
junk <- "junk"
1212

1313
it("tests if the channel in an ODBC connection", {
14-
skip_on_cran()
15-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
1614
expect_error(
1715
check_id(
1816
value = value,
@@ -25,7 +23,7 @@ describe("check_id()", {
2523
})
2624
it("tests if the table exists in the ODBC connection", {
2725
skip_on_cran()
28-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
26+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
2927
channel <- connect_ut_db()
3028
expect_error(
3129
check_id(
@@ -43,7 +41,7 @@ describe("check_id()", {
4341
})
4442
it("tests if the variable table exists in the table", {
4543
skip_on_cran()
46-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
44+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
4745
channel <- connect_ut_db()
4846
value <- 1
4947
expect_error(
@@ -59,7 +57,7 @@ describe("check_id()", {
5957
})
6058
it("tests if the id exists in the table", {
6159
skip_on_cran()
62-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
60+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
6361
channel <- connect_ut_db()
6462
expect_false(
6563
check_id(

Diff for: tests/testthat/test_connect_result.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("check_id()", {
1313
it("uses trusted authentication when username is missing or ''", {
1414
skip_on_cran()
1515
skip_on_os("linux")
16-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
16+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
1717
expect_is(
1818
connect_result(),
1919
"src"
@@ -25,7 +25,7 @@ describe("check_id()", {
2525
})
2626
it("uses username and password when supplied", {
2727
skip_on_cran()
28-
skip_if(isTRUE(Sys.getenv("CHECKLIST_OS", FALSE)))
28+
skip_if(as.logical(Sys.getenv("CHECKLIST_OS", FALSE)))
2929
expect_is(
3030
connect_result(
3131
username = Sys.getenv("N2KRESULT_USERNAME"),

0 commit comments

Comments
 (0)