"""内存数据库(MockMySQL):模拟 MySQL 的表读写,供用例做落库校验。 只提供用例所需的最小查询能力(insert/select/count),字段命名沿用 snake_case,贴近真实库表列名;缓存侧(MockRedis)则用 camelCase, 模拟真实系统"库与缓存字段命名不一致、断言前需归一化"的常见情况。 """ class MockMySQL: def __init__(self): self._tables = {} def insert(self, table, row): """插入一行(dict)。""" self._tables.setdefault(table, []).append(dict(row)) def select(self, table, **where): """按等值条件查询,返回匹配的行(list[dict]);无条件返回全表。""" rows = self._tables.get(table, []) return [row for row in rows if all(row.get(k) == v for k, v in where.items())] def count(self, table, **where): """按条件统计行数。""" return len(self.select(table, **where))