assertRaises() help

Steven D'Aprano steve at pearwood.info
Wed May 27 21:38:05 EDT 2015


On Thu, 28 May 2015 08:09 am, Vincent Davis wrote:

> I am trying to add a test to pandas Int the first case I assert that I get
> a NaT value, in the second I what to test that I get a value error.

Your sentence has just enough typos to lead me to doubt I understand you.
What do you mean, add a test "to pandas Int the first case..." ?

What's a NaT value?


> def
> test_day_not_in_month_coerce_true
> () works

If it works, why is it relevant to your question?


> I am trying to duplicate them with coerce=
> False which
> will give a ValueError but I cant get the tests to work.
[...]

>     def test_day_not_in_month_coerce_false(self):
>         self.assertRaises(ValueError, to_datetime, '2015-02-29',
> coerce=False)


What leads you to believe that to_datetime('2015-02-29', coerce=False) will
raise ValueError?


> what I get is
> 
> FAIL: test_day_not_in_month_coerce_false
> (pandas.tests.test_tseries.TestDaysInMonth)

This failure clearly shows that to_datetime(...) does not raise ValueError.

I don't see anything obviously wrong in your use of the assertRaises method,
*assuming* that it is the assertRaises method from the standard library
unittest module. If it is some custom method written by you, or part of
pandas, then I have no idea if you are doing something wrong.

But I expect that the real problem is that you are mistaken to believe that
to_datetime('2015-02-29', coerce=False) raises ValueError.




-- 
Steven




More information about the Python-list mailing list