Back to index

obnam  1.1
Public Member Functions | Public Attributes
obnamlib.clientmetadatatree_tests.ClientMetadataTreeTests Class Reference

List of all members.

Public Member Functions

def current_time
def setUp
def tearDown
def test_has_not_current_generation_initially
def test_lists_no_generations_initially
def test_starts_generation
def test_starts_second_generation
def test_sets_is_checkpoint
def test_unsets_is_checkpoint
def test_removes_generation
def test_removes_started_generation
def test_started_generation_has_start_time
def test_committed_generation_has_times
def test_single_empty_generation_counts_zero_files
def test_counts_files_in_first_generation
def test_counts_new_files_in_second_generation
def test_discounts_deleted_files_in_second_generation
def test_does_not_increment_count_for_recreated_files
def test_single_empty_generation_has_no_data
def test_has_data_in_first_generation
def test_counts_new_files_in_second_generation
def test_counts_replaced_data_in_second_generation
def test_discounts_deleted_data_in_second_generation
def test_does_not_increment_data_for_recreated_files
def test_finds_generation_the_first_time
def test_finds_generation_the_second_time
def test_find_generation_raises_keyerror_for_empty_forest
def test_find_generation_raises_keyerror_for_unknown_generation

Public Attributes

 now
 tempdir
 hooks
 client
 file_size
 file_metadata
 file_encoded

Detailed Description

Definition at line 26 of file clientmetadatatree_tests.py.


Member Function Documentation

Definition at line 28 of file clientmetadatatree_tests.py.

00028 
00029     def current_time(self):
00030         return time.time() if self.now is None else self.now

Definition at line 31 of file clientmetadatatree_tests.py.

00031 
00032     def setUp(self):
00033         self.now = None
00034         self.tempdir = tempfile.mkdtemp()
00035         fs = obnamlib.LocalFS(self.tempdir)
00036         self.hooks = obnamlib.HookManager()
00037         self.hooks.new('repository-toplevel-init')
00038         self.client = obnamlib.ClientMetadataTree(fs, 'clientid',
00039                                    obnamlib.DEFAULT_NODE_SIZE,
00040                                    obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE,
00041                                    obnamlib.DEFAULT_LRU_SIZE, self)
00042         self.file_size = 123
00043         self.file_metadata = obnamlib.Metadata(st_mode=stat.S_IFREG | 0666,
00044                                                st_size=self.file_size)
00045         self.file_encoded = obnamlib.encode_metadata(self.file_metadata)
        

Definition at line 46 of file clientmetadatatree_tests.py.

00046 
00047     def tearDown(self):
00048         shutil.rmtree(self.tempdir)

Definition at line 122 of file clientmetadatatree_tests.py.

00122 
00123     def test_committed_generation_has_times(self):
00124         self.now = 1
00125         self.client.start_generation()
00126         genid = self.client.get_generation_id(self.client.tree)
00127         self.now = 2
00128         self.client.commit()
00129         self.assertEqual(self.client.get_generation_times(genid), (1, 2))

Definition at line 136 of file clientmetadatatree_tests.py.

00136 
00137     def test_counts_files_in_first_generation(self):
00138         self.client.start_generation()
00139         genid = self.client.get_generation_id(self.client.tree)
00140         self.client.create('/foo', self.file_encoded)
00141         self.client.commit()
00142         self.assertEqual(self.client.get_generation_file_count(genid), 1)

Definition at line 143 of file clientmetadatatree_tests.py.

00143 
00144     def test_counts_new_files_in_second_generation(self):
00145         self.client.start_generation()
00146         self.client.create('/foo', self.file_encoded)
00147         self.client.commit()
00148 
00149         self.client.start_generation()
00150         genid = self.client.get_generation_id(self.client.tree)
00151         self.client.create('/bar', self.file_encoded)
00152         self.client.commit()
00153 
00154         self.assertEqual(self.client.get_generation_file_count(genid), 2)

Here is the caller graph for this function:

Definition at line 193 of file clientmetadatatree_tests.py.

00193 
00194     def test_counts_new_files_in_second_generation(self):
00195         self.client.start_generation()
00196         self.client.create('/foo', self.file_encoded)
00197         self.client.commit()
00198 
00199         self.client.start_generation()
00200         genid = self.client.get_generation_id(self.client.tree)
00201         self.client.create('/bar', self.file_encoded)
00202         self.client.commit()
00203 
00204         self.assertEqual(self.client.get_generation_data(genid),
00205                          2 * self.file_size)

Here is the call graph for this function:

Definition at line 206 of file clientmetadatatree_tests.py.

