How to capture a Fail() condition in Python test #2438
Replies: 1 comment 2 replies
-
You can in c++ with Google test.
Le lun. 15 mars 2021 à 23:59, James Marca ***@***.***> a
écrit :
… I'm trying to write a test that fails, but it seems the usual way of
calling assertRaises(...) isn't working for me
First, I can't see what exception is being thrown from logging.h,
logging.cc.
Second, even wrapping the entire crashing call in a try block still
doesn't catch the error.
In the source in
https://github.com/google/or-tools/blob/193101786ecb527fb76a957ce5f2efe4016836c5/ortools/constraint_solver/routing.cc#L6835-L6844,
I added
CHECK_EQ(node_visit_transits.size(), model_->Size());
What I want to do is check that this fails when called from Python, so I
tried various iterations of this:
try:
dim.SetBreakIntervalsOfVehicle(break_intervals[0], 0, [1])
self.fail("shouldn't happen")
except:
pass
Rather than catching the error, the code invoked by CHECK_EQ seems to be
able to completely kill off the python caller.
test_set_break_intervals (__main__.TestRoutingModel) ... WARNING: Logging before InitGoogleLogging() is written to STDERR
F0320 23:28:15.916748 28053 routing.cc:6839] Check failed: node_visit_transits.size() == model_->Size() (1 vs. 7)
*** Check failure stack trace: ***
Aborted
How should one go about testing that bad input causes the solver to fail?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2438>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3IZHRL3ZMMH2EXRTJTTD2GNDANCNFSM4ZHNCDDQ>
.
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to write a test that fails, but it seems the usual way of calling assertRaises(...) isn't working for me
First, I can't see what exception is being thrown from logging.h, logging.cc.
Second, even wrapping the entire crashing call in a try block still doesn't catch the error.
In the source in
or-tools/ortools/constraint_solver/routing.cc
Lines 6835 to 6844 in 1931017
CHECK_EQ(node_visit_transits.size(), model_->Size());
What I want to do is check that this fails when called from Python, so I tried various iterations of this:
Rather than catching the error, the code invoked by CHECK_EQ seems to be able to completely kill off the python caller.
How should one go about testing that bad input causes the solver to fail?
Beta Was this translation helpful? Give feedback.
All reactions