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


Groups > comp.lang.python > #91328

assertRaises() help

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <vincent@vincentdavis.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'skip:" 60': 0.05; 'subject:help': 0.07; 'raised.': 0.09; 'valueerror': 0.09; 'def': 0.14; '"with"': 0.16; 'duplicate': 0.18; 'tests': 0.18; 'to:name:python-list@python.org': 0.20; 'trying': 0.22; 'skip:( 40': 0.23; '(most': 0.24; 'raise': 0.24; 'second': 0.24; 'skip:t 40': 0.27; 'message-id:@mail.gmail.com': 0.28; '**kwargs)': 0.29; 'skip:& 70': 0.29; "skip:' 10": 0.30; 'work.': 0.30; 'maybe': 0.31; 'error.': 0.31; 'skip:_ 10': 0.32; 'class': 0.33; 'int': 0.33; 'traceback': 0.33; 'skip:& 10': 0.34; 'file': 0.34; 'add': 0.34; 'received:google.com': 0.34; 'to:addr:python- list': 0.35; 'false': 0.35; 'skip:" 50': 0.35; 'skip:& 60': 0.35; 'but': 0.36; 'should': 0.37; 'skip:s 40': 0.38; 'test': 0.39; 'to:addr:python.org': 0.39; 'skip:t 20': 0.40
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=vincentdavis.net; s=google; h=mime-version:from:date:message-id:subject:to:content-type; bh=cR6iuEBk14rrxTGDLr+S87Zp84DtUH/Pzio0GKDcYBc=; b=F38CsfcGhnEa2MlaGAc0Oir0078Zp0iD7D2HQ0b+6aInBkejuLsG9gYqq3QiUc4P4f MLQHj3dUzQPWej0cxE5Aiq1ppD9c9xjCoJQqpyzoRznBicZ4Rj3+FuCbQq6TU+gogGO7 SyNxSnyFffrA6FdOUSD2smQrvJHcuU4WJxTdk=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=cR6iuEBk14rrxTGDLr+S87Zp84DtUH/Pzio0GKDcYBc=; b=QEeIpEMz1SLDy4spedplJ1yX0PwyirO36G+IPNhn12dAE1gj+4S3+brZILWFH91cA8 /Kk+pwDppl0RCVGTHJPin0YRCnTssUNQN7PIq4UJTQ5tcHWMnH6HSkK03oEXyU69YohZ J0dmf3vmBxQCSYstvwax6bt+zprA7YV5drKm8Obghvwdog6TpUWPFNFqwTwsWMLK/K5e paUkwJLH8kxu5SXY1pIDSeLfesCkGwIaXAQ9HRbkUB0Pr/z0IyzfyoeXIm7hvaCLCnqL SpECec85w34QptmIjEhe2SLaVo6tTPxoDKsZgt2CihOYnP0oBjNtPRNoT4VjUTm+Dg+B yFUQ==
X-Gm-Message-State ALoCoQmPtZ+m/FP7Ob1w2BdDL7MTGBH55eghgSWz6ZF8NCVCQ3rRD7uYAvTaJx/8AeKmyjjb9p7C
X-Received by 10.202.212.68 with SMTP id l65mr20978163oig.89.1432764587813; Wed, 27 May 2015 15:09:47 -0700 (PDT)
MIME-Version 1.0
From Vincent Davis <vincent@vincentdavis.net>
Date Wed, 27 May 2015 16:09:27 -0600
Subject assertRaises() help
To "python-list@python.org" <python-list@python.org>
Content-Type multipart/alternative; boundary=001a113cab984dc72005171780b6
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.103.1432764591.5151.python-list@python.org> (permalink)
Lines 90
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432764591 news.xs4all.nl 2962 [2001:888:2000:d::a6]:40654
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91328

Show key headers only | View raw


[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 | NextNext in thread | Find similar | Unroll thread


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