00206 
00207     def test_counts_replaced_data_in_second_generation(self):
00208         self.client.start_generation()
00209         self.client.create('/foo', self.file_encoded)
00210         self.client.commit()
00211 
00212         self.client.start_generation()
00213         genid = self.client.get_generation_id(self.client.tree)
00214         self.client.create('/foo', self.file_encoded)
00215         self.client.commit()
00216 
00217         self.assertEqual(self.client.get_generation_data(genid),
00218                          self.file_size)

Definition at line 219 of file clientmetadatatree_tests.py.

00219 
00220     def test_discounts_deleted_data_in_second_generation(self):
00221         self.client.start_generation()
00222         self.client.create('/foo', self.file_encoded)
00223         self.client.commit()
00224 
00225         self.client.start_generation()
00226         genid = self.client.get_generation_id(self.client.tree)
00227         self.client.remove('/foo')
00228         self.client.commit()
00229 
00230         self.assertEqual(self.client.get_generation_data(genid), 0)

Definition at line 155 of file clientmetadatatree_tests.py.

00155 
00156     def test_discounts_deleted_files_in_second_generation(self):
00157         self.client.start_generation()
00158         self.client.create('/foo', self.file_encoded)
00159         self.client.commit()
00160 
00161         self.client.start_generation()
00162         genid = self.client.get_generation_id(self.client.tree)
00163         self.client.remove('/foo')
00164         self.client.commit()
00165 
00166         self.assertEqual(self.client.get_generation_file_count(genid), 0)

Definition at line 167 of file clientmetadatatree_tests.py.

00167 
00168     def test_does_not_increment_count_for_recreated_files(self):
00169         self.client.start_generation()
00170         self.client.create('/foo', self.file_encoded)
00171         self.client.commit()
00172 
00173         self.client.start_generation()
00174         genid = self.client.get_generation_id(self.client.tree)
00175         self.client.create('/foo', self.file_encoded)
00176         self.client.commit()
00177 
00178         self.assertEqual(self.client.get_generation_file_count(genid), 1)

Definition at line 231 of file clientmetadatatree_tests.py.

00231 
00232     def test_does_not_increment_data_for_recreated_files(self):
00233         self.client.start_generation()
00234         self.client.create('/foo', self.file_encoded)
00235         self.client.commit()
00236 
00237         self.client.start_generation()
00238         genid = self.client.get_generation_id(self.client.tree)
00239         self.client.create('/foo', self.file_encoded)
00240         self.client.commit()
00241 
00242         self.assertEqual(self.client.get_generation_data(genid), 
00243                          self.file_size)

Definition at line 259 of file clientmetadatatree_tests.py.

00259 
00260     def test_find_generation_raises_keyerror_for_empty_forest(self):
00261         self.client.init_forest()
00262         self.assertRaises(KeyError, self.client.find_generation, 0)

Definition at line 263 of file clientmetadatatree_tests.py.

00263 
00264     def test_find_generation_raises_keyerror_for_unknown_generation(self):
00265         self.assertRaises(KeyError, self.client.find_generation, 0)
00266 

Definition at line 244 of file clientmetadatatree_tests.py.

00244 
00245     def test_finds_generation_the_first_time(self):
00246         self.client.start_generation()
00247         tree = self.client.tree
00248         genid = self.client.get_generation_id(tree)
00249         self.client.commit()
00250         self.assertEqual(self.client.find_generation(genid), tree)

Definition at line 251 of file clientmetadatatree_tests.py.

00251 
00252     def test_finds_generation_the_second_time(self):
00253         self.client.start_generation()
00254         tree = self.client.tree
00255         genid = self.client.get_generation_id(tree)
00256         self.client.commit()
00257         self.client.find_generation(genid)
00258         self.assertEqual(self.client.find_generation(genid), tree)

Definition at line 185 of file clientmetadatatree_tests.py.

00185 
00186     def test_has_data_in_first_generation(self):
00187         self.client.start_generation()
00188         genid = self.client.get_generation_id(self.client.tree)
00189         self.client.create('/foo', self.file_encoded)
00190         self.client.commit()
00191         self.assertEqual(self.client.get_generation_data(genid),
00192                          self.file_size)

Definition at line 49 of file clientmetadatatree_tests.py.

00049 
00050     def test_has_not_current_generation_initially(self):
00051         self.assertEqual(self.client.tree, None)
    

Definition at line 52 of file clientmetadatatree_tests.py.

00052 
00053     def test_lists_no_generations_initially(self):
00054         self.assertEqual(self.client.list_generations(), [])

