FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use Ruff instead of flake8 by methane · Pull Request #1112 · PyMySQL/PyMySQL · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
F841
  • Loading branch information
methane committed May 24, 2023
commit b8358f6a65052a229ca6f5201a94acab5c0b1b95
1 change: 0 additions & 1 deletion pymysql/tests/test_basic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class TestBulkInserts(base.PyMySQLTestCase):
def setUp(self):
super(TestBulkInserts, self).setUp()
self.conn = conn = self.connect()
c = conn.cursor(self.cursor_type)

# create a table and some data to query
self.safe_create_table(
Expand Down
68 changes: 21 additions & 47 deletions pymysql/tests/test_connection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def realtestSocketAuth(self):
TestAuthentication.osuser + "@localhost",
self.databases[0]["database"],
self.socket_plugin_name,
) as u:
c = pymysql.connect(user=TestAuthentication.osuser, **self.db)
):
pymysql.connect(user=TestAuthentication.osuser, **self.db)

class Dialog:
fail = False
Expand All @@ -167,7 +167,7 @@ def __init__(self, con):
def authenticate(self, pkt):
while True:
flag = pkt.read_uint8()
echo = (flag & 0x06) == 0x02
# echo = (flag & 0x06) == 0x02
last = (flag & 0x01) == 0x01
prompt = pkt.read_all()

Expand Down Expand Up @@ -219,7 +219,7 @@ def realTestDialogAuthTwoQuestions(self):
self.databases[0]["database"],
"two_questions",
"notverysecret",
) as u:
):
with self.assertRaises(pymysql.err.OperationalError):
pymysql.connect(user="pymysql_2q", **self.db)
pymysql.connect(
Expand Down Expand Up @@ -261,7 +261,7 @@ def realTestDialogAuthThreeAttempts(self):
self.databases[0]["database"],
"three_attempts",
"stillnotverysecret",
) as u:
):
pymysql.connect(
user="pymysql_3a",
auth_plugin_map={b"dialog": TestAuthentication.Dialog},
Expand Down Expand Up @@ -356,9 +356,9 @@ def realTestPamAuth(self):
self.databases[0]["database"],
"pam",
os.environ.get("PAMSERVICE"),
) as u:
):
try:
c = pymysql.connect(user=TestAuthentication.osuser, **db)
pymysql.connect(user=TestAuthentication.osuser, **db)
db["password"] = "very bad guess at password"
with self.assertRaises(pymysql.err.OperationalError):
pymysql.connect(
Expand Down Expand Up @@ -396,7 +396,7 @@ def testAuthSHA256(self):
"pymysql_sha256@localhost",
self.databases[0]["database"],
"sha256_password",
) as u:
):
c.execute("SET PASSWORD FOR 'pymysql_sha256'@'localhost' ='Sh@256Pa33'")
c.execute("FLUSH PRIVILEGES")
db = self.db.copy()
Expand All @@ -422,7 +422,7 @@ def testAuthEd25519(self):
self.databases[0]["database"],
"ed25519",
empty_pass,
) as u:
):
pymysql.connect(user="pymysql_ed25519", password="", **db)

with TempUser(
Expand All @@ -431,7 +431,7 @@ def testAuthEd25519(self):
self.databases[0]["database"],
"ed25519",
non_empty_pass,
) as u:
):
pymysql.connect(user="pymysql_ed25519", password="ed25519_password", **db)


Expand All @@ -440,7 +440,7 @@ def test_utf8mb4(self):
"""This test requires MySQL >= 5.5"""
arg = self.databases[0].copy()
arg["charset"] = "utf8mb4"
conn = pymysql.connect(**arg)
pymysql.connect(**arg)

def test_largedata(self):
"""Large query and response (>=16MB)"""
Expand Down Expand Up @@ -543,9 +543,7 @@ def test_defer_connect(self):

def test_ssl_connect(self):
dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -564,9 +562,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_called_with("cipher")

dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -584,9 +580,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -600,9 +594,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -619,9 +611,7 @@ def test_ssl_connect(self):

