Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
79173d49
Commit
79173d49
authored
8 years ago
by
Gerardo Tauriello
Browse files
Options
Downloads
Patches
Plain Diff
Fixed broken string conversion in Python-exported OST logging.
parent
b98ccb08
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/base/pymod/export_logger.cc
+12
-11
12 additions, 11 deletions
modules/base/pymod/export_logger.cc
modules/base/tests/test_log.py
+27
-10
27 additions, 10 deletions
modules/base/tests/test_log.py
with
39 additions
and
21 deletions
modules/base/pymod/export_logger.cc
+
12
−
11
View file @
79173d49
...
...
@@ -54,10 +54,10 @@ typedef boost::shared_ptr<WrappedLogSink> WrappedLogSinkPtr;
void
push_verb
(
int
n
)
{
if
(
n
<
0
){
Logger
::
Instance
().
PushVerbosityLevel
(
0
);
}
else
{
Logger
::
Instance
().
PushVerbosityLevel
(
n
);
if
(
n
<
0
)
{
Logger
::
Instance
().
PushVerbosityLevel
(
0
);
}
else
{
Logger
::
Instance
().
PushVerbosityLevel
(
n
);
}
}
...
...
@@ -90,17 +90,18 @@ LogSinkPtr get_log_sink()
String
args_to_string
(
tuple
args
,
dict
kwargs
)
{
std
::
stringstream
ss
;
bool
empty
=
true
;
for
(
size_t
i
=
0
,
l
=
len
(
args
);
i
<
l
;
++
i
)
{
bool
empty
=
true
;
for
(
size_t
i
=
0
,
l
=
len
(
args
);
i
<
l
;
++
i
)
{
if
(
!
empty
)
{
ss
<<
" "
;
}
empty
=
false
;
empty
=
false
;
String
string_val
;
try
{
string_val
=
extract
<
String
>
(
args
[
i
]);
}
catch
(...)
{
string_val
=
extract
<
String
>
(
args
[
i
].
attr
(
"__str__"
)());
extract
<
String
>
tst
(
args
[
i
]);
if
(
tst
.
check
())
{
string_val
=
tst
();
}
else
{
string_val
=
extract
<
String
>
(
str
(
args
[
i
]));
// use boost python str
}
ss
<<
string_val
;
}
...
...
This diff is collapsed.
Click to expand it.
modules/base/tests/test_log.py
+
27
−
10
View file @
79173d49
import
unittest
import
ost
# helper log sink to campture messages
class
_CapturingLogSink
(
ost
.
LogSink
):
def
__init__
(
self
):
ost
.
LogSink
.
__init__
(
self
)
def
LogMessage
(
self
,
message
,
severity
):
self
.
message
=
message
self
.
severity
=
severity
# Altough the logging system might appear to be too simple to be worth writing a
# specific test case for, it actually isn't. The python export is very fragile
# and seemingly trivial changes can break the code in unexpected ways. So let's
# check for some invariants
class
TestLog
(
unittest
.
TestCase
):
def
testGetLogSink
(
self
):
logsink
=
ost
.
GetCurrentLogSink
()
logsink
=
ost
.
GetCurrentLogSink
()
self
.
assertTrue
(
hasattr
(
logsink
,
'
LogMessage
'
))
# Check if the return type of logsink is sane
ost
.
PushLogSink
(
ost
.
GetCurrentLogSink
())
def
testPushPopLogSink
(
self
):
class
MyLogSink
(
ost
.
LogSink
):
def
__init__
(
self
):
ost
.
LogSink
.
__init__
(
self
)
ls
=
MyLogSink
()
ls
=
MyLogSink
()
ost
.
PushLogSink
(
ls
)
self
.
assertEqual
(
ls
,
ost
.
GetCurrentLogSink
())
ost
.
PopLogSink
()
self
.
assertNotEqual
(
ls
,
ost
.
GetCurrentLogSink
())
def
testLogMessage
(
self
):
class
CapturingLogSink
(
ost
.
LogSink
):
def
__init__
(
self
):
ost
.
LogSink
.
__init__
(
self
)
def
LogMessage
(
self
,
message
,
severity
):
self
.
message
=
message
self
.
severity
=
severity
ost
.
PushLogSink
(
ls
)
ls
=
CapturingLogSink
()
ls
=
_CapturingLogSink
()
ost
.
PushVerbosityLevel
(
1
)
ost
.
PushLogSink
(
ls
)
ost
.
LogError
(
'
error message
'
)
...
...
@@ -39,6 +42,20 @@ class TestLog(unittest.TestCase):
self
.
assertEqual
(
ls
.
message
,
'
1 2 3
\n
'
)
self
.
assertEqual
(
ls
.
severity
,
1
)
ost
.
PopLogSink
()
def
testLogMultipleMessages
(
self
):
# observation: converting non-strings in logging can break following calls
ls
=
_CapturingLogSink
()
ost
.
PushVerbosityLevel
(
1
)
ost
.
PushLogSink
(
ls
)
ost
.
LogWarning
(
'
foo
'
)
self
.
assertEqual
(
ls
.
message
,
'
foo
\n
'
)
ost
.
LogWarning
(
1
)
self
.
assertEqual
(
ls
.
message
,
'
1
\n
'
)
ost
.
LogWarning
(
'
bar
'
)
self
.
assertEqual
(
ls
.
message
,
'
bar
\n
'
)
ost
.
PopLogSink
()
if
__name__
==
"
__main__
"
:
from
ost
import
testutils
testutils
.
RunTests
()
\ No newline at end of file
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