def testIterate(self): """Test writing several records and then reading them back""" self.make_backup_dirs() rp1 = self.ea_test1_rpath.append('e1') rp2 = self.ea_test1_rpath.append('e2') rp3 = self.ea_test1_rpath.append('e3') # Now write records corresponding to above rps into file Globals.rbdir = tempdir man = metadata.PatchDiffMan() writer = man.get_ea_writer('snapshot', 10000) for rp in [self.ea_test1_rpath, rp1, rp2, rp3]: ea = ExtendedAttributes(rp.index) ea.read_from_rp(rp) writer.write_object(ea) writer.close() # Read back records and compare ea_iter = man.get_eas_at_time(10000, None) assert ea_iter, "No extended_attributes.<time> file found" sample_ea_reread = next(ea_iter) # we ignore SELinux extended attributes for comparaison if sample_ea_reread.attr_dict: sample_ea_reread.attr_dict.pop(b'security.selinux', None) assert sample_ea_reread == self.sample_ea, "Re-read EAs %s are different from %s" % \ (sample_ea_reread.attr_dict, self.sample_ea.attr_dict) ea1_reread = next(ea_iter) if ea1_reread.attr_dict: ea1_reread.attr_dict.pop(b'security.selinux', None) assert ea1_reread == self.ea1, "Re-read EAs %s are different from %s" % \ (ea1_reread.attr_dict, self.ea1.attr_dict) ea2_reread = next(ea_iter) if ea2_reread.attr_dict: ea2_reread.attr_dict.pop(b'security.selinux', None) assert ea2_reread == self.ea2, "Re-read EAs %s are different from %s" % \ (ea2_reread.attr_dict, self.ea2.attr_dict) ea3_reread = next(ea_iter) if ea3_reread.attr_dict: ea3_reread.attr_dict.pop(b'security.selinux', None) assert ea3_reread == self.ea3, "Re-read EAs %s are different from %s" % \ (ea3_reread.attr_dict, self.ea3.attr_dict) try: next(ea_iter) except StopIteration: pass else: assert 0, "Expected end to iterator"
def testIterate(self): """Test writing several records and then reading them back""" self.make_backup_dirs() rp1 = self.ea_test1_rpath.append('e1') rp2 = self.ea_test1_rpath.append('e2') rp3 = self.ea_test1_rpath.append('e3') # Now write records corresponding to above rps into file Globals.rbdir = tempdir man = metadata.PatchDiffMan() writer = man._get_ea_writer('snapshot', 10000) for rp in [self.ea_test1_rpath, rp1, rp2, rp3]: ea = ExtendedAttributes(rp.index) ea.read_from_rp(rp) writer.write_object(ea) writer.close() # Read back records and compare ea_iter = man._get_eas_at_time(10000, None) self.assertTrue(ea_iter, "No extended_attributes.<time> file found") sample_ea_reread = next(ea_iter) # we ignore SELinux extended attributes for comparison if sample_ea_reread.attr_dict: sample_ea_reread.attr_dict.pop(b'security.selinux', None) # Check if re-read EAs are different from sample ones self.assertEqual(sample_ea_reread, self.sample_ea) ea1_reread = next(ea_iter) if ea1_reread.attr_dict: ea1_reread.attr_dict.pop(b'security.selinux', None) self.assertEqual(ea1_reread, self.ea1) ea2_reread = next(ea_iter) if ea2_reread.attr_dict: ea2_reread.attr_dict.pop(b'security.selinux', None) self.assertEqual(ea2_reread, self.ea2) ea3_reread = next(ea_iter) if ea3_reread.attr_dict: ea3_reread.attr_dict.pop(b'security.selinux', None) self.assertEqual(ea3_reread, self.ea3) with self.assertRaises(StopIteration, msg="Too many elements in iterator"): next(ea_iter)
def testBasic(self): """Test basic writing and reading of extended attributes""" self.make_temp_out_dirs() new_ea = ExtendedAttributes(()) new_ea.read_from_rp(tempdir) # we ignore SELinux extended attributes for comparaison if new_ea.attr_dict: new_ea.attr_dict.pop(b'security.selinux', None) assert not new_ea.attr_dict, "The attributes of %s should have been empty: %s" % ( tempdir, new_ea.attr_dict) assert not new_ea == self.sample_ea assert new_ea != self.sample_ea assert new_ea == self.empty_ea self.sample_ea.write_to_rp(tempdir) new_ea.read_from_rp(tempdir) if new_ea.attr_dict: new_ea.attr_dict.pop(b'security.selinux', None) assert new_ea.attr_dict == self.sample_ea.attr_dict, \ (new_ea.attr_dict, self.sample_ea.attr_dict) assert new_ea == self.sample_ea
def testBasic(self): """Test basic writing and reading of extended attributes""" self.make_temp_out_dirs() new_ea = ExtendedAttributes(()) new_ea.read_from_rp(tempdir) # we ignore SELinux extended attributes for comparison if new_ea.attr_dict: new_ea.attr_dict.pop(b'security.selinux', None) self.assertFalse( new_ea.attr_dict, "The attributes of {dir} should have been empty: {attr}".format( dir=tempdir, attr=new_ea.attr_dict)) self.assertNotEqual(new_ea, self.sample_ea) self.assertEqual(new_ea, self.empty_ea) self.sample_ea.write_to_rp(tempdir) new_ea.read_from_rp(tempdir) if new_ea.attr_dict: new_ea.attr_dict.pop(b'security.selinux', None) self.assertEqual(new_ea.attr_dict, self.sample_ea.attr_dict) self.assertEqual(new_ea, self.sample_ea)