fix: 兼容非滚动面板静态尺码采集 (#177)

This commit is contained in:
chengma
2026-08-12 10:32:01 +08:00
parent e72462b3d8
commit 2088bc3ea6
2 changed files with 118 additions and 0 deletions
+68
View File
@@ -813,6 +813,74 @@ class PddCollectParserTest(unittest.TestCase):
[item.name for item in result.dimensions],
)
def test_collects_static_sizes_from_non_scrollable_submit_hint_panel(self):
device = FakeCollectDevice(self.home_xml, self.submit_hint_spec_xml)
device.opened_url = (
"https://mobile.yangkeduo.com/goods.html?goods_id=123"
)
device.panel_open = True
service = PddCollectService(
PddDeviceService(lambda _serial: device),
"USB-001",
"client-001",
sleeper=lambda _seconds: None,
)
dimension = service._collect_size_dimension(device)
self.assertIsNotNone(dimension)
self.assertEqual(dimension.name, "尺码")
self.assertEqual(
[value.text for value in dimension.values],
["M", "L"],
)
self.assertEqual(device.swipes, [])
def test_static_sizes_keep_explicit_count_validation(self):
spec_xml = self.submit_hint_spec_xml.replace(
'text="尺码" bounds=', 'text="尺码(3)" bounds=', 1
)
device = FakeCollectDevice(self.home_xml, spec_xml)
device.opened_url = (
"https://mobile.yangkeduo.com/goods.html?goods_id=123"
)
device.panel_open = True
service = PddCollectService(
PddDeviceService(lambda _serial: device),
"USB-001",
"client-001",
sleeper=lambda _seconds: None,
)
with self.assertRaises(PddCollectError) as raised:
service._collect_size_dimension(device)
self.assertEqual(raised.exception.code, "PDD_DATA_SPEC_INCOMPLETE")
self.assertEqual(raised.exception.diagnostics["expected_count"], 3)
self.assertEqual(raised.exception.diagnostics["collected_count"], 2)
def test_static_sizes_require_strong_non_scrollable_panel_evidence(self):
snapshot = parse_spec_panel(self.submit_hint_spec_xml)
dimension = next(
item for item in snapshot.dimensions if item.key == "size"
)
incomplete_evidence_xml = self.submit_hint_spec_xml.replace(
'class="android.widget.EditText"',
'class="android.widget.TextView"',
1,
)
service = PddCollectService(
PddDeviceService(lambda _serial: object()),
"USB-001",
"client-001",
)
result = service._non_scrollable_second_dimension(
incomplete_evidence_xml, dimension
)
self.assertIsNone(result)
def test_isolated_submit_hint_is_not_a_spec_panel(self):
xml_data = """<hierarchy>
<node package="com.xunmeng.pinduoduo"