Skip to content

Commit

Permalink
TST: Create a MySQL database and run MySQL tests on Travis.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Jul 9, 2013
1 parent b3e5338 commit 4db1800
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
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
34 changes: 24 additions & 10 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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 +175,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 +241,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:
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 @@ -383,23 +392,28 @@ def _check_roundtrip(self, frame):
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)
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

0 comments on commit 4db1800

Please sign in to comment.