Definition at line 103 of file clientmetadatatree_tests.py.

00103 
00104     def test_removes_generation(self):
00105         self.client.start_generation()
00106         self.client.commit()
00107         genid = self.client.list_generations()[0]
00108         self.client.remove_generation(genid)
00109         self.assertEqual(self.client.list_generations(), [])

Definition at line 110 of file clientmetadatatree_tests.py.

00110 
00111     def test_removes_started_generation(self):
00112         self.client.start_generation()
00113         self.client.remove_generation(self.client.list_generations()[0])
00114         self.assertEqual(self.client.list_generations(), [])
00115         self.assertEqual(self.client.tree, None)

Definition at line 90 of file clientmetadatatree_tests.py.

00090 
00091     def test_sets_is_checkpoint(self):
00092         self.client.start_generation()
00093         genid = self.client.get_generation_id(self.client.tree)
00094         self.client.set_current_generation_is_checkpoint(True)
00095         self.assert_(self.client.get_is_checkpoint(genid))

Definition at line 130 of file clientmetadatatree_tests.py.

00130 
00131     def test_single_empty_generation_counts_zero_files(self):
00132         self.client.start_generation()
00133         genid = self.client.get_generation_id(self.client.tree)
00134         self.client.commit()
00135         self.assertEqual(self.client.get_generation_file_count(genid), 0)

Definition at line 179 of file clientmetadatatree_tests.py.

00179 
00180     def test_single_empty_generation_has_no_data(self):
00181         self.client.start_generation()
00182         genid = self.client.get_generation_id(self.client.tree)
00183         self.client.commit()
00184         self.assertEqual(self.client.get_generation_data(genid), 0)

Definition at line 116 of file clientmetadatatree_tests.py.

00116 
00117     def test_started_generation_has_start_time(self):
00118         self.now = 1
00119         self.client.start_generation()
00120         genid = self.client.get_generation_id(self.client.tree)
00121         self.assertEqual(self.client.get_generation_times(genid), (1, None))

Definition at line 55 of file clientmetadatatree_tests.py.

00055 
00056     def test_starts_generation(self):
00057         self.now = 12765
00058         self.client.start_generation()
00059         self.assertNotEqual(self.client.tree, None)
00060         
00061         def lookup(x):
00062             key = self.client.genkey(x)
00063             return self.client._lookup_int(self.client.tree, key)
00064 
00065         genid = self.client.get_generation_id(self.client.tree)
00066         self.assertEqual(lookup(self.client.GEN_ID), genid)
00067         self.assertEqual(lookup(self.client.GEN_STARTED), 12765)
00068         self.assertFalse(self.client.get_is_checkpoint(genid))

Definition at line 69 of file clientmetadatatree_tests.py.

00069 
00070     def test_starts_second_generation(self):
00071         self.now = 1
00072         self.client.start_generation()
00073         genid1 = self.client.get_generation_id(self.client.tree)
00074         self.client.commit()
00075         self.assertEqual(self.client.tree, None)
00076         self.now = 2
00077         self.client.start_generation()
00078         self.assertNotEqual(self.client.tree, None)
00079         
00080         def lookup(x):
00081             key = self.client.genkey(x)
00082             return self.client._lookup_int(self.client.tree, key)
00083 
00084         genid2 = self.client.get_generation_id(self.client.tree)
00085         self.assertEqual(lookup(self.client.GEN_ID), genid2)
00086         self.assertNotEqual(genid1, genid2)
00087         self.assertEqual(lookup(self.client.GEN_STARTED), 2)
00088         self.assertFalse(self.client.get_is_checkpoint(genid2))
00089         self.assertEqual(self.client.list_generations(), [genid1, genid2])

Definition at line 96 of file clientmetadatatree_tests.py.

00096 
00097     def test_unsets_is_checkpoint(self):
00098         self.client.start_generation()
00099         genid = self.client.get_generation_id(self.client.tree)
00100         self.client.set_current_generation_is_checkpoint(True)
00101         self.client.set_current_generation_is_checkpoint(False)
00102         self.assertFalse(self.client.get_is_checkpoint(genid))


Member Data Documentation

Definition at line 37 of file clientmetadatatree_tests.py.

Definition at line 44 of file clientmetadatatree_tests.py.

Definition at line 42 of file clientmetadatatree_tests.py.

Definition at line 41 of file clientmetadatatree_tests.py.

Definition at line 35 of file clientmetadatatree_tests.py.

Definition at line 32 of file clientmetadatatree_tests.py.

Definition at line 33 of file clientmetadatatree_tests.py.


The documentation for this class was generated from the following file: