Skip to content

TST: Do not skip MySQL tests on Travis. #4177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ install:
- echo "Waldo2"
- ci/install.sh

before_script:
- mysql -e 'create database pandas_nosetest;'

script:
- echo "Waldo3"
- ci/script.sh
Expand Down
1 change: 1 addition & 0 deletions ci/requirements-2.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ patsy==0.1.0
html5lib==1.0b2
lxml==3.2.1
scikits.timeseries==0.91.3
MySQL-python==1.2.4
49 changes: 36 additions & 13 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import with_statement
from pandas.util.py3compat import StringIO
import unittest
import sqlite3
import sys

import warnings

import nose

import numpy as np
Expand Down Expand Up @@ -160,7 +163,7 @@ def _check_roundtrip(self, frame):
sql.write_frame(frame, name='test_table', con=self.db)
result = sql.read_frame("select * from test_table", self.db)

# HACK!
# HACK! Change this once indexes are handled properly.
result.index = frame.index

expected = frame
Expand All @@ -175,6 +178,8 @@ def _check_roundtrip(self, frame):
expected = frame.copy()
expected.index = Index(range(len(frame2))) + 10
expected.index.name = 'Idx'
print expected.index.names
print result.index.names
tm.assert_frame_equal(expected, result)

def test_tquery(self):
Expand Down Expand Up @@ -239,20 +244,27 @@ def test_onecolumn_of_integer(self):
class TestMySQL(unittest.TestCase):

def setUp(self):
_skip_if_no_MySQLdb()
import MySQLdb
try:
import MySQLdb
except ImportError:
raise nose.SkipTest
# Try Travis defaults.
# No real user should allow root access with a blank password.
self.db = MySQLdb.connect(host='localhost', user='root', passwd='',
db='pandas_nosetest')
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to catch the error here, like below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this test may be run by Travis (with root authentication) or by a user (with authentication provided in a defaults file), there is really only an error to catch if BOTH fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...but I'll concede that this approach, equivalent to nest try blocks, is inelegant. I couldn't think of a better way, but I'd be glad for a better suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't mind nested try blocks, but they can get ugly and are hard to follow given significant nesting. i just twitch a little when i see except:, it's not that it's not elegant it's that it hides errors

pass
else:
return
try:
self.db = MySQLdb.connect(read_default_group='pandas')
except MySQLdb.Error, e:
except MySQLdb.ProgrammingError, e:
raise nose.SkipTest(
"Cannot connect to database. "
"Create a group of connection parameters under the heading "
"[pandas] in your system's mysql default file, "
"typically located at ~/.my.cnf or /etc/.my.cnf. ")
except MySQLdb.ProgrammingError, e:
except MySQLdb.Error, e:
raise nose.SkipTest(
"Cannot connect to database. "
"Create a group of connection parameters under the heading "
"[pandas] in your system's mysql default file, "
"typically located at ~/.my.cnf or /etc/.my.cnf. ")
Expand Down Expand Up @@ -288,7 +300,9 @@ def test_execute(self):
drop_sql = "DROP TABLE IF EXISTS test"
create_sql = sql.get_schema(frame, 'test', 'mysql')
cur = self.db.cursor()
cur.execute(drop_sql)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Unknown table.*")
cur.execute(drop_sql)
cur.execute(create_sql)
ins = "INSERT INTO test VALUES (%s, %s, %s, %s)"

Expand Down Expand Up @@ -379,27 +393,36 @@ def _check_roundtrip(self, frame):
_skip_if_no_MySQLdb()
drop_sql = "DROP TABLE IF EXISTS test_table"
cur = self.db.cursor()
cur.execute(drop_sql)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Unknown table.*")
cur.execute(drop_sql)
sql.write_frame(frame, name='test_table', con=self.db, flavor='mysql')
result = sql.read_frame("select * from test_table", self.db)

# HACK!
# HACK! Change this once indexes are handled properly.
result.index = frame.index
result.index.name = frame.index.name

expected = frame
tm.assert_frame_equal(result, expected)

frame['txt'] = ['a'] * len(frame)
frame2 = frame.copy()
frame2['Idx'] = Index(range(len(frame2))) + 10
index = Index(range(len(frame2))) + 10
frame2['Idx'] = index
drop_sql = "DROP TABLE IF EXISTS test_table2"
cur = self.db.cursor()
cur.execute(drop_sql)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Unknown table.*")
cur.execute(drop_sql)
sql.write_frame(frame2, name='test_table2', con=self.db, flavor='mysql')
result = sql.read_frame("select * from test_table2", self.db,
index_col='Idx')
expected = frame.copy()
expected.index = Index(range(len(frame2))) + 10

# HACK! Change this once indexes are handled properly.
expected.index = index
expected.index.names = result.index.names
tm.assert_frame_equal(expected, result)

def test_tquery(self):
Expand Down