23
23
import sqlite3
24
24
import csv
25
25
import os
26
- import sys
27
26
28
27
import warnings
29
28
import numpy as np
36
35
from pandas import DataFrame , Series , Index , MultiIndex , isnull , concat
37
36
from pandas import date_range , to_datetime , to_timedelta , Timestamp
38
37
import 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
40
39
from pandas .tseries .tools import format as date_format
41
40
42
41
import pandas .io .sql as sql
@@ -2220,6 +2219,7 @@ def test_schema(self):
2220
2219
cur = self .conn .cursor ()
2221
2220
cur .execute (create_sql )
2222
2221
2222
+ @tm .capture_stdout
2223
2223
def test_execute_fail (self ):
2224
2224
create_sql = """
2225
2225
CREATE TABLE test
@@ -2236,14 +2236,11 @@ def test_execute_fail(self):
2236
2236
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2237
2237
sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
2238
2238
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 )
2246
2242
2243
+ @tm .capture_stdout
2247
2244
def test_execute_closed_connection (self ):
2248
2245
create_sql = """
2249
2246
CREATE TABLE test
@@ -2259,12 +2256,10 @@ def test_execute_closed_connection(self):
2259
2256
2260
2257
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2261
2258
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 )
2268
2263
2269
2264
# Initialize connection again (needed for tearDown)
2270
2265
self .setUp ()
@@ -2534,6 +2529,7 @@ def test_schema(self):
2534
2529
cur .execute (drop_sql )
2535
2530
cur .execute (create_sql )
2536
2531
2532
+ @tm .capture_stdout
2537
2533
def test_execute_fail (self ):
2538
2534
_skip_if_no_pymysql ()
2539
2535
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2553,14 +2549,11 @@ def test_execute_fail(self):
2553
2549
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2554
2550
sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
2555
2551
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 )
2563
2555
2556
+ @tm .capture_stdout
2564
2557
def test_execute_closed_connection (self ):
2565
2558
_skip_if_no_pymysql ()
2566
2559
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2579,12 +2572,10 @@ def test_execute_closed_connection(self):
2579
2572
2580
2573
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2581
2574
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 )
2588
2579
2589
2580
# Initialize connection again (needed for tearDown)
2590
2581
self .setUp ()
0 commit comments