Skip to content

Commit 326ce2a

Browse files
committed
fix error tests for cran/ci
1 parent a309352 commit 326ce2a

12 files changed

+290
-29
lines changed

DESCRIPTION

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
Package: restatis
2-
Title: R Wrapper to access a wide range of Germany's Federal Statistical System
3-
databases based on the GENESIS Web Service RESTful API of the German
4-
Federal Statistical Office (Statistisches Bundesamt/Destatis)
2+
Title: R Wrapper to Access a Wide Range of Germany's Federal Statistical System Databases Based on the GENESIS Web Service RESTful API of the German Federal Statistical Office (Statistisches Bundesamt/Destatis)
53
Version: 0.2.0
64
Authors@R: c(
75
person("Yannik", "Buhl", , "[email protected]", role = c("aut", "cre")),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
structure(list(method = "GET", url = "/api/catalogue/modifieddata?username=ABCDEF&password=1234abcd&username=ABCDEF&password=1234abcdselection=61111&type=all&date=20.07.2024",
2+
status_code = 404L, headers = structure(list(Date = "Sat, 20 Jul 2024 16:13:04 GMT",
3+
Server = "Apache", `Content-Length` = "106", `Content-Type` = "application/json"), class = "httr2_headers"),
4+
body = charToRaw("{\"Code\":2,\"Content\":\"Ein Fehler ist aufgetreten. (Bitte geben Sie Ihren Nutzernamen ein.)\",\"Type\":\"ERROR\"}"),
5+
cache = new.env(parent = emptyenv())), class = "httr2_response")

tests/testthat/test_gen_alternative_terms.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,54 @@ with_mock_dir("terms1", {
2020
expect_true("Copyright" %in% names(attrs))
2121

2222
})
23+
2324
})
2425

2526
#-------------------------------------------------------------------------------
2627
# Test for errors, warnings, messages of parameters ----
2728
#-------------------------------------------------------------------------------
2829

2930
test_that("search term errors on multiple codes", {
31+
32+
skip_on_cran()
33+
skip_on_ci()
34+
3035
expect_error(
3136
gen_alternative_terms(term = c("611*", "711*"), database = "genesis"),
3237
regexp = "Parameter 'term' must be a single string.")
38+
3339
})
3440

3541
test_that("search term errors on too long search term", {
42+
43+
skip_on_cran()
44+
skip_on_ci()
45+
3646
expect_error(
3747
gen_alternative_terms(term = "dies das ananas!", database = "genesis"),
3848
regexp = "Parameter 'term' cannot consist of more than 15 characters.")
49+
3950
})
4051

4152
test_that("search term errors on wrong parameter type", {
53+
54+
skip_on_cran()
55+
skip_on_ci()
56+
4257
expect_error(
4358
gen_alternative_terms(term = "Krankenhaus", similarity = 1, database = "genesis"),
4459
regexp = "Parameter 'similarity' has to be of type 'logical'.")
60+
4561
})
4662

4763
test_that("search term errors on wrong parameter type", {
64+
65+
skip_on_cran()
66+
skip_on_ci()
67+
4868
expect_error(
4969
gen_alternative_terms(term = 1992, similarity = TRUE, database = "genesis"),
5070
regexp = "Parameter 'term' has to be of type 'character'.")
71+
5172
})
5273

tests/testthat/test_gen_catalogue.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ with_mock_dir("catalogue3", {
5656
error.ignore = FALSE,
5757
database = "genesis"),
5858
regexp = "No object found for your request")
59+
5960
})
61+
6062
})
6163

6264
#-------------------------------------------------------------------------------
@@ -91,23 +93,34 @@ with_mock_dir("catalogue5", {
9193
error.ignore = TRUE,
9294
database = "genesis"),
9395
regexp = "Use 'error.ignore = FALSE' to stop the function at the point where no object could be found.")
96+
9497
})
98+
9599
})
96100

97101
#-------------------------------------------------------------------------------
98102
# Test for errors, warnings, messages of parameters ----
99103
#-------------------------------------------------------------------------------
100104

101105
test_that("gen_catalogue function errors on multiple codes", {
106+
107+
skip_on_cran()
108+
skip_on_ci()
109+
102110
expect_error(
103111
gen_catalogue(code = c("611*", "711*"),
104112
detailed = TRUE,
105113
category = "tables",
106114
database = "genesis"),
107115
regexp = "Parameter 'code' must be a single string.")
116+
108117
})
109118

