Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91328
| From | Vincent Davis <vincent@vincentdavis.net> |
|---|---|
| Date | 2015-05-27 16:09 -0600 |
| Subject | assertRaises() help |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.103.1432764591.5151.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/vmd/GitHub/pandas_vmd/pandas/tests/test_tseries.py", line
747, in test_day_not_in_month_coerce_false
self.assertRaises(ValueError, to_datetime, '2015-02-29', coerce=False)
File "/Users/vmd/GitHub/pandas_vmd/pandas/util/testing.py", line 1576, in
assertRaises
_callable(*args, **kwargs)
File "/Users/vmd/GitHub/pandas_vmd/pandas/util/testing.py", line 1640, in
__exit__
raise AssertionError("{0} not raised.".format(name))
AssertionError: ValueError not raised.
>From the docs maybe I should be using a "with" statement​.
Vincent Davis
720-301-3003
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
assertRaises() help Vincent Davis <vincent@vincentdavis.net> - 2015-05-27 16:09 -0600 Re: assertRaises() help Steven D'Aprano <steve@pearwood.info> - 2015-05-28 11:38 +1000
csiph-web