def test_to_hard(self): # two kinds of backslash n to trip up the escaping: line = util.to_checksum_format('filepath/\n/with/\\newline', '939aaaae6098ebdab049b0f3abe7b68c') # Note raw string self.assertEqual( line, r'\939aaaae6098ebdab049b0f3abe7b68c filepath/\n/with/\\newline')
def write(cls, archive_record, type, format, data_initializer, provenance_capture): super().write(archive_record, type, format, data_initializer, provenance_capture) checksums = md5sum_directory(str(archive_record.root)) with (archive_record.root / cls.CHECKSUM_FILE).open('w') as fh: for item in checksums.items(): fh.write(to_checksum_format(*item)) fh.write('\n')
def check_roundtrip(self, filepath, checksum): line = util.to_checksum_format(filepath, checksum) new_fp, new_chks = util.from_checksum_format(line) self.assertEqual(new_fp, filepath) self.assertEqual(new_chks, checksum)
def test_to_simple(self): line = util.to_checksum_format('this/is/a/filepath', 'd9724aeba59d8cea5265f698b2c19684') self.assertEqual( line, 'd9724aeba59d8cea5265f698b2c19684 this/is/a/filepath')