def test_file_entry_as_fields(): filename = os.path.join(temp_dir, '0') entry = FileEntry(filename, "data/{}/{}".format(sha1sum('0'), sha1sum("This is content number 0"))) stat_info = StatInfo.for_file(filename) expected = (filename, "data/{}/{}".format(sha1sum('0'), sha1sum("This is content number 0"))) + stat_info assert_really_equal(expected, entry.as_fields())
def test_file_entry_equality(): a = FileEntry(os.path.join(temp_dir, '0'), "data/54231/12345") b = FileEntry(os.path.join(temp_dir, '0'), "data/54231/12345") c = FileEntry(os.path.join(temp_dir, '1'), "data/67890/09876") assert_really_equal(a, b) assert_really_not_equal(a, c) assert_equal(NotImplemented, a.__eq__(1)) assert_equal(NotImplemented, a.__ne__(1))
def test_file_entry_from_fields_wrong_fields(): filename = os.path.join(temp_dir, '0') with assert_raises(TypeError): fields = (filename, "12345", "data/object_id", 12345) FileEntry.from_fields(*fields) with assert_raises(TypeError): fields = (filename, "hi") FileEntry.from_fields(*fields)
def test_file_entry_checksum(): a = FileEntry(os.path.join(temp_dir, '0'), "data/54231/12345") b = FileEntry(os.path.join(temp_dir, '0'), "data/54231/67890") assert_true(a.checksum_differs(b)) assert_true(b.checksum_differs(a))