2323import sqlite3
2424import csv
2525import os
26- import sys
2726
2827import warnings
2928import numpy as np
3635from pandas import DataFrame , Series , Index , MultiIndex , isnull , concat
3736from pandas import date_range , to_datetime , to_timedelta , Timestamp
3837import pandas .compat as compat
39- from pandas .compat import StringIO , range , lrange , string_types , PY36
38+ from pandas .compat import range , lrange , string_types , PY36
4039from pandas .tseries .tools import format as date_format
4140
4241import pandas .io .sql as sql
@@ -2220,6 +2219,7 @@ def test_schema(self):
22202219 cur = self .conn .cursor ()
22212220 cur .execute (create_sql )
22222221
2222+ @tm .capture_stdout
22232223 def test_execute_fail (self ):
22242224 create_sql = """
22252225 CREATE TABLE test
@@ -2236,14 +2236,11 @@ def test_execute_fail(self):
22362236 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
22372237 sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
22382238
2239- try :
2240- sys .stdout = StringIO ()
2241- self .assertRaises (Exception , sql .execute ,
2242- 'INSERT INTO test VALUES("foo", "bar", 7)' ,
2243- self .conn )
2244- finally :
2245- sys .stdout = sys .__stdout__
2239+ self .assertRaises (Exception , sql .execute ,
2240+ 'INSERT INTO test VALUES("foo", "bar", 7)' ,
2241+ self .conn )
22462242
2243+ @tm .capture_stdout
22472244 def test_execute_closed_connection (self ):
22482245 create_sql = """
22492246 CREATE TABLE test
@@ -2259,12 +2256,10 @@ def test_execute_closed_connection(self):
22592256
22602257 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
22612258 self .conn .close ()
2262- try :
2263- sys .stdout = StringIO ()
2264- self .assertRaises (Exception , tquery , "select * from test" ,
2265- con = self .conn )
2266- finally :
2267- sys .stdout = sys .__stdout__
2259+
2260+ self .assertRaises (Exception , tquery ,
2261+ "select * from test" ,
2262+ con = self .conn )
22682263
22692264 # Initialize connection again (needed for tearDown)
22702265 self .setUp ()
@@ -2534,6 +2529,7 @@ def test_schema(self):
25342529 cur .execute (drop_sql )
25352530 cur .execute (create_sql )
25362531
2532+ @tm .capture_stdout
25372533 def test_execute_fail (self ):
25382534 _skip_if_no_pymysql ()
25392535 drop_sql = "DROP TABLE IF EXISTS test"
@@ -2553,14 +2549,11 @@ def test_execute_fail(self):
25532549 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
25542550 sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
25552551
2556- try :
2557- sys .stdout = StringIO ()
2558- self .assertRaises (Exception , sql .execute ,
2559- 'INSERT INTO test VALUES("foo", "bar", 7)' ,
2560- self .conn )
2561- finally :
2562- sys .stdout = sys .__stdout__
2552+ self .assertRaises (Exception , sql .execute ,
2553+ 'INSERT INTO test VALUES("foo", "bar", 7)' ,
2554+ self .conn )
25632555
2556+ @tm .capture_stdout
25642557 def test_execute_closed_connection (self ):
25652558 _skip_if_no_pymysql ()
25662559 drop_sql = "DROP TABLE IF EXISTS test"
@@ -2579,12 +2572,10 @@ def test_execute_closed_connection(self):
25792572
25802573 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
25812574 self .conn .close ()
2582- try :
2583- sys .stdout = StringIO ()
2584- self .assertRaises (Exception , tquery , "select * from test" ,
2585- con = self .conn )
2586- finally :
2587- sys .stdout = sys .__stdout__
2575+
2576+ self .assertRaises (Exception , tquery ,
2577+ "select * from test" ,
2578+ con = self .conn )
25882579
25892580 # Initialize connection again (needed for tearDown)
25902581 self .setUp ()
0 commit comments