110119
test_that("gen_catalogue function errors on numeric code param", {
120+
121+
skip_on_cran()
122+
skip_on_ci()
123+
111124
expect_error(
112125
gen_catalogue(code = 12345,
113126
detailed = TRUE,
@@ -119,32 +132,47 @@ test_that("gen_catalogue function errors on numeric code param", {
119132
#-------------------------------------------------------------------------------
120133

121134
test_that("gen_catalogue function errors on wrong categories", {
135+
136+
skip_on_cran()
137+
skip_on_ci()
138+
122139
expect_error(
123140
gen_catalogue(code = "611*",
124141
detailed = TRUE,
125142
category = "variables",
126143
database = "genesis"),
127144
regexp = "Available categories are 'tables', 'statistics', and 'cubes'.")
145+
128146
})
129147

130148
test_that("gen_catalogue function errors on too many categories", {
149+
150+
skip_on_cran()
151+
skip_on_ci()
152+
131153
expect_error(
132154
gen_catalogue(code = "611*",
133155
detailed = TRUE,
134156
category = c("variables", "statistics", "tables", "cubes"),
135157
database = "genesis"),
136158
regexp = "Parameter 'category' has to have a length of 1 to 3.")
159+
137160
})
138161

139162
#-------------------------------------------------------------------------------
140163

141164
test_that("gen_catalogue function errors on numeric detailed param", {
165+
166+
skip_on_cran()
167+
skip_on_ci()
168+
142169
expect_error(
143170
gen_catalogue(code = "711*",
144171
detailed = 1,
145172
category = "tables",
146173
database = "genesis"),
147174
regexp = "Parameter 'detailed' has to be of type 'logical' and of length 1.")
175+
148176
})
149177

150178
with_mock_dir("catalogue6", {
@@ -159,18 +187,25 @@ with_mock_dir("catalogue6", {
159187
category = "tables",
160188
database = "genesis"),
161189
regexp = "Use 'detailed = TRUE' to obtain the complete output.")
190+
162191
})
192+
163193
})
164194

165195
#-------------------------------------------------------------------------------
166196

167197
test_that("gen_catalogue function errors on wrong error.ignore param", {
198+
199+
skip_on_cran()
200+
skip_on_ci()
201+
168202
expect_error(
169203
gen_catalogue(code = "711*",
170204
detailed = TRUE,
171205
category = "tables",
172206
error.ignore = 1,
173207
database = "genesis"),
174208
regexp = "Parameter 'error.ignore' has to be of type 'logical' and of length 1.")
209+
175210
})
176211

tests/testthat/test_gen_find.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ with_mock_dir("find1", {
2222
expect_true("Language" %in% names(attrs))
2323
expect_true("Pagelength" %in% names(attrs))
2424
expect_true("Copyright" %in% names(attrs))
25+
2526
})
27+
2628
})
2729

2830
#-------------------------------------------------------------------------------
@@ -40,7 +42,9 @@ with_mock_dir("find2_fake", {
4042
expect_error(
4143
gen_find(term = "bus", error.ignore = TRUE, database = "genesis"),
4244
regexp = "test error message")
45+
4346
})
47+
4448
})
4549

4650
#-------------------------------------------------------------------------------
@@ -64,31 +68,56 @@ with_mock_dir("find3", {
6468
#-------------------------------------------------------------------------------
6569

6670
test_that("gen_find function errors on numeric term param", {
71+
72+
skip_on_cran()
73+
skip_on_ci()
74+
6775
expect_error(
6876
gen_find(term = 12345, detailed = TRUE, category = "tables", database = "genesis"),
6977
regexp = "Parameter 'term' has to be of type 'character'.")
78+
7079
})
7180

7281
test_that("gen_find function errors on wrong category", {
82+
83+
skip_on_cran()
84+
skip_on_ci()
85+
7386
expect_error(
7487
gen_find(term = "bus", detailed = TRUE, category = "table", database = "genesis"),
7588
regexp = "Available categories for parameter 'category' for 'genesis' database are 'all', 'tables', 'statistics', 'variables', and 'cubes'.")
89+
7690
})
7791

7892
test_that("gen_find function errors on wrong detailed param", {
93+
94+
skip_on_cran()
95+
skip_on_ci()
96+
7997
expect_error(
8098
gen_find(term = "bus", detailed = 1, category = "tables", database = "genesis"),
8199
regexp = "Parameter 'detailed' has to be of type 'logical' and of length 1.")
100+
82101
})
83102

84103
test_that("gen_find function errors on wrong ordering param", {
104+
105+
skip_on_cran()
106+
skip_on_ci()
107+
85108
expect_error(
86109
gen_find(term = "bus", ordering = 1, category = "tables", database = "genesis"),
87110
regexp = "Parameter 'ordering' has to be of type 'logical' and of length 1.")
111+
88112
})
89113

90114
test_that("gen_find function errors on wrong error.ignore param", {
115+
116+
skip_on_cran()
117+
skip_on_ci()
118+
91119
expect_error(
92120
gen_find(term = "bus", error.ignore = 1, category = "tables", database = "genesis"),
93121
regexp = "Parameter 'error.ignore' has to be of type 'logical' and of length 1.")
122+
94123
})

tests/testthat/test_gen_meta_data.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ with_mock_dir("meta2_fake", {
4343
category = "cube",
4444
database = "genesis"),
4545
regexp = "test error message")
46+
4647
})
48+
4749
})
4850

