Skip to content

Commit 0372035

Browse files
authored
Fix RowsEvent.__is_null usage in tests (#374)
The test `TestDataType::test_null_bitmask` currently fails with ``` AttributeError: type object 'RowsEvent' has no attribute '_TestDataType__is_null'` ``` The test method in the `TestDataType` class calls the `__is_null` method of the `RowsEvent` class. Due to name mangling of "private" methods/variables in Python [1] the calling class name is prepended to the method name. This makes the call fail when called from a foreign class. This commit fixes that by a) Renaming `__is_null` to `_is_null` which is only "private" by convention and involves no name mangling. b) Makes the method a staticmethod, as it's not depending on any instances or class attributes/ methods, and is referenced by class only (and not by instance) in the test. [1] https://docs.python.org/3/tutorial/classes.html#private-variables
1 parent f5ff4d9 commit 0372035

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pymysqlreplication/row_event.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
8585
if self._fail_on_table_metadata_unavailable:
8686
raise TableMetadataUnavailableError(self.table)
8787

88-
def __is_null(self, null_bitmap, position):
88+
@staticmethod
89+
def _is_null(null_bitmap, position):
8990
bit = null_bitmap[int(position / 8)]
9091
if type(bit) is str:
9192
bit = ord(bit)
@@ -113,7 +114,7 @@ def _read_column_data(self, cols_bitmap):
113114
values[name] = None
114115
continue
115116

116-
if self.__is_null(null_bitmap, nullBitmapIndex):
117+
if self._is_null(null_bitmap, nullBitmapIndex):
117118
values[name] = None
118119
elif column.type == FIELD_TYPE.TINY:
119120
if unsigned:
@@ -649,7 +650,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
649650
self.table, self.columns)
650651

651652
# ith column is nullable if (i - 1)th bit is set to True, not nullable otherwise
652-
## Refer to definition of and call to row.event.__is_null() to interpret bitmap corresponding to columns
653+
## Refer to definition of and call to row.event._is_null() to interpret bitmap corresponding to columns
653654
self.null_bitmask = self.packet.read((self.column_count + 7) / 8)
654655

655656
def get_table(self):

pymysqlreplication/tests/test_data_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def test_null_bitmask(self):
730730
column_type = "INT"
731731
column_definition.append(column_type)
732732

733-
nullability = "NOT NULL" if not RowsEvent.__is_null(bit_mask, i) else ""
733+
nullability = "NOT NULL" if not RowsEvent._is_null(bit_mask, i) else ""
734734
column_definition.append(nullability)
735735

736736
columns.append(" ".join(column_definition))

0 commit comments

Comments
 (0)