MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_pack

Method test_pack

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

Source from the content-addressed store, hash-verified

1426 self._box.unlock()
1427
1428 def test_pack(self):
1429 # Pack the contents of the mailbox
1430 msg0 = mailbox.MHMessage(self._template % 0)
1431 msg1 = mailbox.MHMessage(self._template % 1)
1432 msg2 = mailbox.MHMessage(self._template % 2)
1433 msg3 = mailbox.MHMessage(self._template % 3)
1434 msg0.set_sequences(['foo', 'unseen'])
1435 msg1.set_sequences(['foo'])
1436 msg2.set_sequences(['foo', 'flagged'])
1437 msg3.set_sequences(['foo', 'bar', 'replied'])
1438 key0 = self._box.add(msg0)
1439 key1 = self._box.add(msg1)
1440 key2 = self._box.add(msg2)
1441 key3 = self._box.add(msg3)
1442 self.assertEqual(self._box.get_sequences(),
1443 {'foo':[key0,key1,key2,key3], 'unseen':[key0],
1444 'flagged':[key2], 'bar':[key3], 'replied':[key3]})
1445 self._box.remove(key2)
1446 self.assertEqual(self._box.get_sequences(),
1447 {'foo':[key0,key1,key3], 'unseen':[key0], 'bar':[key3],
1448 'replied':[key3]})
1449 self._box.pack()
1450 self.assertEqual(self._box.keys(), [1, 2, 3])
1451 key0 = key0
1452 key1 = key0 + 1
1453 key2 = key1 + 1
1454 self.assertEqual(self._box.get_sequences(),
1455 {'foo':[1, 2, 3], 'unseen':[1], 'bar':[3], 'replied':[3]})
1456
1457 # Test case for packing while holding the mailbox locked.
1458 key0 = self._box.add(msg1)
1459 key1 = self._box.add(msg1)
1460 key2 = self._box.add(msg1)
1461 key3 = self._box.add(msg1)
1462
1463 self._box.remove(key0)
1464 self._box.remove(key2)
1465 self._box.lock()
1466 self._box.pack()
1467 self._box.unlock()
1468 self.assertEqual(self._box.get_sequences(),
1469 {'foo':[1, 2, 3, 4, 5],
1470 'unseen':[1], 'bar':[3], 'replied':[3]})
1471
1472 def _get_lock_path(self):
1473 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