Skip to content

Commit 67129f0

Browse files
authored
wrap tests into local environment and set option (#7378)
1 parent fb81ce0 commit 67129f0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

inst/tests/tests.Rraw

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17078,16 +17078,19 @@ DT = data.table(dates, times)
1707817078
DT_trunc = copy(DT)[, times := as.POSIXct(trunc(times))]
1707917079
tmp = tempfile()
1708017080
## ISO8601 format (%FT%TZ) by default
17081-
fwrite(DT, tmp)
17082-
test(2150.01, fread(tmp), DT) # defaults for fwrite/fread simple and preserving
17083-
fwrite(DT, tmp, dateTimeAs='write.csv') # as write.csv, writes the UTC times as-is not local because the time column has tzone=="UTC", but without the Z marker. Also truncates milliseconds, hence DT_trunc below.
17084-
test(2150.021, env=list(TZ=NULL), sapply(fread(tmp,tz=""), typeof), c(dates="integer", times="character")) # from v1.14.0 tz="" needed to read datetime as character
17085-
test(2150.022, env=list(TZ=NULL), fread(tmp,tz="UTC"), DT_trunc) # user can tell fread to interpret the unmarked datetimes as UTC
17086-
test(2150.023, env=c(TZ='UTC'), fread(tmp), DT_trunc) # TZ environment variable is also recognized
17087-
if (.Platform$OS.type!="windows") {
17088-
test(2150.024, env=c(TZ=''), fread(tmp), DT_trunc) # on Windows this unsets TZ, see ?Sys.setenv
17089-
# blank TZ env variable on non-Windows is recognized as UTC consistent with C and R; but R's tz= argument is the opposite and uses "" for local
17090-
}
17081+
local({
17082+
old=options(digits.secs=0); on.exit(options(old))
17083+
fwrite(DT, tmp)
17084+
test(2150.01, fread(tmp), DT) # defaults for fwrite/fread simple and preserving
17085+
fwrite(DT, tmp, dateTimeAs='write.csv') # as write.csv, writes the UTC times as-is not local because the time column has tzone=="UTC", but without the Z marker. Also truncates milliseconds, hence DT_trunc below.
17086+
test(2150.021, env=list(TZ=NULL), sapply(fread(tmp,tz=""), typeof), c(dates="integer", times="character")) # from v1.14.0 tz="" needed to read datetime as character
17087+
test(2150.022, env=list(TZ=NULL), fread(tmp,tz="UTC"), DT_trunc) # user can tell fread to interpret the unmarked datetimes as UTC
17088+
test(2150.023, env=c(TZ='UTC'), fread(tmp), DT_trunc) # TZ environment variable is also recognized
17089+
if (.Platform$OS.type!="windows") {
17090+
test(2150.024, env=c(TZ=''), fread(tmp), DT_trunc) # on Windows this unsets TZ, see ?Sys.setenv
17091+
# blank TZ env variable on non-Windows is recognized as UTC consistent with C and R; but R's tz= argument is the opposite and uses "" for local
17092+
}
17093+
})
1709117094
# Notes:
1709217095
# - from v1.14.0 tz="" needed
1709317096
# - as.POSIXct puts "" on the result (testing the write.csv version here with missing tzone)

0 commit comments

Comments
 (0)