def test_xattrs_with_no_serialized_value_are_kept(self): dumbattr.set(self.file1, "test1", "1") xattr.set(self.file1, "test2", "2", namespace=xattr.NS_USER) self.assertEqual(self.serialized_metadata(), {'file1': {'test1':'1'}}) self.assertEqual(dumbattr.load(self.file1).copy(), {'test1': '1', 'test2':'2'}) self.assertEqual(self.serialized_metadata(), {'file1': {'test1': '1', 'test2':'2'}})
def test_loading_attr_ensures_all_xattrs_are_set(self): dumbattr.set(self.file1, "file_1", "1") xattr.remove(self.file1, "file_1", namespace=xattr.NS_USER) self.assertEqual(self.all_xattrs(self.file1), {}) self.assertEqual(dumbattr.load(self.file1).copy(), {'file_1':'1'}) self.assertEqual(self.all_xattrs(self.file1), {b'file_1':b'1'})
def test_xattrs_overriden_by_serialized_attrs(self): dumbattr.set(self.file1, "test1", "1") xattr.set(self.file1, "test1", "2", namespace=xattr.NS_USER) self.assertEqual(self.serialized_metadata(), {'file1': {'test1':'1'}}) # load() has the side effect of fixing any discrepancies, just like `fix()` self.assertEqual(dumbattr.load(self.file1).copy(), {'test1': '1'}) self.assertEqual(self.all_xattrs(self.file1), {b'test1': b'1'})
def test_metadata_file_is_removed_when_no_files_have_attrs(self): dumbattr.set(self.file1, "test1", "1") self.assertEqual(self.serialized_metadata(), {'file1': {'test1':'1'}}) dumbattr.remove(self.file1, "test1") self.assertEqual(self.serialized_metadata(), None) assert not os.path.exists(os.path.join(self.base, dumbattr.METADATA_FILENAME))
def test_attr_removal(self): dumbattr.set(self.file1, 'test1', '1') dumbattr.set(self.file1, 'test2', '2') dumbattr.remove(self.file1, 'test1') self.assertEqual(dumbattr.load(self.file1).copy(), {'test2':'2'}) self.assertEqual(self.serialized_metadata(), {'file1':{'test2':'2'}}) dumbattr.remove(self.file1, 'test2') self.assertEqual(self.serialized_metadata(), None)
def test_symlink_attr_removal(self): dumbattr.set(self.link, 'kind', 'link') dumbattr.set(self.link, 'test', '1') dumbattr.remove(self.link, 'test') self.assertEqual(self.serialized_metadata(), { 'link': {'kind': 'link'}, }) dumbattr.remove(self.link, 'kind') self.assertEqual(self.serialized_metadata(), None)
def test_symlink_attrs_are_saved_only_in_metadata(self): dumbattr.set(self.link_target, 'kind', 'target') dumbattr.set(self.link, 'kind', 'link') self.assertEqual(self.serialized_metadata(), { 'link': {'kind': 'link'}, 'link_target': {'kind': 'target'}, }) self.assertEqual(self.all_xattrs(self.link_target, nofollow=True), {b'kind':b'target'}) self.assertEqual(self.all_xattrs(self.link, nofollow=True), {}) self.assertEqual(dumbattr.load(self.link_target).copy(), {'kind':'target'}) self.assertEqual(dumbattr.load(self.link).copy(), {'kind':'link'})
def test_deleting_last_attr_from_file(self): dumbattr.set(self.file1, 'test1', '1') dumbattr.set(self.file2, 'test2', '2') dumbattr.set(self.link, 'test3', '3') dumbattr.remove(self.file1, 'test1') dumbattr.remove(self.link, 'test3') self.assertEqual(self.serialized_metadata(), {'file2':{'test2':'2'}})
def test_adding_attr_to_second_file(self): dumbattr.set(self.file1, "test1", "value1") dumbattr.set(self.file2, "test2", "value2") self.assertEqual(self.all_xattrs(self.file1), {b"test1":b"value1"}) self.assertEqual(self.all_xattrs(self.file2), {b"test2":b"value2"}) self.assertEqual(self.serialized_metadata(), {"file1": {"test1":"value1"}, "file2": {"test2": "value2"}})
def test_adding_multiple_attrs(self): dumbattr.set(self.file1, "test1", "value1") dumbattr.set(self.file1, "test2", "value2") self.assertEqual(self.all_xattrs(self.file1), {b"test1":b"value1", b"test2": b"value2"}) self.assertEqual(self.serialized_metadata(), {"file1": {"test1":"value1", "test2": "value2"}})
def test_adding_attr_to_previously_untouched_dir(self): dumbattr.set(self.file1, "test1", "value1") self.assertEqual(self.all_xattrs(self.file1), {b"test1":b"value1"}) self.assertEqual(self.serialized_metadata(), {"file1": {"test1":"value1"}})
def test_stored_view_returns_dict_when_data_saved(self): dumbattr.set(self.file1, 'test1', '1') dumbattr.set(self.file2, 'test2', '2') meta = dumbattr.stored_view(self.base) self.assertEqual(meta, self.serialized_metadata())