comparison tests/test_helpers.py @ 945:bfbfc9be3faa

editor: add a pop() method to RevisionMeta to reduce resource usage The commit pass only has to read files once, removing the related data after the read helps not keeping large temporary files around after they have been stored
author Patrick Mezard <patrick@mezard.eu>
date Wed, 26 Sep 2012 21:01:17 +0200
parents
children d741f536f23a
comparison
equal deleted inserted replaced
944:d6db289f1548 945:bfbfc9be3faa
1 import os, sys, unittest
2
3 _rootdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4 sys.path.insert(0, _rootdir)
5
6 from hgsubversion import editor
7
8 class TestHelpers(unittest.TestCase):
9 def test_filestore(self):
10 fs = editor.FileStore(2)
11 fs.setfile('a', 'a')
12 fs.setfile('b', 'b')
13 self.assertEqual('a', fs._data.get('a'))
14 self.assertEqual('b', fs._data.get('b'))
15
16 fs.delfile('b')
17 self.assertRaises(IOError, lambda: fs.getfile('b'))
18 fs.setfile('bb', 'bb')
19 self.assertTrue('bb' in fs._files)
20 self.assertTrue('bb' not in fs._data)
21 self.assertEqual('bb', fs.getfile('bb'))
22
23 fs.delfile('bb')
24 self.assertTrue('bb' not in fs._files)
25 self.assertEqual([], os.listdir(fs._tempdir))
26 self.assertRaises(IOError, lambda: fs.getfile('bb'))
27
28 fs.setfile('bb', 'bb')
29 self.assertEqual(1, len(os.listdir(fs._tempdir)))
30 fs.popfile('bb')
31 self.assertEqual([], os.listdir(fs._tempdir))
32 self.assertRaises(editor.EditingError, lambda: fs.getfile('bb'))
33
34 def suite():
35 return unittest.TestSuite([
36 unittest.TestLoader().loadTestsFromTestCase(TestHelpers),
37 ])