Skip to content

Commit 0329902

Browse files
Merge pull request #119 from vartec/master
Unittest for issue #118
2 parents eb1d7a6 + 5349992 commit 0329902

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

pymysqlreplication/tests/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
from pymysqlreplication.tests.test_data_objects import *
66

77
if __name__ == "__main__":
8-
import unittest
8+
if sys.version_info < (2, 7):
9+
import unittest2 as unittest
10+
else:
11+
import unittest
912
unittest.main()

pymysqlreplication/tests/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# -*- coding: utf-8 -*-
22

33
import pymysql
4-
import unittest
54
import copy
65
from pymysqlreplication import BinLogStreamReader
76
import os
87
import sys
98

10-
(major, minor, _, _, _) = sys.version_info
11-
if (major, minor) < (2, 7):
12-
import unittest2
13-
base = unittest2.TestCase
9+
if sys.version_info < (2, 7):
10+
import unittest2 as unittest
1411
else:
15-
base = unittest.TestCase
12+
import unittest
13+
14+
base = unittest.TestCase
1615

1716

1817
class PyMySQLReplicationTestCase(base):

pymysqlreplication/tests/test_basic.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
import unittest
3-
42
import time
3+
import sys
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
58

69
from pymysqlreplication.tests import base
710
from pymysqlreplication import BinLogStreamReader
@@ -585,6 +588,33 @@ def test_drop_column(self):
585588
finally:
586589
self.resetBinLog()
587590

591+
@unittest.expectedFailure
592+
def test_alter_column(self):
593+
self.stream.close()
594+
self.execute("CREATE TABLE test_alter_column (id INTEGER(11), data VARCHAR(50))")
595+
self.execute("INSERT INTO test_alter_column VALUES (1, 'A value')")
596+
self.execute("COMMIT")
597+
# this is a problem only when column is added in position other than at the end
598+
self.execute("ALTER TABLE test_alter_column ADD COLUMN another_data VARCHAR(50) AFTER id")
599+
self.execute("INSERT INTO test_alter_column VALUES (2, 'Another value', 'A value')")
600+
self.execute("COMMIT")
601+
602+
self.stream = BinLogStreamReader(
603+
self.database,
604+
server_id=1024,
605+
only_events=(WriteRowsEvent,),
606+
)
607+
event = self.stream.fetchone() # insert with two values
608+
# both of these asserts fail because of issue underlying proble described in issue #118
609+
# because it got table schema info after the alter table, it wrongly assumes the second
610+
# column of the first insert is 'another_data'
611+
# ER: {'id': 1, 'data': 'A value'}
612+
# AR: {'id': 1, 'another_data': 'A value'}
613+
self.assertIn("data", event.rows[0]["values"])
614+
self.assertNot("another_data", event.rows[0]["values"])
615+
self.assertEqual(event.rows[0]["values"]["data"], 'A value')
616+
self.stream.fetchone() # insert with three values
617+
588618

589619
class TestGtidBinLogStreamReader(base.PyMySQLReplicationTestCase):
590620
def setUp(self):

pymysqlreplication/tests/test_data_objects.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import unittest
1+
import sys
2+
if sys.version_info < (2, 7):
3+
import unittest2 as unittest
4+
else:
5+
import unittest
26

37
from pymysqlreplication.column import Column
48
from pymysqlreplication.table import Table

pymysqlreplication/tests/test_data_type.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import copy
44
import platform
5-
import unittest
5+
import sys
6+
if sys.version_info < (2, 7):
7+
import unittest2 as unittest
8+
else:
9+
import unittest
610

711
from decimal import Decimal
812

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
install_requires = ['pymysql']
1212

1313
# add unittest2 to install_requires for python < 2.7
14-
major, minor, _, _, _ = sys.version_info
15-
if (major, minor) < (2, 7):
14+
if sys.version_info < (2, 7):
1615
install_requires.append("unittest2")
1716

1817

0 commit comments

Comments
 (0)