Skip to content

Commit 5107c77

Browse files
committed
refactor: modify scripts by black
1 parent f2f991e commit 5107c77

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

Diff for: pymysqlreplication/row_event.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ def __read_values_name(
137137
if BitGet(cols_bitmap, i) == 0:
138138
# This block is only executed when binlog_row_image = MINIMAL.
139139
# When binlog_row_image = FULL, this block does not execute.
140-
self.__none_sources[name] = 'cols_bitmap'
140+
self.__none_sources[name] = "cols_bitmap"
141141
return None
142142

143143
if self._is_null(null_bitmap, null_bitmap_index):
144-
self.__none_sources[name] = 'null'
144+
self.__none_sources[name] = "null"
145145
return None
146146

147147
if column.type == FIELD_TYPE.TINY:
@@ -187,14 +187,14 @@ def __read_values_name(
187187
elif column.type == FIELD_TYPE.DATETIME:
188188
ret = self.__read_datetime()
189189
if ret is None:
190-
self.__none_sources[name] = 'out of datetime range'
190+
self.__none_sources[name] = "out of datetime range"
191191
return ret
192192
elif column.type == FIELD_TYPE.TIME:
193193
return self.__read_time()
194194
elif column.type == FIELD_TYPE.DATE:
195195
ret = self.__read_date()
196196
if ret is None:
197-
self.__none_sources[name] = 'out of date range'
197+
self.__none_sources[name] = "out of date range"
198198
return ret
199199
elif column.type == FIELD_TYPE.TIMESTAMP:
200200
return datetime.datetime.utcfromtimestamp(self.packet.read_uint32())
@@ -203,7 +203,7 @@ def __read_values_name(
203203
elif column.type == FIELD_TYPE.DATETIME2:
204204
ret = self.__read_datetime2(column)
205205
if ret is None:
206-
self.__none_sources[name] = 'out of datetime2 range'
206+
self.__none_sources[name] = "out of datetime2 range"
207207
return ret
208208
elif column.type == FIELD_TYPE.TIME2:
209209
return self.__read_time2(column)
@@ -547,12 +547,15 @@ def _dump(self):
547547
for row in self.rows:
548548
print("--")
549549
for key in row["values"]:
550-
none_source = row["none_sources"][key] if key in row["none_sources"] else ""
550+
none_source = (
551+
row["none_sources"][key] if key in row["none_sources"] else ""
552+
)
551553
if none_source:
552554
print("*", key, ":", row["values"][key], f"({none_source})")
553555
else:
554556
print("*", key, ":", row["values"][key])
555557

558+
556559
class WriteRowsEvent(RowsEvent):
557560
"""This event is triggered when a row in database is added
558561
@@ -580,7 +583,9 @@ def _dump(self):
580583
for row in self.rows:
581584
print("--")
582585
for key in row["values"]:
583-
none_source = row["none_sources"][key] if key in row["none_sources"] else ""
586+
none_source = (
587+
row["none_sources"][key] if key in row["none_sources"] else ""
588+
)
584589
if none_source:
585590
print("*", key, ":", row["values"][key], f"({none_source})")
586591
else:
@@ -626,14 +631,18 @@ def _dump(self):
626631
print("--")
627632
for key in row["before_values"]:
628633
if key in row["before_none_source"]:
629-
before_value_info = "%s(%s)" % (row["before_values"][key],
630-
row["before_none_source"][key])
634+
before_value_info = "%s(%s)" % (
635+
row["before_values"][key],
636+
row["before_none_source"][key],
637+
)
631638
else:
632639
before_value_info = row["before_values"][key]
633640

634641
if key in row["after_none_source"]:
635-
after_value_info = "%s(%s)" % (row["after_values"][key],
636-
row["after_none_source"][key])
642+
after_value_info = "%s(%s)" % (
643+
row["after_values"][key],
644+
row["after_none_source"][key],
645+
)
637646
else:
638647
after_value_info = row["after_values"][key]
639648

Diff for: pymysqlreplication/tests/test_basic.py

+28-16
Original file line numberDiff line numberDiff line change
@@ -609,23 +609,31 @@ def test_get_none(self):
609609
self.database,
610610
server_id=1024,
611611
resume_stream=False,
612-
only_events=[WriteRowsEvent]
612+
only_events=[WriteRowsEvent],
613613
)
614614
query = "CREATE TABLE null_operation_update_example (col1 INT, col2 INT);"
615615
self.execute(query)
616-
query = "INSERT INTO null_operation_update_example (col1, col2) VALUES (NULL, 1);"
616+
query = (
617+
"INSERT INTO null_operation_update_example (col1, col2) VALUES (NULL, 1);"
618+
)
617619
self.execute(query)
618620
self.execute("COMMIT")
619621
write_rows_event = self.stream.fetchone()
620622
self.assertIsInstance(write_rows_event, WriteRowsEvent)
621-
self.assertEqual(write_rows_event.rows[0]['none_sources']['col1'], 'null')
623+
self.assertEqual(write_rows_event.rows[0]["none_sources"]["col1"], "null")
622624

623625
def test_get_none_invalid(self):
624626
self.execute("SET SESSION SQL_MODE='ALLOW_INVALID_DATES'")
625-
self.execute("CREATE TABLE test_table (col0 INT, col1 VARCHAR(10), col2 DATETIME, col3 DATE, col4 SET('a', 'b', 'c'))")
626-
self.execute("INSERT INTO test_table VALUES (NULL, NULL, '0000-00-00 00:00:00', NULL, NULL)")
627+
self.execute(
628+
"CREATE TABLE test_table (col0 INT, col1 VARCHAR(10), col2 DATETIME, col3 DATE, col4 SET('a', 'b', 'c'))"
629+
)
630+
self.execute(
631+
"INSERT INTO test_table VALUES (NULL, NULL, '0000-00-00 00:00:00', NULL, NULL)"
632+
)
627633
self.resetBinLog()
628-
self.execute("UPDATE test_table SET col1 = NULL, col2 = NULL, col3='0000-00-00',col4 = 'd' WHERE col0 IS NULL")
634+
self.execute(
635+
"UPDATE test_table SET col1 = NULL, col2 = NULL, col3='0000-00-00',col4 = 'd' WHERE col0 IS NULL"
636+
)
629637
self.execute("COMMIT")
630638

631639
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
@@ -639,16 +647,20 @@ def test_get_none_invalid(self):
639647
else:
640648
self.assertEqual(event.event_type, UPDATE_ROWS_EVENT_V1)
641649
self.assertIsInstance(event, UpdateRowsEvent)
642-
self.assertEqual(event.rows[0]["before_none_source"]["col0"], 'null')
643-
self.assertEqual(event.rows[0]["before_none_source"]["col1"], 'null')
644-
self.assertEqual(event.rows[0]["before_none_source"]["col2"], 'out of datetime2 range')
645-
self.assertEqual(event.rows[0]["before_none_source"]["col3"], 'null')
646-
self.assertEqual(event.rows[0]["before_none_source"]["col4"], 'null')
647-
self.assertEqual(event.rows[0]["after_none_source"]["col0"], 'null')
648-
self.assertEqual(event.rows[0]["after_none_source"]["col1"], 'null')
649-
self.assertEqual(event.rows[0]["after_none_source"]["col2"], 'null')
650-
self.assertEqual(event.rows[0]["after_none_source"]["col3"], 'out of date range')
651-
self.assertEqual(event.rows[0]["after_none_source"]["col4"], 'empty set')
650+
self.assertEqual(event.rows[0]["before_none_source"]["col0"], "null")
651+
self.assertEqual(event.rows[0]["before_none_source"]["col1"], "null")
652+
self.assertEqual(
653+
event.rows[0]["before_none_source"]["col2"], "out of datetime2 range"
654+
)
655+
self.assertEqual(event.rows[0]["before_none_source"]["col3"], "null")
656+
self.assertEqual(event.rows[0]["before_none_source"]["col4"], "null")
657+
self.assertEqual(event.rows[0]["after_none_source"]["col0"], "null")
658+
self.assertEqual(event.rows[0]["after_none_source"]["col1"], "null")
659+
self.assertEqual(event.rows[0]["after_none_source"]["col2"], "null")
660+
self.assertEqual(
661+
event.rows[0]["after_none_source"]["col3"], "out of date range"
662+
)
663+
self.assertEqual(event.rows[0]["after_none_source"]["col4"], "empty set")
652664

653665

654666
class TestMultipleRowBinLogStreamReader(base.PyMySQLReplicationTestCase):

0 commit comments

Comments
 (0)