Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
acea9f62
Kaydet (Commit)
acea9f62
authored
Eyl 02, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23517: Reintroduce unit tests for the old PyTime API since it's still
used.
üst
67edcc90
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
154 additions
and
0 deletions
+154
-0
test_time.py
Lib/test/test_time.py
+154
-0
No files found.
Lib/test/test_time.py
Dosyayı görüntüle @
acea9f62
...
...
@@ -727,6 +727,9 @@ class TestPytime(unittest.TestCase):
@unittest.skipUnless
(
_testcapi
is
not
None
,
'need the _testcapi module'
)
class
TestPyTime_t
(
unittest
.
TestCase
):
"""
Test the _PyTime_t API.
"""
def
test_FromSeconds
(
self
):
from
_testcapi
import
PyTime_FromSeconds
for
seconds
in
(
0
,
3
,
-
456
,
_testcapi
.
INT_MAX
,
_testcapi
.
INT_MIN
):
...
...
@@ -1041,5 +1044,156 @@ class TestPyTime_t(unittest.TestCase):
self
.
assertEqual
(
PyTime_AsMicroseconds
(
ns
,
rnd
),
ms
)
@unittest.skipUnless
(
_testcapi
is
not
None
,
'need the _testcapi module'
)
class
TestOldPyTime
(
unittest
.
TestCase
):
"""
Test the old _PyTime_t API: _PyTime_ObjectToXXX() functions.
"""
def
setUp
(
self
):
self
.
invalid_values
=
(
-
(
2
**
100
),
2
**
100
,
-
(
2.0
**
100.0
),
2.0
**
100.0
,
)
@support.cpython_only
def
test_time_t
(
self
):
from
_testcapi
import
pytime_object_to_time_t
# Conversion giving the same result for all rounding methods
for
rnd
in
ALL_ROUNDING_METHODS
:
for
obj
,
time_t
in
(
# int
(
0
,
0
),
(
-
1
,
-
1
),
# float
(
1.0
,
1
),
(
-
1.0
,
-
1
),
):
self
.
assertEqual
(
pytime_object_to_time_t
(
obj
,
rnd
),
time_t
)
# Conversion giving different results depending on the rounding method
FLOOR
=
_PyTime
.
ROUND_FLOOR
CEILING
=
_PyTime
.
ROUND_CEILING
HALF_UP
=
_PyTime
.
ROUND_HALF_UP
for
obj
,
time_t
,
rnd
in
(
(
-
1.9
,
-
2
,
FLOOR
),
(
-
1.9
,
-
2
,
HALF_UP
),
(
-
1.9
,
-
1
,
CEILING
),
(
1.9
,
1
,
FLOOR
),
(
1.9
,
2
,
HALF_UP
),
(
1.9
,
2
,
CEILING
),
):
self
.
assertEqual
(
pytime_object_to_time_t
(
obj
,
rnd
),
time_t
)
# Test OverflowError
rnd
=
_PyTime
.
ROUND_FLOOR
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
pytime_object_to_time_t
,
invalid
,
rnd
)
def
test_timeval
(
self
):
from
_testcapi
import
pytime_object_to_timeval
# Conversion giving the same result for all rounding methods
for
rnd
in
ALL_ROUNDING_METHODS
:
for
obj
,
timeval
in
(
# int
(
0
,
(
0
,
0
)),
(
-
1
,
(
-
1
,
0
)),
# float
(
-
1.0
,
(
-
1
,
0
)),
(
-
1.2
,
(
-
2
,
800000
)),
(
-
1e-6
,
(
-
1
,
999999
)),
(
1e-6
,
(
0
,
1
)),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
timeval
=
timeval
):
self
.
assertEqual
(
pytime_object_to_timeval
(
obj
,
rnd
),
timeval
)
# Conversion giving different results depending on the rounding method
FLOOR
=
_PyTime
.
ROUND_FLOOR
CEILING
=
_PyTime
.
ROUND_CEILING
HALF_UP
=
_PyTime
.
ROUND_HALF_UP
for
obj
,
timeval
,
rnd
in
(
(
-
1e-7
,
(
-
1
,
999999
),
FLOOR
),
(
-
1e-7
,
(
0
,
0
),
CEILING
),
(
-
1e-7
,
(
0
,
0
),
HALF_UP
),
(
1e-7
,
(
0
,
0
),
FLOOR
),
(
1e-7
,
(
0
,
1
),
CEILING
),
(
1e-7
,
(
0
,
0
),
HALF_UP
),
(
0.4e-6
,
(
0
,
0
),
HALF_UP
),
(
0.5e-6
,
(
0
,
1
),
HALF_UP
),
(
0.6e-6
,
(
0
,
1
),
HALF_UP
),
(
0.9999999
,
(
0
,
999999
),
FLOOR
),
(
0.9999999
,
(
1
,
0
),
CEILING
),
(
0.9999999
,
(
1
,
0
),
HALF_UP
),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
timeval
=
timeval
):
self
.
assertEqual
(
pytime_object_to_timeval
(
obj
,
rnd
),
timeval
)
rnd
=
_PyTime
.
ROUND_FLOOR
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
pytime_object_to_timeval
,
invalid
,
rnd
)
@support.cpython_only
def
test_timespec
(
self
):
from
_testcapi
import
pytime_object_to_timespec
# Conversion giving the same result for all rounding methods
for
rnd
in
ALL_ROUNDING_METHODS
:
for
obj
,
timespec
in
(
# int
(
0
,
(
0
,
0
)),
(
-
1
,
(
-
1
,
0
)),
# float
(
-
1.0
,
(
-
1
,
0
)),
(
-
1e-9
,
(
-
1
,
999999999
)),
(
1e-9
,
(
0
,
1
)),
(
-
1.2
,
(
-
2
,
800000000
)),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
timespec
=
timespec
):
self
.
assertEqual
(
pytime_object_to_timespec
(
obj
,
rnd
),
timespec
)
# Conversion giving different results depending on the rounding method
FLOOR
=
_PyTime
.
ROUND_FLOOR
CEILING
=
_PyTime
.
ROUND_CEILING
HALF_UP
=
_PyTime
.
ROUND_HALF_UP
for
obj
,
timespec
,
rnd
in
(
(
-
1e-10
,
(
-
1
,
999999999
),
FLOOR
),
(
-
1e-10
,
(
0
,
0
),
CEILING
),
(
-
1e-10
,
(
0
,
0
),
HALF_UP
),
(
1e-10
,
(
0
,
0
),
FLOOR
),
(
1e-10
,
(
0
,
1
),
CEILING
),
(
1e-10
,
(
0
,
0
),
HALF_UP
),
(
0.4e-9
,
(
0
,
0
),
HALF_UP
),
(
0.5e-9
,
(
0
,
1
),
HALF_UP
),
(
0.6e-9
,
(
0
,
1
),
HALF_UP
),
(
0.9999999999
,
(
0
,
999999999
),
FLOOR
),
(
0.9999999999
,
(
1
,
0
),
CEILING
),
(
0.9999999999
,
(
1
,
0
),
HALF_UP
),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
timespec
=
timespec
):
self
.
assertEqual
(
pytime_object_to_timespec
(
obj
,
rnd
),
timespec
)
# Test OverflowError
rnd
=
FLOOR
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
pytime_object_to_timespec
,
invalid
,
rnd
)
if
__name__
==
"__main__"
:
unittest
.
main
()
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