Example #1
0
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(u"%s  %s" % (md5sum(f), f))
        md5sums = '\n'.join(md5sums)
        fp = io.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)
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)
Example #3
0
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)
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)
Example #5
0
class TestYieldFilepairs(unittest.TestCase):
    def setUp(self):
        # Create example directory structure which
        # includes files and links
        self.d = ExampleDirLanguages()
        self.d.create_directory()
    def tearDown(self):
        # Delete example directory structure
        self.d.delete_directory()
    def test_yield_filepairs(self):
        """yield_filepairs returns correct set of files and links
        """
        # Get all files, links and directories in the example directory
        expected = self.d.filelist(include_links=True,include_dirs=True)
        # Remove any (non-link) directories from the expected list
        expected = filter(lambda x: os.path.islink(x) or not os.path.isdir(x),
                          expected)
        print "Expected = %s" % expected
        # Get all file pairs from the example dir and a
        # dummy target directory name
        for pair in yield_filepairs(self.d.dirn,'/dummy/dir'):
            p1,p2 = pair
            self.assertTrue(p1 in expected,"%s not expected" % p1)
            # Remove from the list
            expected.remove(p1)
            # Check target file is as expected
            p2_expected = os.path.join('/dummy/dir',
                                       os.path.relpath(p1,self.d.dirn))
            self.assertEqual(p2,p2_expected,
                             "Expected '%s', got '%s'" % (p2,p2_expected))
        # List should be empty at the end
        self.assertEqual(len(expected),0,
                         "Some paths not returned: %s" % expected)
Example #6
0
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_md5sums_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))

    def test_compute_md5sums_handle_broken_links(self):
        """Md5Checker.compute_md5sums handles broken links

        """
        # Add a broken link
        self.example_dir.add_link("broken", "missing.txt")
        # Get file list including links
        files = self.example_dir.filelist(include_links=True, full_path=False)
        # Check checksums
        for f, md5 in Md5Checker.compute_md5sums(self.example_dir.dirn):
            self.assertTrue(f in files, "%s doesn't appear in file list?" % f)
            self.assertEqual(md5, self.example_dir.checksum_for_file(f))
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_md5sums_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))

    def test_compute_md5sums_handle_broken_links(self):
        """Md5Checker.compute_md5sums handles broken links

        """
        # Add a broken link
        self.example_dir.add_link("broken","missing.txt")
        # Get file list including links
        files = self.example_dir.filelist(include_links=True,full_path=False)
        # Check checksums
        for f,md5 in Md5Checker.compute_md5sums(self.example_dir.dirn):
            self.assertTrue(f in files,"%s doesn't appear in file list?" % f)
            self.assertEqual(md5,self.example_dir.checksum_for_file(f))