Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91335
| Date | 2015-05-28 08:55 +1000 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: assertRaises() help |
| References | <CALyJZZV9DjUbyYRfGoaWzPG1FVnVx0+AsSOyud_ZOyE914A55Q@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.109.1432768581.5151.python-list@python.org> (permalink) |
On 27May2015 16:09, Vincent Davis <vincent@vincentdavis.net> 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.
>def
>test_day_not_in_month_coerce_true
>() works
>I am trying to duplicate them with coerce=
>False which
>will give a ValueError but I cant get the tests to work.
>
>
>class TestDaysInMonth(tm.TestCase):
> def test_day_not_in_month_coerce_true(self):
> self.assertTrue(isnull(to_datetime('2015-02-29', coerce=True)))
> self.assertTrue(isnull(to_datetime('2015-02-29', format="%Y-%m-%d",
>coerce=True)))
> self.assertTrue(isnull(to_datetime('2015-02-32', format="%Y-%m-%d",
>coerce=True)))
> self.assertTrue(isnull(to_datetime('2015-04-31', format="%Y-%m-%d",
>coerce=True)))
> def test_day_not_in_month_coerce_false(self):
> self.assertRaises(ValueError, to_datetime, '2015-02-29',
>coerce=False)
>
>what I get is
>
>FAIL: test_day_not_in_month_coerce_false
>(pandas.tests.test_tseries.TestDaysInMonth)
>----------------------------------------------------------------------
[...]
>AssertionError: ValueError not raised.
>
>From the docs maybe I should be using a "with" statement​.
Unlikely.
First, test your test by hand running:
to_datetime('2015-02-29', coerce=False)
_Does_ it raise ValueError?
Cheers,
Cameron Simpson <cs@zip.com.au>
Q: How many user support people does it take to change a light bulb?
A: We have an exact copy of the light bulb here and it seems to be
working fine. Can you tell me what kind of system you have?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: assertRaises() help Cameron Simpson <cs@zip.com.au> - 2015-05-28 08:55 +1000
csiph-web