Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11_abseil
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11_abseil
Commits
5b334624
Commit
5b334624
authored
Feb 16, 2022
by
Ken Oslund
Committed by
Copybara-Service
Feb 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Internal change
PiperOrigin-RevId: 429099528
parent
01fd6b4f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
28 deletions
+10
-28
pybind11_abseil/tests/absl_test.py
+10
-28
No files found.
pybind11_abseil/tests/absl_test.py
View file @
5b334624
...
@@ -4,13 +4,8 @@
...
@@ -4,13 +4,8 @@
# BSD-style license that can be found in the LICENSE file.
# BSD-style license that can be found in the LICENSE file.
"""Tests for absl pybind11 casters."""
"""Tests for absl pybind11 casters."""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
array
import
array
import
datetime
import
datetime
import
sys
from
absl.testing
import
absltest
from
absl.testing
import
absltest
from
absl.testing
import
parameterized
from
absl.testing
import
parameterized
...
@@ -20,25 +15,11 @@ import numpy as np
...
@@ -20,25 +15,11 @@ import numpy as np
from
pybind11_abseil.tests
import
absl_example
from
pybind11_abseil.tests
import
absl_example
if
sys
.
version_info
.
major
>
2
:
DateTime
=
datetime
.
datetime
else
:
class
DateTime
(
datetime
.
datetime
):
def
timestamp
(
self
):
if
self
.
tzinfo
:
with_tz
=
self
else
:
with_tz
=
self
.
replace
(
tzinfo
=
tz
.
gettz
())
# pylint: disable=g-tzinfo-replace
epoch
=
datetime
.
datetime
(
1970
,
1
,
1
,
tzinfo
=
tz
.
tzutc
())
# pylint: disable=g-tzinfo-datetime
return
(
with_tz
-
epoch
)
.
total_seconds
()
class
AbslTimeTest
(
parameterized
.
TestCase
):
class
AbslTimeTest
(
parameterized
.
TestCase
):
SECONDS_IN_DAY
=
24
*
60
*
60
SECONDS_IN_DAY
=
24
*
60
*
60
POSITIVE_SECS
=
3
*
SECONDS_IN_DAY
+
2.5
POSITIVE_SECS
=
3
*
SECONDS_IN_DAY
+
2.5
NEGATIVE_SECS
=
-
3
*
SECONDS_IN_DAY
+
2.5
NEGATIVE_SECS
=
-
3
*
SECONDS_IN_DAY
+
2.5
TEST_DATETIME
=
DateT
ime
(
2000
,
1
,
2
,
3
,
4
,
5
,
int
(
5e5
))
TEST_DATETIME
=
datetime
.
datet
ime
(
2000
,
1
,
2
,
3
,
4
,
5
,
int
(
5e5
))
# Linter error relevant for pytz only.
# Linter error relevant for pytz only.
# pylint: disable=g-tzinfo-replace
# pylint: disable=g-tzinfo-replace
TEST_DATETIME_UTC
=
TEST_DATETIME
.
replace
(
tzinfo
=
tz
.
tzutc
())
TEST_DATETIME_UTC
=
TEST_DATETIME
.
replace
(
tzinfo
=
tz
.
tzutc
())
...
@@ -70,7 +51,7 @@ class AbslTimeTest(parameterized.TestCase):
...
@@ -70,7 +51,7 @@ class AbslTimeTest(parameterized.TestCase):
local_tz
=
tz
.
gettz
()
local_tz
=
tz
.
gettz
()
# pylint: disable=g-tzinfo-datetime
# pylint: disable=g-tzinfo-datetime
# Warning about tzinfo applies to pytz, but we are using dateutil.tz
# Warning about tzinfo applies to pytz, but we are using dateutil.tz
expected_datetime
=
DateT
ime
(
expected_datetime
=
datetime
.
datet
ime
(
year
=
self
.
TEST_DATETIME
.
year
,
year
=
self
.
TEST_DATETIME
.
year
,
month
=
self
.
TEST_DATETIME
.
month
,
month
=
self
.
TEST_DATETIME
.
month
,
day
=
self
.
TEST_DATETIME
.
day
,
day
=
self
.
TEST_DATETIME
.
day
,
...
@@ -85,8 +66,8 @@ class AbslTimeTest(parameterized.TestCase):
...
@@ -85,8 +66,8 @@ class AbslTimeTest(parameterized.TestCase):
self
.
assertEqual
(
expected_datetime
,
absl_example
.
make_datetime
(
secs
))
self
.
assertEqual
(
expected_datetime
,
absl_example
.
make_datetime
(
secs
))
def
test_pass_date
(
self
):
def
test_pass_date
(
self
):
secs
=
DateT
ime
(
self
.
TEST_DATE
.
year
,
self
.
TEST_DATE
.
month
,
secs
=
datetime
.
datet
ime
(
self
.
TEST_DATE
.
year
,
self
.
TEST_DATE
.
month
,
self
.
TEST_DATE
.
day
)
.
timestamp
()
self
.
TEST_DATE
.
day
)
.
timestamp
()
self
.
assertTrue
(
absl_example
.
check_datetime
(
self
.
TEST_DATE
,
secs
))
self
.
assertTrue
(
absl_example
.
check_datetime
(
self
.
TEST_DATE
,
secs
))
def
test_pass_datetime
(
self
):
def
test_pass_datetime
(
self
):
...
@@ -97,7 +78,8 @@ class AbslTimeTest(parameterized.TestCase):
...
@@ -97,7 +78,8 @@ class AbslTimeTest(parameterized.TestCase):
pacific_tz
=
tz
.
gettz
(
'America/Los_Angeles'
)
pacific_tz
=
tz
.
gettz
(
'America/Los_Angeles'
)
# pylint: disable=g-tzinfo-datetime
# pylint: disable=g-tzinfo-datetime
# Warning about tzinfo applies to pytz, but we are using dateutil.tz
# Warning about tzinfo applies to pytz, but we are using dateutil.tz
dt_with_tz
=
DateTime
(
year
=
2020
,
month
=
2
,
day
=
1
,
hour
=
20
,
tzinfo
=
pacific_tz
)
dt_with_tz
=
datetime
.
datetime
(
year
=
2020
,
month
=
2
,
day
=
1
,
hour
=
20
,
tzinfo
=
pacific_tz
)
# pylint: enable=g-tzinfo-datetime
# pylint: enable=g-tzinfo-datetime
secs
=
dt_with_tz
.
timestamp
()
secs
=
dt_with_tz
.
timestamp
()
self
.
assertTrue
(
absl_example
.
check_datetime
(
dt_with_tz
,
secs
))
self
.
assertTrue
(
absl_example
.
check_datetime
(
dt_with_tz
,
secs
))
...
@@ -105,13 +87,13 @@ class AbslTimeTest(parameterized.TestCase):
...
@@ -105,13 +87,13 @@ class AbslTimeTest(parameterized.TestCase):
def
test_pass_datetime_dst_with_timezone
(
self
):
def
test_pass_datetime_dst_with_timezone
(
self
):
pacific_tz
=
tz
.
gettz
(
'America/Los_Angeles'
)
pacific_tz
=
tz
.
gettz
(
'America/Los_Angeles'
)
# pylint: disable=g-tzinfo-datetime
# pylint: disable=g-tzinfo-datetime
dst_end
=
DateT
ime
(
2020
,
11
,
1
,
2
,
0
,
0
,
tzinfo
=
pacific_tz
)
dst_end
=
datetime
.
datet
ime
(
2020
,
11
,
1
,
2
,
0
,
0
,
tzinfo
=
pacific_tz
)
# pylint: enable=g-tzinfo-datetime
# pylint: enable=g-tzinfo-datetime
secs
=
dst_end
.
timestamp
()
secs
=
dst_end
.
timestamp
()
self
.
assertTrue
(
absl_example
.
check_datetime
(
dst_end
,
secs
))
self
.
assertTrue
(
absl_example
.
check_datetime
(
dst_end
,
secs
))
def
test_pass_datetime_dst
(
self
):
def
test_pass_datetime_dst
(
self
):
dst_end
=
DateT
ime
(
2020
,
11
,
1
,
2
,
0
,
0
)
dst_end
=
datetime
.
datet
ime
(
2020
,
11
,
1
,
2
,
0
,
0
)
secs
=
dst_end
.
timestamp
()
secs
=
dst_end
.
timestamp
()
self
.
assertTrue
(
absl_example
.
check_datetime
(
dst_end
,
secs
))
self
.
assertTrue
(
absl_example
.
check_datetime
(
dst_end
,
secs
))
...
@@ -119,14 +101,14 @@ class AbslTimeTest(parameterized.TestCase):
...
@@ -119,14 +101,14 @@ class AbslTimeTest(parameterized.TestCase):
def
test_dst_datetime_from_timestamp
(
self
,
offs
):
def
test_dst_datetime_from_timestamp
(
self
,
offs
):
secs_flip
=
1604224799
# 2020-11-01T02:00:00-08:00
secs_flip
=
1604224799
# 2020-11-01T02:00:00-08:00
secs
=
secs_flip
+
offs
secs
=
secs_flip
+
offs
time_utc
=
DateT
ime
.
fromtimestamp
(
secs
,
tz
.
tzutc
())
time_utc
=
datetime
.
datet
ime
.
fromtimestamp
(
secs
,
tz
.
tzutc
())
time_local_aware
=
time_utc
.
astimezone
(
tz
.
gettz
())
time_local_aware
=
time_utc
.
astimezone
(
tz
.
gettz
())
time_local_naive
=
time_local_aware
.
replace
(
tzinfo
=
None
)
time_local_naive
=
time_local_aware
.
replace
(
tzinfo
=
None
)
for
time
in
(
time_utc
,
time_local_aware
,
time_local_naive
):
for
time
in
(
time_utc
,
time_local_aware
,
time_local_naive
):
self
.
assertTrue
(
absl_example
.
check_datetime
(
time
,
secs
))
self
.
assertTrue
(
absl_example
.
check_datetime
(
time
,
secs
))
def
test_pass_datetime_pre_unix_epoch
(
self
):
def
test_pass_datetime_pre_unix_epoch
(
self
):
dt
=
DateT
ime
(
1969
,
7
,
16
,
10
,
56
,
7
,
microsecond
=
140
)
dt
=
datetime
.
datet
ime
(
1969
,
7
,
16
,
10
,
56
,
7
,
microsecond
=
140
)
secs
=
dt
.
timestamp
()
secs
=
dt
.
timestamp
()
self
.
assertTrue
(
absl_example
.
check_datetime
(
dt
,
secs
))
self
.
assertTrue
(
absl_example
.
check_datetime
(
dt
,
secs
))
...
...
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