Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
01b7eab8
Commit
01b7eab8
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
yo typecheck
parent
88c2f01c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/coding/debug.md
+23
-0
23 additions, 0 deletions
docs/coding/debug.md
tests/test_coding/test_debug.py
+29
-0
29 additions, 0 deletions
tests/test_coding/test_debug.py
tests/test_instrumentation/test_trace_back.py
+15
-2
15 additions, 2 deletions
tests/test_instrumentation/test_trace_back.py
with
67 additions
and
2 deletions
docs/coding/debug.md
0 → 100644
+
23
−
0
View file @
01b7eab8
# debug module
debug module is used during development. If Python's
\_\_
debug__ variable is set,
debug functions become operational.
If it's not (Python was launched with -O), they will do their best not to affect
performance, including removing themselves from code.
## Type checking
```
python
from
satella.coding.debug
import
typed
@typed
(
int
,
int
)
def
add_two_numbers
(
a
,
b
):
return
a
+
b
```
If you want to check for None-ness, you can pass None as well. Types for particular
arguments can also be tuples or lists, in that case if any of these types matches,
it's OK.
If type check fails, TypeError will be raised.
This diff is collapsed.
Click to expand it.
tests/test_coding/test_debug.py
0 → 100644
+
29
−
0
View file @
01b7eab8
# coding=UTF-8
"""
It sounds like a melody
"""
from
__future__
import
print_function
,
absolute_import
,
division
import
six
import
unittest
from
satella.coding.debug
import
typed
class
TestTypecheck
(
unittest
.
TestCase
):
def
test_t1
(
self
):
@typed
(
int
,
float
,
six
.
text_type
)
def
testf
(
a_int
,
a_float
,
a_string
):
pass
self
.
assertRaises
(
TypeError
,
lambda
:
testf
(
'
lol
'
,
15
,
'
test
'
))
self
.
assertRaises
(
TypeError
,
lambda
:
testf
(
12
,
2.0
,
'
hey
'
))
testf
(
12
,
2.0
,
u
'
hey
'
)
@typed
((
None
,
int
,
float
))
def
testa
(
param
):
pass
self
.
assertRaises
(
TypeError
,
lambda
:
testa
(
'
hey
'
))
testa
(
2
)
testa
(
2
)
testa
(
2.0
)
This diff is collapsed.
Click to expand it.
tests/test_instrumentation/test_trace_back.py
+
15
−
2
View file @
01b7eab8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
__future__
import
print_function
,
absolute_import
,
division
from
__future__
import
print_function
,
absolute_import
,
division
import
six
import
six
import
pickle
import
unittest
import
unittest
from
satella.instrumentation
import
Traceback
from
satella.instrumentation
import
Traceback
...
@@ -10,10 +11,22 @@ class TestTraceback(unittest.TestCase):
...
@@ -10,10 +11,22 @@ class TestTraceback(unittest.TestCase):
def
test_tb
(
self
):
def
test_tb
(
self
):
try
:
try
:
loc
=
'
hello world
'
raise
ValueError
(
'
hello
'
)
raise
ValueError
(
'
hello
'
)
except
:
except
ValueError
:
tb
=
Traceback
()
tb
=
Traceback
()
p_fmt
=
tb
.
pretty_format
()
p_fmt
=
tb
.
pretty_format
()
self
.
assertTrue
(
p_fmt
)
self
.
assertTrue
(
p_fmt
)
\ No newline at end of file
print
(
p_fmt
)
def
test_compression_happens
(
self
):
try
:
loc
=
'
'
*
(
10
*
1024
*
1024
)
raise
ValueError
(
'
hello
'
)
except
ValueError
:
tb
=
Traceback
()
self
.
assertLess
(
len
(
pickle
.
dumps
(
tb
,
-
1
)),
9
*
1024
*
1024
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment