Skip to content

Commit 2cda574

Browse files
Fix condition expectations in prevision of testthat breaking change (#236)
* Fix condition expectations in prevision of testthat breaking change See r-lib/testthat#1401 * Add NEWS bullet Co-authored-by: DavisVaughan <[email protected]>
1 parent 0d6a03e commit 2cda574

File tree

6 files changed

+78
-51
lines changed

6 files changed

+78
-51
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
as_date_time(x, "America/New_York")
2828
#> [1] "2019-01-01 00:00:59 EST" "2019-01-01 00:01:00 EST"
2929
```
30+
31+
* Preemptively updated tests related to upcoming changes in testthat (#236).
3032

3133
# clock 0.3.0
3234

tests/testthat/test-date.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ test_that("parsing into a date if you requested to parse time components rounds
311311
})
312312

313313
test_that("parsing fails when undocumented rounding behavior would result in invalid 60 second component (#230) (undocumented)", {
314-
expect_identical(
315-
expect_warning(
314+
expect_warning(
315+
expect_identical(
316316
date_parse("2019-01-01 01:01:59.550", format = "%Y-%m-%d %H:%M:%6S"),
317-
class = "clock_warning_parse_failures"
317+
new_date(NA_real_)
318318
),
319-
new_date(NA_real_)
319+
class = "clock_warning_parse_failures"
320320
)
321321
})
322322

tests/testthat/test-gregorian-year-month-day.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ test_that("multiple formats can be provided", {
222222
test_that("failure to parse results in `NA`", {
223223
x <- "2020-01-ohno"
224224

225-
expect_identical(
226-
expect_warning(year_month_day_parse(x)),
227-
year_month_day(NA, NA, NA)
225+
expect_warning(
226+
expect_identical(
227+
year_month_day_parse(x),
228+
year_month_day(NA, NA, NA)
229+
)
228230
)
229231
})
230232

tests/testthat/test-naive-time.R

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ test_that("parsing day components with second precision uses midnight as time",
180180
test_that("cannot parse invalid dates", {
181181
x <- "2019-02-31"
182182

183-
expect_identical(
184-
expect_warning(naive_time_parse(x, precision = "day")),
185-
naive_days(NA)
183+
expect_warning(
184+
expect_identical(
185+
naive_time_parse(x, precision = "day"),
186+
naive_days(NA)
187+
)
186188
)
187189

188190
expect_snapshot(naive_time_parse(x, precision = "day"))
@@ -201,9 +203,11 @@ test_that("can parse with multiple formats", {
201203
test_that("failure to parse results in NA", {
202204
x <- "2019-01-oh"
203205

204-
expect_identical(
205-
expect_warning(naive_time_parse(x, format = "%Y-%m-%d", precision = "day")),
206-
naive_days(NA)
206+
expect_warning(
207+
expect_identical(
208+
naive_time_parse(x, format = "%Y-%m-%d", precision = "day"),
209+
naive_days(NA)
210+
)
207211
)
208212
})
209213

@@ -255,9 +259,11 @@ test_that("%z is completely ignored, but is required to be parsed correctly if s
255259
naive_time_parse(x, format = "%Y-%m-%d %H:%M:%S%z"),
256260
as_naive_time(year_month_day(2019, 1, 1, 0, 0, 0))
257261
)
258-
expect_identical(
259-
expect_warning(naive_time_parse(y, format = "%Y-%m-%d %H:%M:%S%z")),
260-
naive_seconds(NA)
262+
expect_warning(
263+
expect_identical(
264+
naive_time_parse(y, format = "%Y-%m-%d %H:%M:%S%z"),
265+
naive_seconds(NA)
266+
)
261267
)
262268
})
263269

@@ -302,12 +308,12 @@ test_that("parsing rounds parsed subsecond components more precise than the resu
302308
})
303309

304310
test_that("parsing fails when undocumented rounding behavior would result in invalid 60 second component (#230) (undocumented)", {
305-
expect_identical(
306-
expect_warning(
311+
expect_warning(
312+
expect_identical(
307313
naive_time_parse("2019-01-01 01:01:59.550", format = "%Y-%m-%d %H:%M:%6S", precision = "second"),
308-
class = "clock_warning_parse_failures"
314+
as_naive_time(year_month_day(NA, NA, NA, NA, NA, NA))
309315
),
310-
as_naive_time(year_month_day(NA, NA, NA, NA, NA, NA))
316+
class = "clock_warning_parse_failures"
311317
)
312318
})
313319

tests/testthat/test-utils.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ test_that("POSIXt time zones are standardized as expected", {
88

99
# Unknown if this can happen, but we handle it anyways
1010
expect_snapshot(posixt_tzone_standardize(character()))
11-
expect_identical(expect_warning(posixt_tzone_standardize(character())), "")
11+
expect_warning(
12+
expect_identical(posixt_tzone_standardize(character()), "")
13+
)
1214

1315
expect_snapshot_error(posixt_tzone_standardize(1))
1416
})

tests/testthat/test-zoned-time.R

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ test_that("cannot parse nonexistent time", {
117117

118118
x <- "1970-04-26 02:30:00-05:00[America/New_York]"
119119

120-
expect_identical(
121-
expect_warning(zoned_time_parse_complete(x)),
122-
as_zoned_time(naive_seconds(NA), zone)
120+
expect_warning(
121+
expect_identical(
122+
zoned_time_parse_complete(x),
123+
as_zoned_time(naive_seconds(NA), zone)
124+
)
123125
)
124126

125127
expect_snapshot(zoned_time_parse_complete(x))
@@ -149,9 +151,11 @@ test_that("offset must align with unique offset", {
149151
# Should be `-05:00`
150152
x <- "2019-01-01 01:02:03-03:00[America/New_York]"
151153

152-
expect_identical(
153-
expect_warning(zoned_time_parse_complete(x)),
154-
as_zoned_time(naive_seconds(NA), zone)
154+
expect_warning(
155+
expect_identical(
156+
zoned_time_parse_complete(x),
157+
as_zoned_time(naive_seconds(NA), zone)
158+
)
155159
)
156160

157161
expect_snapshot(zoned_time_parse_complete(x))
@@ -166,9 +170,11 @@ test_that("offset must align with one of two possible ambiguous offsets", {
166170
"1970-10-25 01:30:00-06:00[America/New_York]"
167171
)
168172

169-
expect_identical(
170-
expect_warning(zoned_time_parse_complete(x)),
171-
as_zoned_time(naive_seconds(c(NA, NA)), zone)
173+
expect_warning(
174+
expect_identical(
175+
zoned_time_parse_complete(x),
176+
as_zoned_time(naive_seconds(c(NA, NA)), zone)
177+
)
172178
)
173179

174180
expect_snapshot(zoned_time_parse_complete(x))
@@ -208,9 +214,11 @@ test_that("all `NA`s uses UTC time zone (#162)", {
208214
})
209215

210216
test_that("all failures uses UTC time zone (#162)", {
211-
expect_identical(
212-
expect_warning(zoned_time_parse_complete(c("foo", "bar"))),
213-
as_zoned_time(naive_seconds(c(NA, NA)), "UTC")
217+
expect_warning(
218+
expect_identical(
219+
zoned_time_parse_complete(c("foo", "bar")),
220+
as_zoned_time(naive_seconds(c(NA, NA)), "UTC")
221+
)
214222
)
215223
})
216224

@@ -242,9 +250,12 @@ test_that("leftover subseconds result in a parse failure", {
242250
# This defaults to `%6S`, which parses `01.123` then stops,
243251
# leaving a `8` for `%z` to parse, resulting in a failure. Because everything
244252
# fails, we get a UTC time zone.
245-
expect_identical(
246-
expect_warning(zoned_time_parse_complete(x, precision = "millisecond"), class = "clock_warning_parse_failures"),
247-
as_zoned_time(naive_seconds(NA) + duration_milliseconds(NA), zone = "UTC")
253+
expect_warning(
254+
expect_identical(
255+
zoned_time_parse_complete(x, precision = "millisecond"),
256+
as_zoned_time(naive_seconds(NA) + duration_milliseconds(NA), zone = "UTC")
257+
),
258+
class = "clock_warning_parse_failures"
248259
)
249260
})
250261

@@ -263,12 +274,12 @@ test_that("parsing fails when undocumented rounding behavior would result in inv
263274

264275
# Requesting `%6S` parses the full `59.550`, which is immediately rounded to `60` which looks invalid.
265276
# The correct way to do this is to parse the milliseconds, then round.
266-
expect_identical(
267-
expect_warning(
277+
expect_warning(
278+
expect_identical(
268279
zoned_time_parse_complete(x, precision = "second", format = "%Y-%m-%d %H:%M:%6S%Ez[%Z]"),
269-
class = "clock_warning_parse_failures"
280+
as_zoned_time(as_naive_time(year_month_day(NA, NA, NA, NA, NA, NA)), zone = "UTC")
270281
),
271-
as_zoned_time(as_naive_time(year_month_day(NA, NA, NA, NA, NA, NA)), zone = "UTC")
282+
class = "clock_warning_parse_failures"
272283
)
273284
})
274285

@@ -322,28 +333,32 @@ test_that("abbreviation is used to resolve ambiguity", {
322333
})
323334

324335
test_that("nonexistent times are NAs", {
325-
expect_identical(
326-
expect_warning(
327-
zoned_time_parse_abbrev("1970-04-26 02:30:00 EST", "America/New_York")
328-
),
329-
as_zoned_time(sys_seconds(NA), "America/New_York")
336+
expect_warning(
337+
expect_identical(
338+
zoned_time_parse_abbrev("1970-04-26 02:30:00 EST", "America/New_York"),
339+
as_zoned_time(sys_seconds(NA), "America/New_York")
340+
)
330341
)
331342
})
332343

333344
test_that("abbreviation must match the one implied from naive + time zone name lookup", {
334345
x <- "1970-01-01 00:00:00 FOOBAR"
335346

336-
expect_identical(
337-
expect_warning(zoned_time_parse_abbrev(x, "America/New_York")),
338-
as_zoned_time(sys_days(NA), "America/New_York")
347+
expect_warning(
348+
expect_identical(
349+
zoned_time_parse_abbrev(x, "America/New_York"),
350+
as_zoned_time(sys_days(NA), "America/New_York")
351+
)
339352
)
340353

341354
# Should be EST
342355
x <- "1970-01-01 00:00:00 EDT"
343356

344-
expect_identical(
345-
expect_warning(zoned_time_parse_abbrev(x, "America/New_York")),
346-
as_zoned_time(sys_days(NA), "America/New_York")
357+
expect_warning(
358+
expect_identical(
359+
zoned_time_parse_abbrev(x, "America/New_York"),
360+
as_zoned_time(sys_days(NA), "America/New_York")
361+
)
347362
)
348363

349364
expect_snapshot(zoned_time_parse_abbrev(x, "America/New_York"))

0 commit comments

Comments
 (0)