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
5ceef131
Commit
5ceef131
authored
Apr 02, 2012
by
Brett Cannon
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
927d8747
30d79471
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
76 deletions
+65
-76
Doc/library/time.rst
Doc/library/time.rst
+16
-0
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+0
-70
Lib/test/test_thread.py
Lib/test/test_thread.py
+0
-1
Lib/test/test_time.py
Lib/test/test_time.py
+11
-0
Modules/_decimal/_decimal.c
Modules/_decimal/_decimal.c
+5
-5
Modules/timemodule.c
Modules/timemodule.c
+33
-0
No files found.
Doc/library/time.rst
View file @
5ceef131
...
...
@@ -151,6 +151,13 @@ The module defines the following functions and data items:
.. versionadded:: 3.3
.. function:: clock_settime(clk_id, time)
Set the time of the specified clock *clk_id*.
.. versionadded:: 3.3
.. data:: CLOCK_REALTIME
System-wide real-time clock. Setting this clock requires appropriate
...
...
@@ -159,6 +166,15 @@ The module defines the following functions and data items:
.. versionadded:: 3.3
.. data:: CLOCK_HIGHRES
The Solaris OS has a CLOCK_HIGHRES timer that attempts to use an optimal
hardware source, and may give close to nanosecond resolution. CLOCK_HIGHRES
is the nonadjustable, high-resolution clock.
.. versionadded:: 3.3
.. data:: CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some
...
...
Lib/test/test_decimal.py
View file @
5ceef131
...
...
@@ -56,76 +56,6 @@ sys.modules['decimal'] = C
fractions
=
{
C
:
cfractions
,
P
:
pfractions
}
sys
.
modules
[
'decimal'
]
=
orig_sys_decimal
############ RunFirst ############
class
RunFirst
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
save_default
=
self
.
decimal
.
DefaultContext
.
copy
()
def
tearDown
(
self
):
DefaultContext
=
self
.
decimal
.
DefaultContext
DefaultContext
.
prec
=
self
.
save_default
.
prec
DefaultContext
.
rounding
=
self
.
save_default
.
rounding
DefaultContext
.
Emax
=
self
.
save_default
.
Emax
DefaultContext
.
Emin
=
self
.
save_default
.
Emin
DefaultContext
.
capitals
=
self
.
save_default
.
capitals
DefaultContext
.
clamp
=
self
.
save_default
.
clamp
DefaultContext
.
flags
=
self
.
save_default
.
flags
DefaultContext
.
traps
=
self
.
save_default
.
traps
self
.
decimal
.
setcontext
(
self
.
decimal
.
DefaultContext
)
def
test_00default_context
(
self
):
# The test depends on the fact that getcontext() is called
# for the first time.
DefaultContext
=
self
.
decimal
.
DefaultContext
ROUND_05UP
=
self
.
decimal
.
ROUND_05UP
Clamped
=
self
.
decimal
.
Clamped
InvalidOperation
=
self
.
decimal
.
InvalidOperation
DefaultContext
.
prec
=
5001
DefaultContext
.
rounding
=
ROUND_05UP
DefaultContext
.
Emax
=
10025
DefaultContext
.
Emin
=
-
10025
DefaultContext
.
capitals
=
0
DefaultContext
.
clamp
=
1
DefaultContext
.
flags
[
InvalidOperation
]
=
True
DefaultContext
.
clear_traps
()
DefaultContext
.
traps
[
Clamped
]
=
True
# implicit initialization on first access
c
=
self
.
decimal
.
getcontext
()
self
.
assertEqual
(
c
.
prec
,
5001
)
self
.
assertEqual
(
c
.
rounding
,
ROUND_05UP
)
self
.
assertEqual
(
c
.
Emax
,
10025
)
self
.
assertEqual
(
c
.
Emin
,
-
10025
)
self
.
assertEqual
(
c
.
capitals
,
0
)
self
.
assertEqual
(
c
.
clamp
,
1
)
for
k
in
c
.
flags
:
self
.
assertFalse
(
c
.
flags
[
k
])
for
k
in
c
.
traps
:
if
k
is
Clamped
:
self
.
assertTrue
(
c
.
traps
[
k
])
else
:
self
.
assertFalse
(
c
.
traps
[
k
])
# explicit initialization
self
.
decimal
.
setcontext
(
DefaultContext
)
c
=
self
.
decimal
.
getcontext
()
for
k
in
c
.
flags
:
self
.
assertFalse
(
c
.
flags
[
k
])
class
CRunFirst
(
RunFirst
):
decimal
=
C
class
PyRunFirst
(
RunFirst
):
decimal
=
P
if
C
:
run_unittest
(
CRunFirst
,
PyRunFirst
)
else
:
run_unittest
(
PyRunFirst
)
############ END RunFirst ############
# Useful Test Constant
Signals
=
{
...
...
Lib/test/test_thread.py
View file @
5ceef131
...
...
@@ -132,7 +132,6 @@ class ThreadRunningTests(BasicThreadTest):
# See issue #14474
def
task
():
started
.
release
()
sys
.
stderr
=
stderr
raise
SyntaxError
def
mywrite
(
self
,
*
args
):
try
:
...
...
Lib/test/test_time.py
View file @
5ceef131
...
...
@@ -47,6 +47,17 @@ class TimeTestCase(unittest.TestCase):
self
.
assertGreater
(
res
,
0.0
)
self
.
assertLessEqual
(
res
,
1.0
)
@
unittest
.
skipUnless
(
hasattr
(
time
,
'clock_settime'
),
'need time.clock_settime()'
)
def
test_clock_settime
(
self
):
t
=
time
.
clock_gettime
(
time
.
CLOCK_REALTIME
)
try
:
time
.
clock_settime
(
time
.
CLOCK_REALTIME
,
t
)
except
PermissionError
:
pass
self
.
assertRaises
(
OSError
,
time
.
clock_settime
,
time
.
CLOCK_MONOTONIC
,
0
)
def
test_conversions
(
self
):
self
.
assertEqual
(
time
.
ctime
(
self
.
t
),
time
.
asctime
(
time
.
localtime
(
self
.
t
)))
...
...
Modules/_decimal/_decimal.c
View file @
5ceef131
...
...
@@ -1510,7 +1510,7 @@ current_context(void)
#define CURRENT_CONTEXT_ADDR(ctx) \
ctx = CTX(current_context())
/* Return
current context, increment reference
*/
/* Return
a new reference to the current context
*/
static
PyObject
*
PyDec_GetCurrentContext
(
void
)
{
...
...
@@ -1614,7 +1614,7 @@ current_context(void)
ctx = CTX(_c_t_x_o_b_j); \
}
/* Return
current context, increment reference
*/
/* Return
a new reference to the current context
*/
static
PyObject
*
PyDec_GetCurrentContext
(
void
)
{
...
...
@@ -1759,7 +1759,7 @@ static PyTypeObject PyDecContextManager_Type =
0
,
/* tp_print */
(
getattrfunc
)
0
,
/* tp_getattr */
(
setattrfunc
)
0
,
/* tp_setattr */
0
,
/* tp_
compare
*/
0
,
/* tp_
reserved
*/
(
reprfunc
)
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
...
...
@@ -2699,7 +2699,7 @@ ctx_create_decimal(PyObject *context, PyObject *args)
/******************************************************************************/
/* Implicit conversions to Decimal */
/* Implicit conversions to Decimal */
/******************************************************************************/
/* Try to convert PyObject v to a new PyDecObject conv. If the conversion
...
...
@@ -2796,7 +2796,7 @@ convert_op(int type_err, PyObject **conv, PyObject *v, PyObject *context)
/******************************************************************************/
/* Implicit conversions to Decimal for comparison */
/* Implicit conversions to Decimal for comparison */
/******************************************************************************/
/* Convert rationals for comparison */
...
...
Modules/timemodule.c
View file @
5ceef131
...
...
@@ -158,6 +158,33 @@ PyDoc_STRVAR(clock_gettime_doc,
"clock_gettime(clk_id) -> floating point number
\n
\
\n
\
Return the time of the specified clock clk_id."
);
static
PyObject
*
time_clock_settime
(
PyObject
*
self
,
PyObject
*
args
)
{
clockid_t
clk_id
;
PyObject
*
obj
;
struct
timespec
tp
;
int
ret
;
if
(
!
PyArg_ParseTuple
(
args
,
"iO:clock_settime"
,
&
clk_id
,
&
obj
))
return
NULL
;
if
(
_PyTime_ObjectToTimespec
(
obj
,
&
tp
.
tv_sec
,
&
tp
.
tv_nsec
)
==
-
1
)
return
NULL
;
ret
=
clock_settime
((
clockid_t
)
clk_id
,
&
tp
);
if
(
ret
!=
0
)
{
PyErr_SetFromErrno
(
PyExc_IOError
);
return
NULL
;
}
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
clock_settime_doc
,
"clock_settime(clk_id, time)
\n
\
\n
\
Set the time of the specified clock clk_id."
);
#endif
#ifdef HAVE_CLOCK_GETRES
...
...
@@ -962,6 +989,9 @@ PyInit_timezone(PyObject *m) {
#ifdef CLOCK_MONOTONIC_RAW
PyModule_AddIntMacro
(
m
,
CLOCK_MONOTONIC_RAW
);
#endif
#ifdef CLOCK_HIGHRES
PyModule_AddIntMacro
(
m
,
CLOCK_HIGHRES
);
#endif
#ifdef CLOCK_PROCESS_CPUTIME_ID
PyModule_AddIntMacro
(
m
,
CLOCK_PROCESS_CPUTIME_ID
);
#endif
...
...
@@ -980,6 +1010,9 @@ static PyMethodDef time_methods[] = {
#ifdef HAVE_CLOCK_GETTIME
{
"clock_gettime"
,
time_clock_gettime
,
METH_VARARGS
,
clock_gettime_doc
},
#endif
#ifdef HAVE_CLOCK_GETTIME
{
"clock_settime"
,
time_clock_settime
,
METH_VARARGS
,
clock_settime_doc
},
#endif
#ifdef HAVE_CLOCK_GETRES
{
"clock_getres"
,
time_clock_getres
,
METH_VARARGS
,
clock_getres_doc
},
#endif
...
...
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