8000 test: self.connections[0] -> self.connect() (#758) · kevinvoid/PyMySQL@7b18bb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b18bb6

Browse files
authored
test: self.connections[0] -> self.connect() (PyMySQL#758)
1 parent c42ddff commit 7b18bb6

File tree

6 files changed

+98
-94
lines changed

6 files changed

+98
-94
lines changed

pymysql/tests/test_DictCursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestDictCursor(base.PyMySQLTestCase):
1414

1515
def setUp(self):
1616
super(TestDictCursor, self).setUp()
17-
self.conn = conn = self.connections[0]
17+
self.conn = conn = self.connect()
1818
c = conn.cursor(self.cursor_type)
1919

2020
# create a table ane some data to query

pymysql/tests/test_basic.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class TestConversion(base.PyMySQLTestCase):
1919
def test_datatypes(self):
2020
""" test every data type """
21-
conn = self.connections[0]
21+
conn = self.connect()
2222
c = conn.cursor()
2323
c.execute("create table test_datatypes (b bit, i int, l bigint, f real, s varchar(32), u varchar(32), bb blob, d date, dt datetime, ts timestamp, td time, t time, st datetime)")
2424
try:
@@ -57,7 +57,7 @@ def test_datatypes(self):
5757

5858
def test_dict(self):
5959
""" test dict escaping """
60-
conn = self.connections[0]
60+
conn = self.connect()
6161
c = conn.cursor()
6262
c.execute("create table test_dict (a integer, b integer, c integer)")
6363
try:
@@ -68,7 +68,7 @@ def test_dict(self):
6868
c.execute("drop table test_dict")
6969

7070
def test_string(self):
71-
conn = self.connections[0]
71+
conn = self.connect()
7272
c = conn.cursor()
7373
c.execute("create table test_dict (a text)")
7474
test_value = "I am a test string"
@@ -80,7 +80,7 @@ def test_string(self):
8080
c.execute("drop table test_dict")
8181

8282
def test_integer(self):
83-
conn = self.connections[0]
83+
conn = self.connect()
8484
c = conn.cursor()
8585
c.execute("create table test_dict (a integer)")
8686
test_value = 12345
@@ -94,7 +94,7 @@ def test_integer(self):
9494
def test_binary(self):
9595
"""test binary data"""
9696
data = bytes(bytearray(range(255)))
97-
conn = self.connections[0]
97+
conn = self.connect()
9898
self.safe_create_table(
9999
conn, "test_binary", "create table test_binary (b binary(255))")
100100

@@ -106,7 +106,7 @@ def test_binary(self):
106106
def test_blob(self):
107107
"""test blob data"""
108108
data = bytes(bytearray(range(256)) * 4)
109-
conn = self.connections[0]
109+
conn = self.connect()
110110
self.safe_create_table(
111111
conn, "test_blob", "create table test_blob (b blob)")
112112

@@ -117,7 +117,7 @@ def test_blob(self):
117117

118118
def test_untyped(self):
119119
""" test conversion of null, empty string """
120-
conn = self.connections[0]
120+
conn = self.connect()
121121
c = conn.cursor()
122122
c.execute("select null,''")
123123
self.assertEqual((None,u''), c.fetchone())
@@ -126,7 +126,7 @@ def test_untyped(self):
126126

127127
def test_timedelta(self):
128128
""" test timedelta conversion """
129-
conn = self.connections[0]
129+
conn = self.connect()
130130
c = conn.cursor()
131131
c.execute("select time('12:30'), time('23:12:59'), time('23:12:59.05100'), time('-12:30'), time('-23:12:59'), time('-23:12:59.05100'), time('-00:30')")
132132
self.assertEqual((datetime.timedelta(0, 45000),
@@ -141,7 +141,7 @@ def test_timedelta(self):
141141
def test_datetime_microseconds(self):
142142
""" test datetime conversion w microseconds"""
143143

144-
conn = self.connections[0]
144+
conn = self.connect()
145145
if not self.mysql_server_is(conn, (5, 6, 4)):
146146
raise SkipTest("target backend does not support microseconds")
147147
c = conn.cursor()
@@ -206,15 +206,15 @@ class TestCursor(base.PyMySQLTestCase):
206206
# ('max_updates', 3, 1, 11, 11, 0, 0),
207207
# ('max_connections', 3, 1, 11, 11, 0, 0),
208208
# ('max_user_connections', 3, 1, 11, 11, 0, 0))
209-
# conn = self.connections[0]
209+
# conn = self.connect()
210210
# c = conn.cursor()
211211
# c.execute("select * from mysql.user")
212212
#
213213
# self.assertEqual(r, c.description)
214214

215215
def test_fetch_no_result(self):
216216
""" test a fetchone() with no rows """
217-
conn = self.connections[0]
217+
conn = self.connect()
218218
c = conn.cursor()
219219
c.execute("create table test_nr (b varchar(32))")
220220
try:
@@ -226,7 +226,7 @@ def test_fetch_no_result(self):
226226

227227
def test_aggregates(self):
228228
""" test aggregate functions """
229-
conn = self.connections[0]
229+
conn = self.connect()
230230
c = conn.cursor()
231231
try:
232232
c.execute('create table test_aggregates (i integer)')
@@ -240,7 +240,7 @@ def test_aggregates(self):
240240

241241
def test_single_tuple(self):
242242
""" test a single tuple """
243-
conn = self.connections[0]
243+
conn = self.connect()
244244
c = conn.cursor()
245245
self.safe_create_table(
246246
conn, 'mystuff',
@@ -283,7 +283,7 @@ class TestBulkInserts(base.PyMySQLTestCase):
283283

284284
def setUp(self):
285285
super(TestBulkInserts, self).setUp()
286-
self.conn = conn = self.connections[0]
286+
self.conn = conn = self.connect()
287287
c = conn.cursor(self.cursor_type)
288288

289289
# create a table ane some data to query
@@ -299,14 +299,14 @@ def setUp(self):
299299
""")
300300

301301
def _verify_records(self, data):
302-
conn = self.connections[0]
302+
conn = self.connect()
303303
cursor = conn.cursor()
304304
cursor.execute("SELECT id, name, age, height from bulkinsert")
305305
result = cursor.fetchall()
306306
self.assertEqual(sorted(data), sorted(result))
307307

308308
def test_bulk_insert(self):
309-
conn = self.connections[0]
309+
conn = self.connect()
310310
cursor = conn.cursor()
311311

312312
data = [(0, "bob", 21, 123), (1, "jim", 56, 45), (2, "fred", 100, 180)]
@@ -320,7 +320,7 @@ def test_bulk_insert(self):
320320
self._verify_records(data)
321321

322322
def test_bulk_insert_multiline_statement(self):
323-
conn = self.connections[0]
323+
conn = self.connect()
324324
cursor = conn.cursor()
325325
data = [(0, "bob", 21, 123), (1, "jim", 56, 45), (2, "fred", 100, 180)]
326326
cursor.executemany("""insert
@@ -344,7 +344,7 @@ def test_bulk_insert_multiline_statement(self):
344344
self._verify_records(data)
345345

346346
def test_bulk_insert_single_record(self):
347-
conn = self.connections[0]
347+
conn = self.connect()
348348
cursor = conn.cursor()
349349
data = [(0, "bob", 21, 123)]
350350
cursor.executemany("insert into bulkinsert (id, name, age, height) "
@@ -354,7 +354,7 @@ def test_bulk_insert_single_record(self):
354354

355355
def test_issue_288(self):
356356
"""executemany should work with "insert ... on update" """
357-
conn = self.connections[0]
357+
conn = self.connect()
358358
cursor = conn.cursor()
359359
data = [(0, "bob", 21, 123), (1, "jim", 56, 45), (2, "fred", 100, 180)]
360360
cursor.executemany("""insert
@@ -380,7 +380,7 @@ def test_issue_288(self):
380380
self._verify_records(data)
381381

382382
def test_warnings(self):
383-
con = self.connections[0]
383+
con = self.connect()
384384
cur = con.cursor()
385385
with warnings.catch_warnings(record=True) as ws:
386386
warnings.simplefilter("always")

0 commit comments

Comments
 (0)
0