11from __future__ import division
22
3- import pytest
43from pandas import Interval
4+
55import pandas .util .testing as tm
66
77
88class TestInterval (object ):
9- def setup_method (self , method ):
9+ def setup_method (self , _ ):
1010 self .interval = Interval (0 , 1 )
1111
1212 def test_properties (self ):
@@ -27,7 +27,10 @@ def test_contains(self):
2727 assert 0.5 in self .interval
2828 assert 1 in self .interval
2929 assert 0 not in self .interval
30- pytest .raises (TypeError , lambda : self .interval in self .interval )
30+
31+ msg = "__contains__ not defined for two intervals"
32+ with tm .assert_raises_regex (TypeError , msg ):
33+ self .interval in self .interval
3134
3235 interval = Interval (0 , 1 , closed = 'both' )
3336 assert 0 in interval
@@ -71,10 +74,11 @@ def test_math_add(self):
7174 actual += 1
7275 assert expected == actual
7376
74- with pytest .raises (TypeError ):
77+ msg = "unsupported operand type\(s\) for \+"
78+ with tm .assert_raises_regex (TypeError , msg ):
7579 self .interval + Interval (1 , 2 )
7680
77- with pytest . raises (TypeError ):
81+ with tm . assert_raises_regex (TypeError , msg ):
7882 self .interval + 'foo'
7983
8084 def test_math_sub (self ):
@@ -86,10 +90,11 @@ def test_math_sub(self):
8690 actual -= 1
8791 assert expected == actual
8892
89- with pytest .raises (TypeError ):
93+ msg = "unsupported operand type\(s\) for -"
94+ with tm .assert_raises_regex (TypeError , msg ):
9095 self .interval - Interval (1 , 2 )
9196
92- with pytest . raises (TypeError ):
97+ with tm . assert_raises_regex (TypeError , msg ):
9398 self .interval - 'foo'
9499
95100 def test_math_mult (self ):
@@ -105,10 +110,12 @@ def test_math_mult(self):
105110 actual *= 2
106111 assert expected == actual
107112
108- with pytest .raises (TypeError ):
113+ msg = "unsupported operand type\(s\) for \*"
114+ with tm .assert_raises_regex (TypeError , msg ):
109115 self .interval * Interval (1 , 2 )
110116
111- with pytest .raises (TypeError ):
117+ msg = "can\' t multiply sequence by non-int"
118+ with tm .assert_raises_regex (TypeError , msg ):
112119 self .interval * 'foo'
113120
114121 def test_math_div (self ):
@@ -120,8 +127,9 @@ def test_math_div(self):
120127 actual /= 2.0
121128 assert expected == actual
122129
123- with pytest .raises (TypeError ):
130+ msg = "unsupported operand type\(s\) for /"
131+ with tm .assert_raises_regex (TypeError , msg ):
124132 self .interval / Interval (1 , 2 )
125133
126- with pytest . raises (TypeError ):
134+ with tm . assert_raises_regex (TypeError , msg ):
127135 self .interval / 'foo'
0 commit comments