def test_cathash_files(self):
        """Test the cathash_files() method."""
        for algo in SUPPORTED_ALGORITHMS:
            for filename in self.expected_results.keys():
                hasher = FileHash(algo)
                self.assertEqual(self.expected_results[filename][algo],
                                 hasher.cathash_files([filename]))

            hasher = FileHash(algo)
            # shouldn't matter how you order filenames
            self.assertEqual(
                hasher.cathash_files(['lorem_ipsum.txt', 'lorem_ipsum.zip']),
                hasher.cathash_files(['lorem_ipsum.zip', 'lorem_ipsum.txt']),
            )
            # filenames thmeselves shouldn't matter
            self.assertEqual(
                hasher.cathash_files(['./lorem_ipsum.txt', 'lorem_ipsum.zip']),
                hasher.cathash_files(['lorem_ipsum.txt', 'lorem_ipsum.zip']),
            )
            self.assertEqual(
                hasher.cathash_files(['lorem_ipsum.txt', './lorem_ipsum.zip']),
                hasher.cathash_files(['lorem_ipsum.txt', 'lorem_ipsum.zip']),
            )
            # hash of multiple files should be same as
            # hash of files catted together
            self.assertEqual(
                hasher.cathash_files(['lorem_ipsum.txt', 'lorem_ipsum.zip']),
                self.expected_results['lorem_ipsum_zip+txt.cat' if (
                    self.expected_results['lorem_ipsum.txt'][algo] > self.
                    expected_results['lorem_ipsum.zip'][algo]
                ) else 'lorem_ipsum_txt+zip.cat'][algo])
示例#2
0
    def get_hash(self, build_dir):
        """Compute hash of directory."""
        sha256 = FileHash('sha256')

        build_files = self.get_buildfiles(build_dir)
        return sha256.cathash_files(build_files)