for ssl_verify_cert in (True, "1", "yes", "true"):
dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -640,9 +630,7 @@ def test_ssl_connect(self):

for ssl_verify_cert in (None, False, "0", "no", "false"):
dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -662,9 +650,7 @@ def test_ssl_connect(self):
for ssl_ca in ("ca", None):
for ssl_verify_cert in ("foo", "bar", ""):
dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -685,9 +671,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -704,9 +688,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -721,9 +703,7 @@ def test_ssl_connect(self):
assert not create_default_context.called

dummy_ssl_context = mock.Mock(options=0)
with mock.patch(
"pymysql.connections.Connection.connect"
) as connect, mock.patch(
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand Down Expand Up @@ -761,21 +741,18 @@ def test_escape_string(self):

def test_escape_builtin_encoders(self):
con = self.connect()
cur = con.cursor()

val = datetime.datetime(2012, 3, 4, 5, 6)
self.assertEqual(con.escape(val, con.encoders), "'2012-03-04 05:06:00'")

def test_escape_custom_object(self):
con = self.connect()
cur = con.cursor()

mapping = {Foo: escape_foo}
self.assertEqual(con.escape(Foo(), mapping), "bar")

def test_escape_fallback_encoder(self):
con = self.connect()
cur = con.cursor()

class Custom(str):
pass
Expand All @@ -785,21 +762,18 @@ class Custom(str):

def test_escape_no_default(self):
con = self.connect()
cur = con.cursor()

self.assertRaises(TypeError, con.escape, 42, {})

def test_escape_dict_value(self):
con = self.connect()
cur = con.cursor()

mapping = con.encoders.copy()
mapping[Foo] = escape_foo
self.assertEqual(con.escape({"foo": Foo()}, mapping), {"foo": "bar"})

def test_escape_list_item(self):
con = self.connect()
cur = con.cursor()

mapping = con.encoders.copy()
mapping[Foo] = escape_foo
Expand Down
20 changes: 9 additions & 11 deletions pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_rollback(self):
def test_cursor(self):
con = self._connect()
try:
cur = con.cursor()
con.cursor()
finally:
con.close()

Expand Down Expand Up @@ -810,28 +810,26 @@ def test_None(self):
con.close()

def test_Date(self):
d1 = self.driver.Date(2002, 12, 25)
d2 = self.driver.DateFromTicks(time.mktime((2002, 12, 25, 0, 0, 0, 0, 0, 0)))
self.driver.Date(2002, 12, 25)
self.driver.DateFromTicks(time.mktime((2002, 12, 25, 0, 0, 0, 0, 0, 0)))
# Can we assume this? API doesn't specify, but it seems implied
# self.assertEqual(str(d1),str(d2))

def test_Time(self):
t1 = self.driver.Time(13, 45, 30)
t2 = self.driver.TimeFromTicks(time.mktime((2001, 1, 1, 13, 45, 30, 0, 0, 0)))
self.driver.Time(13, 45, 30)
self.driver.TimeFromTicks(time.mktime((2001, 1, 1, 13, 45, 30, 0, 0, 0)))
# Can we assume this? API doesn't specify, but it seems implied
# self.assertEqual(str(t1),str(t2))

def test_Timestamp(self):
t1 = self.driver.Timestamp(2002, 12, 25, 13, 45, 30)
t2 = self.driver.TimestampFromTicks(
time.mktime((2002, 12, 25, 13, 45, 30, 0, 0, 0))
)
self.driver.Timestamp(2002, 12, 25, 13, 45, 30)
self.driver.TimestampFromTicks(time.mktime((2002, 12, 25, 13, 45, 30, 0, 0, 0)))
# Can we assume this? API doesn't specify, but it seems implied
# self.assertEqual(str(t1),str(t2))

def test_Binary(self):
b = self.driver.Binary(b"Something")
b = self.driver.Binary(b"")
self.driver.Binary(b"Something")
self.driver.Binary(b"")

def test_STRING(self):
self.assertTrue(hasattr(self.driver, "STRING"), "module.STRING must be defined")
Expand Down

Back | FazBrowse Home | New Git URL