コード例 #1
0
ファイル: test_Md5sum.py プロジェクト: hem-cfc/genomics
class TestMd5CheckerComputeMd5sms(unittest.TestCase):
    """Tests for the 'compute_md5sums' method of the Md5Checker class

    """
    def setUp(self):
        self.example_dir = ExampleDirLanguages()
        self.example_dir.create_directory()

    def tearDown(self):
        self.example_dir.delete_directory()

    def test_compute_md5dums(self):
        """Md5Checker.compute_md5sums returns correct md5sums

        """
        files = self.example_dir.filelist(include_links=True,full_path=False)
        for f,md5 in Md5Checker.compute_md5sums(self.example_dir.dirn,
                                                links=Md5Checker.FOLLOW_LINKS):
            self.assertTrue(f in files)
            self.assertEqual(md5,self.example_dir.checksum_for_file(f))

    def test_compute_md5dums_ignore_links(self):
        """Md5Checker.compute_md5sums ignores links

        """
        files = self.example_dir.filelist(include_links=False,full_path=False)
        for f,md5 in Md5Checker.compute_md5sums(self.example_dir.dirn,
                                                links=Md5Checker.IGNORE_LINKS):
            self.assertTrue(f in files)
            self.assertEqual(md5,self.example_dir.checksum_for_file(f))
コード例 #2
0
ファイル: test_Md5sum.py プロジェクト: hem-cfc/genomics
class TestMd5CheckerVerifyMd5sms(unittest.TestCase):
    """Tests for the 'verify_md5sums' method of the Md5Checker class

    """
    def setUp(self):
        self.example_dir = ExampleDirLanguages()
        self.example_dir.create_directory()

    def tearDown(self):
        self.example_dir.delete_directory()

    def test_verify_md5sums(self):
        """Md5Checker.verify_md5sums checks 'md5sum'-format file

        """
        # Create MD5sum 'file'
        md5sums = []
        for f in self.example_dir.filelist(full_path=True):
            md5sums.append("%s  %s" % (md5sum(f),f))
        md5sums = '\n'.join(md5sums)
        fp = cStringIO.StringIO(md5sums)
        # Run verification
        files = self.example_dir.filelist(full_path=True)
        self.assertNotEqual(len(files),0)
        for f,status in Md5Checker.verify_md5sums(fp=fp):
            self.assertTrue(f in files,"%s not in %s" % (f,files))
            self.assertEqual(status,Md5Checker.MD5_OK)
            files.remove(f)
        # Check no files were missed
        self.assertEqual(len(files),0)
コード例 #3
0
ファイル: test_Md5sum.py プロジェクト: hem-cfc/genomics
class TestMd5CheckerWalk(unittest.TestCase):
    """Tests for the 'walk' method of the Md5Checker class

    """
    def setUp(self):
        """Build directory with test data
        """
        self.example_dir = ExampleDirLanguages()
        self.dirn = self.example_dir.create_directory()

    def tearDown(self):
        """Remove directory with test data
        """
        self.example_dir.delete_directory()

    def test_walk(self):
        """Md5Checker.walk yields all files
        """
        # Walk the example directory and check all yielded files
        # are in the list of created files
        file_list = self.example_dir.filelist(include_links=True)
        print str(file_list)
        for f in Md5Checker.walk(self.dirn):
            print "Check for %s" % f
            self.assertTrue(f in file_list,"%s not in files or links?" % f)
            file_list.remove(f)
        # Check that no files were missed
        self.assertTrue(len(file_list) == 0,
                        "Some files not yielded: %s" % file_list)

    def test_walk_ignore_links(self):
        """Md5Checker.walk ignores links
        """
        # Walk the example directory and check all yielded files
        # are in the list of created files
        file_list = self.example_dir.filelist(include_links=False)
        for f in Md5Checker.walk(self.dirn,links=Md5Checker.IGNORE_LINKS):
            self.assertTrue(f in file_list,"%s not in files?" % f)
            file_list.remove(f)
        # Check that no files were missed
        self.assertTrue(len(file_list) == 0,
                        "Some files not yielded: %s" % file_list)

    def test_walk_yields_broken_links(self):
        """Md5Checker.walk yields broken links
        """
        # Add broken link
        self.example_dir.add_link("broken.txt","missing.txt")
        # Walk the example directory and check all yielded files
        # are in the list of created files
        file_list = self.example_dir.filelist(include_links=False)
        for f in Md5Checker.walk(self.dirn,links=Md5Checker.IGNORE_LINKS):
            self.assertTrue(f in file_list,"%s not in files?" % f)
            file_list.remove(f)
        # Check that no files were missed
        self.assertTrue(len(file_list) == 0,
                        "Some files not yielded: %s" % file_list)