Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
code_block_timer
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
code_block_timer
Commits
9c7801cc
Commit
9c7801cc
authored
Feb 12, 2015
by
John Eskew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support specified delimiters between timing levels.
parent
efd19daa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
code_block_timer/__init__.py
+3
-2
code_block_timer/tests/test_timer.py
+30
-2
requirements.txt
+3
-0
No files found.
code_block_timer/__init__.py
View file @
9c7801cc
...
...
@@ -40,7 +40,8 @@ class CodeBlockTimer(object):
self
.
block_desc
=
block_desc
self
.
verbose
=
False
if
'verbose'
not
in
kwargs
else
kwargs
[
'verbose'
]
self
.
timer
=
default_timer
self
.
data_store
=
storage
.
TimingDataStorage
(
**
kwargs
)
self
.
delimiter
=
kwargs
.
pop
(
'delimiter'
,
':'
)
self
.
data_store
=
TimingDataStorage
(
**
kwargs
)
def
__enter__
(
self
):
if
len
(
_m
.
nest_stack
)
==
0
:
...
...
@@ -56,7 +57,7 @@ class CodeBlockTimer(object):
self
.
elapsed
=
self
.
elapsed_secs
*
1000
# millisecs
# Store the timings.
nested_desc
=
":"
.
join
(
_m
.
nest_stack
)
nested_desc
=
self
.
delimiter
.
join
(
_m
.
nest_stack
)
self
.
data_store
.
store
(
_m
.
run_id
,
nested_desc
,
self
.
elapsed
)
# Pop the stack.
...
...
code_block_timer/tests/test_timer.py
View file @
9c7801cc
...
...
@@ -3,10 +3,13 @@ import mock
import
os
import
unittest
import
random
import
math
import
sqlite3
from
code_block_timer
import
CodeBlockTimer
,
code_block_timer
,
_m
import
ddt
@ddt.ddt
class
TestCodeBlockTimer
(
unittest
.
TestCase
):
"""
Tests for CodeBlockTimer.
...
...
@@ -29,10 +32,9 @@ class TestCodeBlockTimer(unittest.TestCase):
iterations
=
[
'iter0'
,
'iter1'
,
'iter2'
,
'iter3'
]
with
CodeBlockTimer
(
"test"
,
db_name
=
self
.
db_name
)
as
timer
:
run_id
=
_m
.
run_id
z
=
0
for
i
,
iter_name
in
enumerate
(
iterations
):
with
CodeBlockTimer
(
iter_name
,
db_name
=
self
.
db_name
)
as
inner
:
z
+=
i
z
=
math
.
factorial
(
10
)
self
.
_verifyEvents
(
run_id
,
[
'test'
,
]
+
[
"test:{}"
.
format
(
x
)
for
x
in
iterations
])
@mock.patch
(
'code_block_timer.storage.TimingDataStorage'
)
...
...
@@ -54,6 +56,32 @@ class TestCodeBlockTimer(unittest.TestCase):
self
.
assertTrue
(
test_dict
[
'entered'
])
store
.
store
.
assert_called_with
(
45
,
'decorator_test'
,
mock
.
ANY
)
def
test_exception_handled
(
self
):
msg
=
"exception_but_still_timed"
try
:
with
CodeBlockTimer
(
msg
,
db_name
=
self
.
db_name
)
as
__
:
run_id
=
_m
.
run_id
z
=
math
.
factorial
(
10
)
raise
Exception
except
Exception
:
pass
self
.
_verifyEvents
(
run_id
,
[
msg
])
def
test_default_delimiter
(
self
):
with
CodeBlockTimer
(
"test"
,
db_name
=
self
.
db_name
)
as
timer
:
run_id
=
_m
.
run_id
with
CodeBlockTimer
(
"delimiter"
,
db_name
=
self
.
db_name
)
as
inner
:
z
=
math
.
factorial
(
10
)
self
.
_verifyEvents
(
run_id
,
[
'test'
,
'test:delimiter'
])
@ddt.data
(
':::::'
,
'
%
'
,
'-'
,
'/'
)
def
test_delimiters
(
self
,
delimiter
):
with
CodeBlockTimer
(
"test"
,
delimiter
=
delimiter
,
db_name
=
self
.
db_name
)
as
timer
:
run_id
=
_m
.
run_id
with
CodeBlockTimer
(
"delimiter"
,
delimiter
=
delimiter
,
db_name
=
self
.
db_name
)
as
inner
:
z
=
math
.
factorial
(
10
)
self
.
_verifyEvents
(
run_id
,
[
'test'
,
'test{}delimiter'
.
format
(
delimiter
)])
def
tearDown
(
self
):
try
:
# Destroy the sqlite DB.
...
...
requirements.txt
0 → 100644
View file @
9c7801cc
ddt
==1.0.0
path.py
==7.2
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