Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91335 > unrolled thread

Re: assertRaises() help

Started byCameron Simpson <cs@zip.com.au>
First post2015-05-28 08:55 +1000
Last post2015-05-28 08:55 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: assertRaises() help Cameron Simpson <cs@zip.com.au> - 2015-05-28 08:55 +1000

#91335 — Re: assertRaises() help

FromCameron Simpson <cs@zip.com.au>
Date2015-05-28 08:55 +1000
SubjectRe: assertRaises() help
Message-ID<mailman.109.1432768581.5151.python-list@python.org>
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?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web