4951
#-------------------------------------------------------------------------------
@@ -60,34 +62,55 @@ with_mock_dir("meta3", {
6062
error.ignore = TRUE,
6163
database = "genesis"),
6264
regexp = "Use 'error.ignore = FALSE' to stop the function at the point where no object could be found.")
65+
6366
})
67+
6468
})
6569

6670
#-------------------------------------------------------------------------------
6771
# Test for errors, warnings, messages of parameters ----
6872
#-------------------------------------------------------------------------------
6973

7074
test_that("gen_metadata function errors on numeric code param", {
75+
76+
skip_on_cran()
77+
skip_on_ci()
78+
7179
expect_error(
7280
gen_metadata(code = 12345, category = "Table", database = "genesis"),
7381
regexp = "Parameter 'code' has to be of type 'character'.")
82+
7483
})
7584

7685
test_that("gen_metadata function errors on multiple categories", {
86+
87+
skip_on_cran()
88+
skip_on_ci()
89+
7790
expect_error(
7891
gen_metadata(code = "12345", category = c("Table", "Cube"), database = "genesis"),
7992
regexp = "Parameter 'category' must have a length of 1. Please specify the category.")
93+
8094
})
8195

8296
test_that("gen_metadata function errors on wrong category", {
97+
98+
skip_on_cran()
99+
skip_on_ci()
100+
83101
expect_error(
84102
gen_metadata(code = "11111", category = "Table", database = "genesis"),
85103
regexp = "Available categories for parameter 'category' for 'genesis' database are 'cube', 'table', 'statistic', 'variable', and 'value'")
86104

87105
})
88106

89107
test_that("gen_metadata function errors on wrong error.ignore param", {
108+
109+
skip_on_cran()
110+
skip_on_ci()
111+
90112
expect_error(
91113
gen_metadata(code = "11111", error.ignore = 1, category = "table", database = "genesis"),
92114
regexp = "Parameter 'error.ignore' has to be of type 'logical' and of length 1.")
115+
93116
})

tests/testthat/test_gen_modified_data.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,60 @@ with_mock_dir("modified4_fake", {
7272
#-------------------------------------------------------------------------------
7373

7474
test_that("gen_modified_data errors on misspecified dates", {
75+
76+
skip_on_cran()
77+
skip_on_ci()
78+
7579
expect_error(
7680
gen_modified_data(code = "61111", date = "1.1.2022"),
7781
regexp = "it has to be of length 1 and format DD.MM.YYYY")
82+
7883
})
7984

8085
test_that("gen_modified_data errors on misspecified dates", {
86+
87+
skip_on_cran()
88+
skip_on_ci()
89+
8190
expect_error(
8291
gen_modified_data(code = "61111", date = 23456),
8392
regexp = "'date', it has to be of type 'character'.")
93+
8494
})
8595

8696
#-------------------------------------------------------------------------------
8797

8898
test_that("gen_modified_data errors on multiple codes", {
99+
100+
skip_on_cran()
101+
skip_on_ci()
102+
89103
expect_error(
90104
gen_modified_data(code = c("611*", "711*")),
91105
regexp = "Parameter 'code' must be a single string.")
106+
92107
})
93108

94109
test_that("gen_modified_data function errors on numeric code param", {
110+
111+
skip_on_cran()
112+
skip_on_ci()
113+
95114
expect_error(
96115
gen_modified_data(code = 12345),
97116
regexp = "Parameter 'code' has to be of type 'character'.")
117+
98118
})
99119

100120
#-------------------------------------------------------------------------------
101121

102122
test_that("gen_modified_data function errors on wrong type value", {
123+
124+
skip_on_cran()
125+
skip_on_ci()
126+
103127
expect_error(
104128
gen_modified_data(code = "12345", type = "diesdasananas"),
105129
regexp = "'arg' should be one of")
130+
106131
})

0 commit comments

Comments
 (0)