MCPcopy Index your code
hub / github.com/python/cpython / test_pack

Method test_pack

Lib/test/test_mailbox.py:1443–1485  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1441 self._box.unlock()
1442
1443 def test_pack(self):
1444 # Pack the contents of the mailbox
1445 msg0 = mailbox.MHMessage(self._template % 0)
1446 msg1 = mailbox.MHMessage(self._template % 1)
1447 msg2 = mailbox.MHMessage(self._template % 2)
1448 msg3 = mailbox.MHMessage(self._template % 3)
1449 msg0.set_sequences(['foo', 'unseen'])
1450 msg1.set_sequences(['foo'])
1451 msg2.set_sequences(['foo', 'flagged'])
1452 msg3.set_sequences(['foo', 'bar', 'replied'])
1453 key0 = self._box.add(msg0)
1454 key1 = self._box.add(msg1)
1455 key2 = self._box.add(msg2)
1456 key3 = self._box.add(msg3)
1457 self.assertEqual(self._box.get_sequences(),
1458 {'foo':[key0,key1,key2,key3], 'unseen':[key0],
1459 'flagged':[key2], 'bar':[key3], 'replied':[key3]})
1460 self._box.remove(key2)
1461 self.assertEqual(self._box.get_sequences(),
1462 {'foo':[key0,key1,key3], 'unseen':[key0], 'bar':[key3],
1463 'replied':[key3]})
1464 self._box.pack()
1465 self.assertEqual(self._box.keys(), [1, 2, 3])
1466 key0 = key0
1467 key1 = key0 + 1
1468 key2 = key1 + 1
1469 self.assertEqual(self._box.get_sequences(),
1470 {'foo':[1, 2, 3], 'unseen':[1], 'bar':[3], 'replied':[3]})
1471
1472 # Test case for packing while holding the mailbox locked.
1473 key0 = self._box.add(msg1)
1474 key1 = self._box.add(msg1)
1475 key2 = self._box.add(msg1)
1476 key3 = self._box.add(msg1)
1477
1478 self._box.remove(key0)
1479 self._box.remove(key2)
1480 self._box.lock()
1481 self._box.pack()
1482 self._box.unlock()
1483 self.assertEqual(self._box.get_sequences(),
1484 {'foo':[1, 2, 3, 4, 5],
1485 'unseen':[1], 'bar':[3], 'replied':[3]})
1486
1487 def _get_lock_path(self):
1488 return os.path.join(self._path, '.mh_sequences.lock')

Callers

nothing calls this directly

Calls 9

set_sequencesMethod · 0.95
addMethod · 0.45
assertEqualMethod · 0.45
get_sequencesMethod · 0.45
removeMethod · 0.45
packMethod · 0.45
keysMethod · 0.45
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected