remove some noises in tests (#16448)

This commit is contained in:
flywind 2020-12-27 07:45:57 -06:00 • committed by GitHub
commit 271f68259b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 140 additions and 181 deletions

View file

@ -116,7 +116,7 @@ template usingTimezone(tz: string, body: untyped) =
body
putEnv("TZ", oldZone)
suite "ttimes":
block: # ttimes
# Generate tests for multiple timezone files where available
# Set the TZ env var for each test
@ -143,7 +143,7 @@ suite "ttimes":
test "parseTest":
runTimezoneTests()
test "dst handling":
block: # dst handling
usingTimezone("Europe/Stockholm"):
# In case of an impossible time, the time is moved to after the
# impossible time period
@ -163,7 +163,7 @@ suite "ttimes":
check initDateTime(21, mOct, 2017, 01, 00, 00).format(f) ==
"2017-10-21 01:00 +02:00"
test "issue #6520":
block: # issue #6520
usingTimezone("Europe/Stockholm"):
var local = fromUnix(1469275200).local
var utc = fromUnix(1469275200).utc
@ -172,19 +172,19 @@ suite "ttimes":
local.utcOffset = 0
check claimedOffset == utc.toTime - local.toTime
test "issue #5704":
block: # issue #5704
usingTimezone("Asia/Seoul"):
let diff = parse("19700101-000000", "yyyyMMdd-hhmmss").toTime -
parse("19000101-000000", "yyyyMMdd-hhmmss").toTime
check diff == initDuration(seconds = 2208986872)
test "issue #6465":
block: # issue #6465
usingTimezone("Europe/Stockholm"):
let dt = parse("2017-03-25 12:00", "yyyy-MM-dd hh:mm")
check $(dt + initTimeInterval(days = 1)) == "2017-03-26T12:00:00+02:00"
check $(dt + initDuration(days = 1)) == "2017-03-26T13:00:00+02:00"
test "adding/subtracting time across dst":
block: # adding/subtracting time across dst
usingTimezone("Europe/Stockholm"):
let dt1 = initDateTime(26, mMar, 2017, 03, 00, 00)
check $(dt1 - 1.seconds) == "2017-03-26T01:59:59+01:00"
@ -192,55 +192,55 @@ suite "ttimes":
var dt2 = initDateTime(29, mOct, 2017, 02, 59, 59)
check $(dt2 + 1.seconds) == "2017-10-29T02:00:00+01:00"
test "datetime before epoch":
block: # datetime before epoch
check $fromUnix(-2147483648).utc == "1901-12-13T20:45:52Z"
test "incorrect inputs: empty string":
block: # incorrect inputs: empty string
parseTestExcp("", "yyyy-MM-dd")
test "incorrect inputs: year":
block: # incorrect inputs: year
parseTestExcp("20-02-19", "yyyy-MM-dd")
test "incorrect inputs: month number":
block: # incorrect inputs: month number
parseTestExcp("2018-2-19", "yyyy-MM-dd")
test "incorrect inputs: month name":
block: # incorrect inputs: month name
parseTestExcp("2018-Fe", "yyyy-MMM-dd")
test "incorrect inputs: day":
block: # incorrect inputs: day
parseTestExcp("2018-02-1", "yyyy-MM-dd")
test "incorrect inputs: day of week":
block: # incorrect inputs: day of week
parseTestExcp("2018-Feb-Mo", "yyyy-MMM-ddd")
test "incorrect inputs: hour":
block: # incorrect inputs: hour
parseTestExcp("2018-02-19 1:30", "yyyy-MM-dd hh:mm")
test "incorrect inputs: minute":
block: # incorrect inputs: minute
parseTestExcp("2018-02-19 16:3", "yyyy-MM-dd hh:mm")
test "incorrect inputs: second":
block: # incorrect inputs: second
parseTestExcp("2018-02-19 16:30:0", "yyyy-MM-dd hh:mm:ss")
test "incorrect inputs: timezone (z)":
block: # incorrect inputs: timezone (z)
parseTestExcp("2018-02-19 16:30:00 ", "yyyy-MM-dd hh:mm:ss z")
test "incorrect inputs: timezone (zz) 1":
block: # incorrect inputs: timezone (zz) 1
parseTestExcp("2018-02-19 16:30:00 ", "yyyy-MM-dd hh:mm:ss zz")
test "incorrect inputs: timezone (zz) 2":
block: # incorrect inputs: timezone (zz) 2
parseTestExcp("2018-02-19 16:30:00 +1", "yyyy-MM-dd hh:mm:ss zz")
test "incorrect inputs: timezone (zzz) 1":
block: # incorrect inputs: timezone (zzz) 1
parseTestExcp("2018-02-19 16:30:00 ", "yyyy-MM-dd hh:mm:ss zzz")
test "incorrect inputs: timezone (zzz) 2":
block: # incorrect inputs: timezone (zzz) 2
parseTestExcp("2018-02-19 16:30:00 +01:", "yyyy-MM-dd hh:mm:ss zzz")
test "incorrect inputs: timezone (zzz) 3":
block: # incorrect inputs: timezone (zzz) 3
parseTestExcp("2018-02-19 16:30:00 +01:0", "yyyy-MM-dd hh:mm:ss zzz")
test "incorrect inputs: year (yyyy/uuuu)":
block: # incorrect inputs: year (yyyy/uuuu)
parseTestExcp("-0001", "yyyy")
parseTestExcp("-0001", "YYYY")
parseTestExcp("1", "yyyy")
@ -249,7 +249,7 @@ suite "ttimes":
parseTestExcp("12345", "uuuu")
parseTestExcp("-1 BC", "UUUU g")
test "incorrect inputs: invalid sign":
block: # incorrect inputs: invalid sign
parseTestExcp("+1", "YYYY")
parseTestExcp("+1", "dd")
parseTestExcp("+1", "MM")
@ -257,10 +257,10 @@ suite "ttimes":
parseTestExcp("+1", "mm")
parseTestExcp("+1", "ss")
test "_ as a separator":
block: # _ as a separator
discard parse("2000_01_01", "YYYY'_'MM'_'dd")
test "dynamic timezone":
block: # dynamic timezone
let tz = staticTz(seconds = -9000)
let dt = initDateTime(1, mJan, 2000, 12, 00, 00, tz)
check dt.utcOffset == -9000
@ -269,13 +269,13 @@ suite "ttimes":
check $dt.utc == "2000-01-01T09:30:00Z"
check $dt.utc.inZone(tz) == $dt
test "isLeapYear":
block: # isLeapYear
check isLeapYear(2016)
check (not isLeapYear(2015))
check isLeapYear(2000)
check (not isLeapYear(1900))
test "TimeInterval":
block: # TimeInterval
let t = fromUnix(876124714).utc # Mon 6 Oct 08:58:34 BST 1997
# Interval tests
let t2 = t - 2.years
@ -287,7 +287,7 @@ suite "ttimes":
check (t + 1.hours).toTime.toUnix == t.toTime.toUnix + 60 * 60
check (t - 1.hours).toTime.toUnix == t.toTime.toUnix - 60 * 60
test "TimeInterval - months":
block: # TimeInterval - months
var dt = initDateTime(1, mFeb, 2017, 00, 00, 00, utc())
check $(dt - initTimeInterval(months = 1)) == "2017-01-01T00:00:00Z"
dt = initDateTime(15, mMar, 2017, 00, 00, 00, utc())
@ -296,7 +296,7 @@ suite "ttimes":
# This happens due to monthday overflow. It's consistent with Phobos.
check $(dt - initTimeInterval(months = 1)) == "2017-03-03T00:00:00Z"
test "duration":
block: # duration
let d = initDuration
check d(hours = 48) + d(days = 5) == d(weeks = 1)
let dt = initDateTime(01, mFeb, 2000, 00, 00, 00, 0, utc()) + d(milliseconds = 1)
@ -316,7 +316,7 @@ suite "ttimes":
check (initDuration(seconds = 1, nanoseconds = 3) <=
initDuration(seconds = 1, nanoseconds = 1)).not
test "large/small dates":
block: # large/small dates
discard initDateTime(1, mJan, -35_000, 12, 00, 00, utc())
# with local tz
discard initDateTime(1, mJan, -35_000, 12, 00, 00)
@ -328,7 +328,7 @@ suite "ttimes":
let dt2 = dt + 35_001.years
check $dt2 == "0001-01-01T12:00:01Z"
test "compare datetimes":
block: # compare datetimes
var dt1 = now()
var dt2 = dt1
check dt1 == dt2
@ -336,7 +336,7 @@ suite "ttimes":
dt2 = dt2 + 1.seconds
check dt1 < dt2
test "adding/subtracting TimeInterval":
block: # adding/subtracting TimeInterval
# add/subtract TimeIntervals and Time/TimeInfo
let now = getTime().utc
let isSpecial = now.isLeapDay
@ -374,14 +374,14 @@ suite "ttimes":
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
test "issue 7620":
block: # issue 7620
let layout = "M/d/yyyy' 'h:mm:ss' 'tt' 'z"
let t7620_am = parse("4/15/2017 12:01:02 AM +0", layout, utc())
check t7620_am.format(layout) == "4/15/2017 12:01:02 AM Z"
let t7620_pm = parse("4/15/2017 12:01:02 PM +0", layout, utc())
check t7620_pm.format(layout) == "4/15/2017 12:01:02 PM Z"
test "format":
block: # format
var dt = initDateTime(1, mJan, -0001,
17, 01, 02, 123_456_789,
staticTz(hours = 1, minutes = 2, seconds = 3))
@ -450,7 +450,7 @@ suite "ttimes":
doAssert dt.format("zz") == tz[2]
doAssert dt.format("zzz") == tz[3]
test "format locale":
block: # format locale
let loc = DateTimeLocale(
MMM: ["Fir","Sec","Thi","Fou","Fif","Six","Sev","Eig","Nin","Ten","Ele","Twe"],
MMMM: ["Firsty", "Secondy", "Thirdy", "Fourthy", "Fifthy", "Sixthy", "Seventhy", "Eighthy", "Ninthy", "Tenthy", "Eleventhy", "Twelfthy"],
@ -467,7 +467,7 @@ suite "ttimes":
check dt.format("MMM", loc) == "Fir"
check dt.format("MMMM", loc) == "Firsty"
test "parse":
block: # parse
check $parse("20180101", "yyyyMMdd", utc()) == "2018-01-01T00:00:00Z"
parseTestExcp("+120180101", "yyyyMMdd")
@ -488,7 +488,7 @@ suite "ttimes":
parseTestExcp("2000 A", "yyyy g")
test "parse locale":
block: # parse locale
let loc = DateTimeLocale(
MMM: ["Fir","Sec","Thi","Fou","Fif","Six","Sev","Eig","Nin","Ten","Ele","Twe"],
MMMM: ["Firsty", "Secondy", "Thirdy", "Fourthy", "Fifthy", "Sixthy", "Seventhy", "Eighthy", "Ninthy", "Tenthy", "Eleventhy", "Twelfthy"],
@ -498,7 +498,7 @@ suite "ttimes":
check $parse("02 Fir 2019", "dd MMM yyyy", utc(), loc) == "2019-01-02T00:00:00Z"
check $parse("Fourthy 6, 2017", "MMMM d, yyyy", utc(), loc) == "2017-04-06T00:00:00Z"
test "timezoneConversion":
block: # timezoneConversion
var l = now()
let u = l.utc
l = u.local
@ -506,7 +506,7 @@ suite "ttimes":
check l.timezone == local()
check u.timezone == utc()
test "getDayOfWeek":
block: # getDayOfWeek
check getDayOfWeek(01, mJan, 0000) == dSat
check getDayOfWeek(01, mJan, -0023) == dSat
check getDayOfWeek(21, mSep, 1900) == dFri
@ -515,29 +515,29 @@ suite "ttimes":
check getDayOfWeek(01, mJan, 2000) == dSat
check getDayOfWeek(01, mJan, 2021) == dFri
test "between - simple":
block: # between - simple
let x = initDateTime(10, mJan, 2018, 13, 00, 00)
let y = initDateTime(11, mJan, 2018, 12, 00, 00)
doAssert x + between(x, y) == y
test "between - dst start":
block: # between - dst start
usingTimezone("Europe/Stockholm"):
let x = initDateTime(25, mMar, 2018, 00, 00, 00)
let y = initDateTime(25, mMar, 2018, 04, 00, 00)
doAssert x + between(x, y) == y
test "between - empty interval":
block: # between - empty interval
let x = now()
let y = x
doAssert x + between(x, y) == y
test "between - dst end":
block: # between - dst end
usingTimezone("Europe/Stockholm"):
let x = initDateTime(27, mOct, 2018, 02, 00, 00)
let y = initDateTime(28, mOct, 2018, 01, 00, 00)
doAssert x + between(x, y) == y
test "between - long day":
block: # between - long day
usingTimezone("Europe/Stockholm"):
# This day is 25 hours long in Europe/Stockholm
let x = initDateTime(28, mOct, 2018, 00, 30, 00)
@ -545,7 +545,7 @@ suite "ttimes":
doAssert between(x, y) == 24.hours + 30.minutes
doAssert x + between(x, y) == y
test "between - offset change edge case":
block: # between - offset change edge case
# This test case is important because in this case
# `x + between(x.utc, y.utc) == y` is not true, which is very rare.
usingTimezone("America/Belem"):
@ -554,19 +554,19 @@ suite "ttimes":
doAssert x + between(x, y) == y
doAssert y + between(y, x) == x
test "between - all units":
block: # between - all units
let x = initDateTime(1, mJan, 2000, 00, 00, 00, utc())
let ti = initTimeInterval(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
let y = x + ti
doAssert between(x, y) == ti
doAssert between(y, x) == -ti
test "between - monthday overflow":
block: # between - monthday overflow
let x = initDateTime(31, mJan, 2001, 00, 00, 00, utc())
let y = initDateTime(1, mMar, 2001, 00, 00, 00, utc())
doAssert x + between(x, y) == y
test "between - misc":
block: # between - misc
block:
let x = initDateTime(31, mDec, 2000, 12, 00, 00, utc())
let y = initDateTime(01, mJan, 2001, 00, 00, 00, utc())
@ -608,7 +608,7 @@ suite "ttimes":
doAssert x + between(x, y) == y
doAssert between(x, y) == 1.months + 1.weeks
test "default DateTime": # https://github.com/nim-lang/RFCs/issues/211
block: # default DateTime https://github.com/nim-lang/RFCs/issues/211
var num = 0
for ai in Month: num.inc
check num == 12
@ -634,7 +634,7 @@ suite "ttimes":
expect(AssertionDefect): discard a.format initTimeFormat("yyyy")
expect(AssertionDefect): discard between(a, a)
test "inX procs":
block: # inX procs
doAssert initDuration(seconds = 1).inSeconds == 1
doAssert initDuration(seconds = -1).inSeconds == -1
doAssert initDuration(seconds = -1, nanoseconds = 1).inSeconds == 0