Back to index

obnam  1.1
chunklist_tests.py
Go to the documentation of this file.
00001 # Copyright 2010  Lars Wirzenius
00002 # 
00003 # This program is free software: you can redistribute it and/or modify
00004 # it under the terms of the GNU General Public License as published by
00005 # the Free Software Foundation, either version 3 of the License, or
00006 # (at your option) any later version.
00007 # 
00008 # This program is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU General Public License for more details.
00012 # 
00013 # You should have received a copy of the GNU General Public License
00014 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015 
00016 
00017 import shutil
00018 import tempfile
00019 import unittest
00020 
00021 import obnamlib
00022 
00023 
00024 class ChunkListTests(unittest.TestCase):
00025 
00026     def setUp(self):
00027         self.tempdir = tempfile.mkdtemp()
00028         fs = obnamlib.LocalFS(self.tempdir)
00029         self.hooks = obnamlib.HookManager()
00030         self.hooks.new('repository-toplevel-init')
00031         self.list = obnamlib.ChunkList(fs, 
00032                                        obnamlib.DEFAULT_NODE_SIZE,
00033                                        obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE,
00034                                        obnamlib.DEFAULT_LRU_SIZE, self)
00035 
00036     def tearDown(self):
00037         shutil.rmtree(self.tempdir)
00038 
00039     def test_raises_keyerror_for_missing_chunk(self):
00040         self.assertRaises(KeyError, self.list.get_checksum, 0)
00041         
00042     def test_adds_chunk(self):
00043         self.list.add(0, 'checksum')
00044         self.assertEqual(self.list.get_checksum(0), 'checksum')
00045         
00046     def test_adds_second_chunk(self):
00047         self.list.add(0, 'checksum')
00048         self.list.add(1, 'checksum1')
00049         self.assertEqual(self.list.get_checksum(1), 'checksum1')
00050 
00051     def test_removes_chunk(self):
00052         self.list.add(0, 'checksum')
00053         self.list.remove(0)
00054         self.assertRaises(KeyError, self.list.get_checksum, 0)
00055