diff --git a/pymysqlreplication/bitmap.py b/pymysqlreplication/bitmap.py index b02da8a1..804968d7 100644 --- a/pymysqlreplication/bitmap.py +++ b/pymysqlreplication/bitmap.py @@ -1,261 +1,23 @@ +# fmt: off bitCountInByte = [ - 0, - 1, - 1, - 2, - 1, - 2, - 2, - 3, - 1, - 2, - 2, - 3, - 2, - 3, - 3, - 4, - 1, - 2, - 2, - 3, - 2, - 3, - 3, - 4, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 1, - 2, - 2, - 3, - 2, - 3, - 3, - 4, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 1, - 2, - 2, - 3, - 2, - 3, - 3, - 4, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 4, - 5, - 5, - 6, - 5, - 6, - 6, - 7, - 1, - 2, - 2, - 3, - 2, - 3, - 3, - 4, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 4, - 5, - 5, - 6, - 5, - 6, - 6, - 7, - 2, - 3, - 3, - 4, - 3, - 4, - 4, - 5, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 4, - 5, - 5, - 6, - 5, - 6, - 6, - 7, - 3, - 4, - 4, - 5, - 4, - 5, - 5, - 6, - 4, - 5, - 5, - 6, - 5, - 6, - 6, - 7, - 4, - 5, - 5, - 6, - 5, - 6, - 6, - 7, - 5, - 6, - 6, - 7, - 6, - 7, - 7, - 8, + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, ] +# fmt: on # Calculate total bit counts in a bitmap diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index 0198f014..b8988ce0 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -85,6 +85,13 @@ def isMySQL8014AndMore(self): return True return version == 8.0 and version_detail >= 14 + def isMySQL8016AndMore(self): + version = float(self.getMySQLVersion().rsplit(".", 1)[0]) + version_detail = int(self.getMySQLVersion().rsplit(".", 1)[1]) + if version > 8.0: + return True + return version == 8.0 and version_detail >= 16 + def isMariaDB(self): if self.__is_mariaDB is None: self.__is_mariaDB = ( diff --git a/pymysqlreplication/tests/benchmark.py b/pymysqlreplication/tests/benchmark.py index 3cd47bd9..c109985c 100644 --- a/pymysqlreplication/tests/benchmark.py +++ b/pymysqlreplication/tests/benchmark.py @@ -25,12 +25,12 @@ def consume_events(): only_events=[UpdateRowsEvent], only_tables=["test"], ) - start = time.clock() + start = time.perf_counter() i = 0.0 for binlogevent in stream: i += 1.0 if i % 1000 == 0: - print(f"{i / (time.clock()- start)} event by seconds ({i} total)") + print(f"{i / (time.perf_counter()- start)} event by seconds ({i} total)") stream.close() diff --git a/pymysqlreplication/tests/test_data_type.py b/pymysqlreplication/tests/test_data_type.py index cece10c3..4c03ab1c 100644 --- a/pymysqlreplication/tests/test_data_type.py +++ b/pymysqlreplication/tests/test_data_type.py @@ -1,5 +1,4 @@ import copy -import platform import json from pymysqlreplication import BinLogStreamReader import unittest @@ -776,10 +775,7 @@ def test_encoding_latin1(self): db["charset"] = "latin1" self.connect_conn_control(db) - if platform.python_version_tuple()[0] == "2": - string = unichr(233) - else: - string = "\u00e9" + string = "\u00e9" create_query = ( "CREATE TABLE test (test CHAR(12)) CHARACTER SET latin1 COLLATE latin1_bin;" @@ -790,10 +786,7 @@ def test_encoding_latin1(self): self.assertEqual(event.rows[0]["values"]["test"], string) def test_encoding_utf8(self): - if platform.python_version_tuple()[0] == "2": - string = unichr(0x20AC) - else: - string = "\u20ac" + string = "\u20ac" create_query = ( "CREATE TABLE test (test CHAR(12)) CHARACTER SET utf8 COLLATE utf8_bin;" @@ -805,7 +798,7 @@ def test_encoding_utf8(self): self.assertMultiLineEqual(event.rows[0]["values"]["test"], string) def test_partition_id(self): - if not self.isMySQL80AndMore(): + if not self.isMySQL8016AndMore(): self.skipTest("Not supported in this version of MySQL") create_query = "CREATE TABLE test (id INTEGER) \ PARTITION BY RANGE (id) ( \ @@ -970,7 +963,7 @@ def create_and_insert_value(self, create_query, insert_query): return event def test_partition_id(self): - if not self.isMySQL80AndMore(): + if not self.isMySQL8016AndMore(): self.skipTest("Not supported in this version of MySQL") create_query = "CREATE TABLE test (id INTEGER) \ PARTITION BY RANGE (id) ( \