Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3df4dcce
Commit
3df4dcce
authored
Nov 17, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19605: Use specific asserts in datetime tests
parent
3afec4e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
79 deletions
+80
-79
Lib/test/datetimetester.py
Lib/test/datetimetester.py
+80
-79
No files found.
Lib/test/datetimetester.py
View file @
3df4dcce
...
...
@@ -115,11 +115,11 @@ class TestTZInfo(unittest.TestCase):
# carry no data), but they need to be picklable anyway else
# concrete subclasses can't be pickled.
orig
=
tzinfo
.
__new__
(
tzinfo
)
self
.
assert
True
(
type
(
orig
)
is
tzinfo
)
self
.
assert
Is
(
type
(
orig
),
tzinfo
)
for
pickler
,
unpickler
,
proto
in
pickle_choices
:
green
=
pickler
.
dumps
(
orig
,
proto
)
derived
=
unpickler
.
loads
(
green
)
self
.
assert
True
(
type
(
derived
)
is
tzinfo
)
self
.
assert
Is
(
type
(
derived
),
tzinfo
)
def
test_pickling_subclass
(
self
):
# Make sure we can pickle/unpickle an instance of a subclass.
...
...
@@ -479,9 +479,9 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
self
.
assertEqual
(
t1
,
t2
)
self
.
assertTrue
(
t1
<=
t2
)
self
.
assertTrue
(
t1
>=
t2
)
self
.
assert
True
(
not
t1
!=
t2
)
self
.
assert
True
(
not
t1
<
t2
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
False
(
t1
!=
t2
)
self
.
assert
False
(
t1
<
t2
)
self
.
assert
False
(
t1
>
t2
)
for
args
in
(
3
,
3
,
3
),
(
2
,
4
,
4
),
(
2
,
3
,
5
):
t2
=
timedelta
(
*
args
)
# this is larger than t1
...
...
@@ -491,12 +491,12 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
self
.
assertTrue
(
t2
>=
t1
)
self
.
assertTrue
(
t1
!=
t2
)
self
.
assertTrue
(
t2
!=
t1
)
self
.
assert
True
(
not
t1
==
t2
)
self
.
assert
True
(
not
t2
==
t1
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
True
(
not
t2
<
t1
)
self
.
assert
True
(
not
t1
>=
t2
)
self
.
assert
True
(
not
t2
<=
t1
)
self
.
assert
False
(
t1
==
t2
)
self
.
assert
False
(
t2
==
t1
)
self
.
assert
False
(
t1
>
t2
)
self
.
assert
False
(
t2
<
t1
)
self
.
assert
False
(
t1
>=
t2
)
self
.
assert
False
(
t2
<=
t1
)
for
badarg
in
OTHERSTUFF
:
self
.
assertEqual
(
t1
==
badarg
,
False
)
...
...
@@ -629,7 +629,7 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
self
.
assertTrue
(
timedelta
(
0
,
1
))
self
.
assertTrue
(
timedelta
(
0
,
0
,
1
))
self
.
assertTrue
(
timedelta
(
microseconds
=
1
))
self
.
assert
True
(
not
timedelta
(
0
))
self
.
assert
False
(
timedelta
(
0
))
def
test_subclass_timedelta
(
self
):
...
...
@@ -645,17 +645,17 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
return
round
(
sum
)
t1
=
T
(
days
=
1
)
self
.
assert
True
(
type
(
t1
)
is
T
)
self
.
assert
Is
(
type
(
t1
),
T
)
self
.
assertEqual
(
t1
.
as_hours
(),
24
)
t2
=
T
(
days
=-
1
,
seconds
=-
3600
)
self
.
assert
True
(
type
(
t2
)
is
T
)
self
.
assert
Is
(
type
(
t2
),
T
)
self
.
assertEqual
(
t2
.
as_hours
(),
-
25
)
t3
=
t1
+
t2
self
.
assert
True
(
type
(
t3
)
is
timedelta
)
self
.
assert
Is
(
type
(
t3
),
timedelta
)
t4
=
T
.
from_td
(
t3
)
self
.
assert
True
(
type
(
t4
)
is
T
)
self
.
assert
Is
(
type
(
t4
),
T
)
self
.
assertEqual
(
t3
.
days
,
t4
.
days
)
self
.
assertEqual
(
t3
.
seconds
,
t4
.
seconds
)
self
.
assertEqual
(
t3
.
microseconds
,
t4
.
microseconds
)
...
...
@@ -1007,8 +1007,9 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
# It worked or it didn't. If it didn't, assume it's reason #2, and
# let the test pass if they're within half a second of each other.
self
.
assertTrue
(
today
==
todayagain
or
abs
(
todayagain
-
today
)
<
timedelta
(
seconds
=
0.5
))
if
today
!=
todayagain
:
self
.
assertAlmostEqual
(
todayagain
,
today
,
delta
=
timedelta
(
seconds
=
0.5
))
def
test_weekday
(
self
):
for
i
in
range
(
7
):
...
...
@@ -1202,9 +1203,9 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
self
.
assertEqual
(
t1
,
t2
)
self
.
assertTrue
(
t1
<=
t2
)
self
.
assertTrue
(
t1
>=
t2
)
self
.
assert
True
(
not
t1
!=
t2
)
self
.
assert
True
(
not
t1
<
t2
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
False
(
t1
!=
t2
)
self
.
assert
False
(
t1
<
t2
)
self
.
assert
False
(
t1
>
t2
)
for
args
in
(
3
,
3
,
3
),
(
2
,
4
,
4
),
(
2
,
3
,
5
):
t2
=
self
.
theclass
(
*
args
)
# this is larger than t1
...
...
@@ -1214,12 +1215,12 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
self
.
assertTrue
(
t2
>=
t1
)
self
.
assertTrue
(
t1
!=
t2
)
self
.
assertTrue
(
t2
!=
t1
)
self
.
assert
True
(
not
t1
==
t2
)
self
.
assert
True
(
not
t2
==
t1
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
True
(
not
t2
<
t1
)
self
.
assert
True
(
not
t1
>=
t2
)
self
.
assert
True
(
not
t2
<=
t1
)
self
.
assert
False
(
t1
==
t2
)
self
.
assert
False
(
t2
==
t1
)
self
.
assert
False
(
t1
>
t2
)
self
.
assert
False
(
t2
<
t1
)
self
.
assert
False
(
t1
>=
t2
)
self
.
assert
False
(
t2
<=
t1
)
for
badarg
in
OTHERSTUFF
:
self
.
assertEqual
(
t1
==
badarg
,
False
)
...
...
@@ -1690,9 +1691,9 @@ class TestDateTime(TestDate):
self
.
assertEqual
(
t1
,
t2
)
self
.
assertTrue
(
t1
<=
t2
)
self
.
assertTrue
(
t1
>=
t2
)
self
.
assert
True
(
not
t1
!=
t2
)
self
.
assert
True
(
not
t1
<
t2
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
False
(
t1
!=
t2
)
self
.
assert
False
(
t1
<
t2
)
self
.
assert
False
(
t1
>
t2
)
for
i
in
range
(
len
(
args
)):
newargs
=
args
[:]
...
...
@@ -1704,12 +1705,12 @@ class TestDateTime(TestDate):
self
.
assertTrue
(
t2
>=
t1
)
self
.
assertTrue
(
t1
!=
t2
)
self
.
assertTrue
(
t2
!=
t1
)
self
.
assert
True
(
not
t1
==
t2
)
self
.
assert
True
(
not
t2
==
t1
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
True
(
not
t2
<
t1
)
self
.
assert
True
(
not
t1
>=
t2
)
self
.
assert
True
(
not
t2
<=
t1
)
self
.
assert
False
(
t1
==
t2
)
self
.
assert
False
(
t2
==
t1
)
self
.
assert
False
(
t1
>
t2
)
self
.
assert
False
(
t2
<
t1
)
self
.
assert
False
(
t1
>=
t2
)
self
.
assert
False
(
t2
<=
t1
)
# A helper for timestamp constructor tests.
...
...
@@ -1846,7 +1847,7 @@ class TestDateTime(TestDate):
if
abs
(
from_timestamp
-
from_now
)
<=
tolerance
:
break
# Else try again a few times.
self
.
assert
True
(
abs
(
from_timestamp
-
from_now
)
<=
tolerance
)
self
.
assert
LessEqual
(
abs
(
from_timestamp
-
from_now
),
tolerance
)
def
test_strptime
(
self
):
string
=
'2004-12-01 13:02:47.197'
...
...
@@ -2072,9 +2073,9 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
self
.
assertEqual
(
t1
,
t2
)
self
.
assertTrue
(
t1
<=
t2
)
self
.
assertTrue
(
t1
>=
t2
)
self
.
assert
True
(
not
t1
!=
t2
)
self
.
assert
True
(
not
t1
<
t2
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
False
(
t1
!=
t2
)
self
.
assert
False
(
t1
<
t2
)
self
.
assert
False
(
t1
>
t2
)
for
i
in
range
(
len
(
args
)):
newargs
=
args
[:]
...
...
@@ -2086,12 +2087,12 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
self
.
assertTrue
(
t2
>=
t1
)
self
.
assertTrue
(
t1
!=
t2
)
self
.
assertTrue
(
t2
!=
t1
)
self
.
assert
True
(
not
t1
==
t2
)
self
.
assert
True
(
not
t2
==
t1
)
self
.
assert
True
(
not
t1
>
t2
)
self
.
assert
True
(
not
t2
<
t1
)
self
.
assert
True
(
not
t1
>=
t2
)
self
.
assert
True
(
not
t2
<=
t1
)
self
.
assert
False
(
t1
==
t2
)
self
.
assert
False
(
t2
==
t1
)
self
.
assert
False
(
t1
>
t2
)
self
.
assert
False
(
t2
<
t1
)
self
.
assert
False
(
t1
>=
t2
)
self
.
assert
False
(
t2
<=
t1
)
for
badarg
in
OTHERSTUFF
:
self
.
assertEqual
(
t1
==
badarg
,
False
)
...
...
@@ -2269,8 +2270,8 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
self
.
assertTrue
(
cls
(
0
,
1
))
self
.
assertTrue
(
cls
(
0
,
0
,
1
))
self
.
assertTrue
(
cls
(
0
,
0
,
0
,
1
))
self
.
assert
True
(
not
cls
(
0
))
self
.
assert
True
(
not
cls
())
self
.
assert
False
(
cls
(
0
))
self
.
assert
False
(
cls
())
def
test_replace
(
self
):
cls
=
self
.
theclass
...
...
@@ -2367,7 +2368,7 @@ class TZInfoBase:
def
utcoffset
(
self
,
dt
):
pass
b
=
BetterTry
()
t
=
cls
(
1
,
1
,
1
,
tzinfo
=
b
)
self
.
assert
True
(
t
.
tzinfo
is
b
)
self
.
assert
Is
(
t
.
tzinfo
,
b
)
def
test_utc_offset_out_of_bounds
(
self
):
class
Edgy
(
tzinfo
):
...
...
@@ -2406,9 +2407,9 @@ class TZInfoBase:
for
t
in
(
cls
(
1
,
1
,
1
),
cls
(
1
,
1
,
1
,
tzinfo
=
None
),
cls
(
1
,
1
,
1
,
tzinfo
=
C1
())):
self
.
assert
True
(
t
.
utcoffset
()
is
None
)
self
.
assert
True
(
t
.
dst
()
is
None
)
self
.
assert
True
(
t
.
tzname
()
is
None
)
self
.
assert
IsNone
(
t
.
utcoffset
()
)
self
.
assert
IsNone
(
t
.
dst
()
)
self
.
assert
IsNone
(
t
.
tzname
()
)
class
C3
(
tzinfo
):
def
utcoffset
(
self
,
dt
):
return
timedelta
(
minutes
=-
1439
)
...
...
@@ -2503,7 +2504,7 @@ class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
self
.
assertEqual
(
t
.
minute
,
0
)
self
.
assertEqual
(
t
.
second
,
0
)
self
.
assertEqual
(
t
.
microsecond
,
0
)
self
.
assert
True
(
t
.
tzinfo
is
None
)
self
.
assert
IsNone
(
t
.
tzinfo
)
def
test_zones
(
self
):
est
=
FixedOffset
(
-
300
,
"EST"
,
1
)
...
...
@@ -2518,25 +2519,25 @@ class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
self
.
assertEqual
(
t1
.
tzinfo
,
est
)
self
.
assertEqual
(
t2
.
tzinfo
,
utc
)
self
.
assertEqual
(
t3
.
tzinfo
,
met
)
self
.
assert
True
(
t4
.
tzinfo
is
None
)
self
.
assert
IsNone
(
t4
.
tzinfo
)
self
.
assertEqual
(
t5
.
tzinfo
,
utc
)
self
.
assertEqual
(
t1
.
utcoffset
(),
timedelta
(
minutes
=-
300
))
self
.
assertEqual
(
t2
.
utcoffset
(),
timedelta
(
minutes
=
0
))
self
.
assertEqual
(
t3
.
utcoffset
(),
timedelta
(
minutes
=
60
))
self
.
assert
True
(
t4
.
utcoffset
()
is
None
)
self
.
assert
IsNone
(
t4
.
utcoffset
()
)
self
.
assertRaises
(
TypeError
,
t1
.
utcoffset
,
"no args"
)
self
.
assertEqual
(
t1
.
tzname
(),
"EST"
)
self
.
assertEqual
(
t2
.
tzname
(),
"UTC"
)
self
.
assertEqual
(
t3
.
tzname
(),
"MET"
)
self
.
assert
True
(
t4
.
tzname
()
is
None
)
self
.
assert
IsNone
(
t4
.
tzname
()
)
self
.
assertRaises
(
TypeError
,
t1
.
tzname
,
"no args"
)
self
.
assertEqual
(
t1
.
dst
(),
timedelta
(
minutes
=
1
))
self
.
assertEqual
(
t2
.
dst
(),
timedelta
(
minutes
=-
2
))
self
.
assertEqual
(
t3
.
dst
(),
timedelta
(
minutes
=
3
))
self
.
assert
True
(
t4
.
dst
()
is
None
)
self
.
assert
IsNone
(
t4
.
dst
()
)
self
.
assertRaises
(
TypeError
,
t1
.
dst
,
"no args"
)
self
.
assertEqual
(
hash
(
t1
),
hash
(
t2
))
...
...
@@ -2633,10 +2634,10 @@ class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
self
.
assertTrue
(
t
)
t
=
cls
(
5
,
tzinfo
=
FixedOffset
(
300
,
""
))
self
.
assert
True
(
not
t
)
self
.
assert
False
(
t
)
t
=
cls
(
23
,
59
,
tzinfo
=
FixedOffset
(
23
*
60
+
59
,
""
))
self
.
assert
True
(
not
t
)
self
.
assert
False
(
t
)
# Mostly ensuring this doesn't overflow internally.
t
=
cls
(
0
,
tzinfo
=
FixedOffset
(
23
*
60
+
59
,
""
))
...
...
@@ -2674,13 +2675,13 @@ class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
# Ensure we can get rid of a tzinfo.
self
.
assertEqual
(
base
.
tzname
(),
"+100"
)
base2
=
base
.
replace
(
tzinfo
=
None
)
self
.
assert
True
(
base2
.
tzinfo
is
None
)
self
.
assert
True
(
base2
.
tzname
()
is
None
)
self
.
assert
IsNone
(
base2
.
tzinfo
)
self
.
assert
IsNone
(
base2
.
tzname
()
)
# Ensure we can add one.
base3
=
base2
.
replace
(
tzinfo
=
z100
)
self
.
assertEqual
(
base
,
base3
)
self
.
assert
True
(
base
.
tzinfo
is
base3
.
tzinfo
)
self
.
assert
Is
(
base
.
tzinfo
,
base3
.
tzinfo
)
# Out of bounds.
base
=
cls
(
1
)
...
...
@@ -2915,7 +2916,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
tz55
=
FixedOffset
(
-
330
,
"west 5:30"
)
timeaware
=
now
.
time
().
replace
(
tzinfo
=
tz55
)
nowaware
=
self
.
theclass
.
combine
(
now
.
date
(),
timeaware
)
self
.
assert
True
(
nowaware
.
tzinfo
is
tz55
)
self
.
assert
Is
(
nowaware
.
tzinfo
,
tz55
)
self
.
assertEqual
(
nowaware
.
timetz
(),
timeaware
)
# Can't mix aware and non-aware.
...
...
@@ -2934,15 +2935,15 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
# Adding a delta should preserve tzinfo.
delta
=
timedelta
(
weeks
=
1
,
minutes
=
12
,
microseconds
=
5678
)
nowawareplus
=
nowaware
+
delta
self
.
assert
True
(
nowaware
.
tzinfo
is
tz55
)
self
.
assert
Is
(
nowaware
.
tzinfo
,
tz55
)
nowawareplus2
=
delta
+
nowaware
self
.
assert
True
(
nowawareplus2
.
tzinfo
is
tz55
)
self
.
assert
Is
(
nowawareplus2
.
tzinfo
,
tz55
)
self
.
assertEqual
(
nowawareplus
,
nowawareplus2
)
# that - delta should be what we started with, and that - what we
# started with should be delta.
diff
=
nowawareplus
-
delta
self
.
assert
True
(
diff
.
tzinfo
is
tz55
)
self
.
assert
Is
(
diff
.
tzinfo
,
tz55
)
self
.
assertEqual
(
nowaware
,
diff
)
self
.
assertRaises
(
TypeError
,
lambda
:
delta
-
nowawareplus
)
self
.
assertEqual
(
nowawareplus
-
nowaware
,
delta
)
...
...
@@ -2951,7 +2952,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
tzr
=
FixedOffset
(
random
.
randrange
(
-
1439
,
1440
),
"randomtimezone"
)
# Attach it to nowawareplus.
nowawareplus
=
nowawareplus
.
replace
(
tzinfo
=
tzr
)
self
.
assert
True
(
nowawareplus
.
tzinfo
is
tzr
)
self
.
assert
Is
(
nowawareplus
.
tzinfo
,
tzr
)
# Make sure the difference takes the timezone adjustments into account.
got
=
nowaware
-
nowawareplus
# Expected: (nowaware base - nowaware offset) -
...
...
@@ -2983,7 +2984,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
off42
=
FixedOffset
(
42
,
"42"
)
another
=
meth
(
off42
)
again
=
meth
(
tz
=
off42
)
self
.
assert
True
(
another
.
tzinfo
is
again
.
tzinfo
)
self
.
assert
Is
(
another
.
tzinfo
,
again
.
tzinfo
)
self
.
assertEqual
(
another
.
utcoffset
(),
timedelta
(
minutes
=
42
))
# Bad argument with and w/o naming the keyword.
self
.
assertRaises
(
TypeError
,
meth
,
16
)
...
...
@@ -3001,7 +3002,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
timezone
(
timedelta
(
hours
=
15
,
minutes
=
58
),
"weirdtz"
),]:
for
dummy
in
range
(
3
):
now
=
datetime
.
now
(
weirdtz
)
self
.
assert
True
(
now
.
tzinfo
is
weirdtz
)
self
.
assert
Is
(
now
.
tzinfo
,
weirdtz
)
utcnow
=
datetime
.
utcnow
().
replace
(
tzinfo
=
utc
)
now2
=
utcnow
.
astimezone
(
weirdtz
)
if
abs
(
now
-
now2
)
<
timedelta
(
seconds
=
30
):
...
...
@@ -3022,7 +3023,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
off42
=
FixedOffset
(
42
,
"42"
)
another
=
meth
(
ts
,
off42
)
again
=
meth
(
ts
,
tz
=
off42
)
self
.
assert
True
(
another
.
tzinfo
is
again
.
tzinfo
)
self
.
assert
Is
(
another
.
tzinfo
,
again
.
tzinfo
)
self
.
assertEqual
(
another
.
utcoffset
(),
timedelta
(
minutes
=
42
))
# Bad argument with and w/o naming the keyword.
self
.
assertRaises
(
TypeError
,
meth
,
ts
,
16
)
...
...
@@ -3233,13 +3234,13 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
# Ensure we can get rid of a tzinfo.
self
.
assertEqual
(
base
.
tzname
(),
"+100"
)
base2
=
base
.
replace
(
tzinfo
=
None
)
self
.
assert
True
(
base2
.
tzinfo
is
None
)
self
.
assert
True
(
base2
.
tzname
()
is
None
)
self
.
assert
IsNone
(
base2
.
tzinfo
)
self
.
assert
IsNone
(
base2
.
tzname
()
)
# Ensure we can add one.
base3
=
base2
.
replace
(
tzinfo
=
z100
)
self
.
assertEqual
(
base
,
base3
)
self
.
assert
True
(
base
.
tzinfo
is
base3
.
tzinfo
)
self
.
assert
Is
(
base
.
tzinfo
,
base3
.
tzinfo
)
# Out of bounds.
base
=
cls
(
2000
,
2
,
29
)
...
...
@@ -3252,18 +3253,18 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
fm5h
=
FixedOffset
(
-
timedelta
(
hours
=
5
),
"m300"
)
dt
=
self
.
theclass
.
now
(
tz
=
f44m
)
self
.
assert
True
(
dt
.
tzinfo
is
f44m
)
self
.
assert
Is
(
dt
.
tzinfo
,
f44m
)
# Replacing with degenerate tzinfo raises an exception.
self
.
assertRaises
(
ValueError
,
dt
.
astimezone
,
fnone
)
# Replacing with same tzinfo makes no change.
x
=
dt
.
astimezone
(
dt
.
tzinfo
)
self
.
assert
True
(
x
.
tzinfo
is
f44m
)
self
.
assert
Is
(
x
.
tzinfo
,
f44m
)
self
.
assertEqual
(
x
.
date
(),
dt
.
date
())
self
.
assertEqual
(
x
.
time
(),
dt
.
time
())
# Replacing with different tzinfo does adjust.
got
=
dt
.
astimezone
(
fm5h
)
self
.
assert
True
(
got
.
tzinfo
is
fm5h
)
self
.
assert
Is
(
got
.
tzinfo
,
fm5h
)
self
.
assertEqual
(
got
.
utcoffset
(),
timedelta
(
hours
=-
5
))
expected
=
dt
-
dt
.
utcoffset
()
# in effect, convert to UTC
expected
+=
fm5h
.
utcoffset
(
dt
)
# and from there to local time
...
...
@@ -3271,7 +3272,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
self
.
assertEqual
(
got
.
date
(),
expected
.
date
())
self
.
assertEqual
(
got
.
time
(),
expected
.
time
())
self
.
assertEqual
(
got
.
timetz
(),
expected
.
timetz
())
self
.
assert
True
(
got
.
tzinfo
is
expected
.
tzinfo
)
self
.
assert
Is
(
got
.
tzinfo
,
expected
.
tzinfo
)
self
.
assertEqual
(
got
,
expected
)
@
support
.
run_with_tz
(
'UTC'
)
...
...
@@ -3732,8 +3733,8 @@ class Oddballs(unittest.TestCase):
as_datetime
=
datetime
.
combine
(
as_date
,
time
())
self
.
assertTrue
(
as_date
!=
as_datetime
)
self
.
assertTrue
(
as_datetime
!=
as_date
)
self
.
assert
True
(
not
as_date
==
as_datetime
)
self
.
assert
True
(
not
as_datetime
==
as_date
)
self
.
assert
False
(
as_date
==
as_datetime
)
self
.
assert
False
(
as_datetime
==
as_date
)
self
.
assertRaises
(
TypeError
,
lambda
:
as_date
<
as_datetime
)
self
.
assertRaises
(
TypeError
,
lambda
:
as_datetime
<
as_date
)
self
.
assertRaises
(
TypeError
,
lambda
:
as_date
<=
as_datetime
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment