def test_gnu_checksum_file(self): """Verify a GNU-style checksum file.""" from pygeoprocessing.testing import assert_checksums_equal from pygeoprocessing.testing import checksum_folder sample_folder = tempfile.mkdtemp(dir=self.workspace) DigestEquality.create_sample_folder(sample_folder) checksum_file = os.path.join(self.workspace, 'checksum.md5') checksum_folder(sample_folder, checksum_file, style='GNU') assert_checksums_equal(checksum_file, base_folder=sample_folder)
def test_checksum_all_files_missing(self): """Verify testing checksum from wrong directory fails.""" from pygeoprocessing.testing import assert_checksums_equal from pygeoprocessing.testing import checksum_folder sample_folder = tempfile.mkdtemp(dir=self.workspace) DigestEquality.create_sample_folder(sample_folder) checksum_file = os.path.join(self.workspace, 'checksum.md5') checksum_folder(sample_folder, checksum_file) with self.assertRaises(AssertionError): assert_checksums_equal(checksum_file, self.workspace)
def test_checksum_a_modified_file(self): """Test for when a checksummed file has been modified.""" from pygeoprocessing.testing import assert_checksums_equal from pygeoprocessing.testing import checksum_folder # Create the sample files, checksum the folder, then remove one of the # files. sample_folder = tempfile.mkdtemp(dir=self.workspace) files = DigestEquality.create_sample_folder(sample_folder) checksum_file = os.path.join(self.workspace, 'checksum.md5') checksum_folder(sample_folder, checksum_file, style='GNU') open(files[0], 'a').write('foo!') with self.assertRaises(AssertionError): assert_checksums_equal(checksum_file, sample_folder)
def test_checksum_assertion_in_cwd(self): """Verify testing from CWD if none is provided.""" from pygeoprocessing.testing import assert_checksums_equal from pygeoprocessing.testing import checksum_folder sample_folder = tempfile.mkdtemp(dir=self.workspace) DigestEquality.create_sample_folder(sample_folder) checksum_file = os.path.join(self.workspace, 'checksum.md5') checksum_folder(sample_folder, checksum_file) try: cwd = os.getcwd() os.chdir(sample_folder) assert_checksums_equal(checksum_file) finally: os.chdir(cwd)