Ejemplo n.º 1
0
 def setUp(self):
     """Build directory with test data
     """
     self.example_dir = ExampleDirSpiders()
     self.wd = self.example_dir.create_directory()
 def setUp(self):
     """Build directory with test data
     """
     self.example_dir = ExampleDirSpiders()
     self.wd = self.example_dir.create_directory()
Ejemplo n.º 3
0
class TestMd5CheckerMd5cmpFiles(unittest.TestCase):
    """Tests for the 'md5cmp_files' method of the Md5Checker class

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

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

    def test_cmp_identical_files(self):
        """Md5Checker.md5cmp_files compare identical files
        """
        self.assertEqual(
            Md5Checker.MD5_OK,
            Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                    self.example_dir.path('spider2.txt')))
        self.assertEqual(
            Md5Checker.MD5_OK,
            Md5Checker.md5cmp_files(self.example_dir.path('spider2.txt'),
                                    self.example_dir.path('spider.txt')))

    def test_cmp_different_files(self):
        """Md5Checker.md5cmp_files compare different files
        """
        self.assertEqual(
            Md5Checker.MD5_FAILED,
            Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                    self.example_dir.path('fly.txt')))
        self.assertEqual(
            Md5Checker.MD5_FAILED,
            Md5Checker.md5cmp_files(self.example_dir.path('fly.txt'),
                                    self.example_dir.path('spider.txt')))

    def test_cmp_missing_reference(self):
        """Md5Checker.md5cmp_files with missing reference file
        """
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('missing.txt'),
                                    self.example_dir.path('spider.txt')))

    def test_cmp_missing_target(self):
        """Md5Checker.md5cmp_files with missing target file
        """
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                    self.example_dir.path('missing.txt')))

    def test_cmp_file_and_link(self):
        """Md5Checker.md5cmp_files with a file against a symlink
        """
        self.assertEqual(
            Md5Checker.MD5_OK,
            Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                    self.example_dir.path('itsy-bitsy.txt')))
        self.assertEqual(
            Md5Checker.MD5_OK,
            Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy.txt'),
                                    self.example_dir.path('spider.txt')))
        self.assertEqual(
            Md5Checker.MD5_FAILED,
            Md5Checker.md5cmp_files(self.example_dir.path('fly.txt'),
                                    self.example_dir.path('itsy-bitsy.txt')))
        self.assertEqual(
            Md5Checker.MD5_FAILED,
            Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy.txt'),
                                    self.example_dir.path('fly.txt')))

    def test_cmp_identical_links(self):
        """Md5Checker.md5cmp_files with symlinks pointing to identical files
        """
        self.assertEqual(
            Md5Checker.MD5_OK,
            Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy.txt'),
                                    self.example_dir.path('itsy-bitsy2.txt')))
        self.assertEqual(
            Md5Checker.MD5_OK,
            Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy2.txt'),
                                    self.example_dir.path('itsy-bitsy.txt')))

    def test_cmp_broken_link(self):
        """Md5Checker.md5cmp_files with a broken symlink
        """
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                    self.example_dir.path('broken.txt')))
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('broken.txt'),
                                    self.example_dir.path('spider.txt')))

    def test_cmp_identical_broken_links(self):
        """Md5Checker.md5cmp_files with identical broken links
        """
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('broken.txt'),
                                    self.example_dir.path('broken2.txt')))
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('broken2.txt'),
                                    self.example_dir.path('broken.txt')))

    def test_cmp_file_and_directory(self):
        """Md5Checker.md5cmp_files when one 'file' is a directory
        """
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                    self.example_dir.dirn))
        self.assertEqual(
            Md5Checker.MD5_ERROR,
            Md5Checker.md5cmp_files(self.example_dir.dirn,
                                    self.example_dir.path('spider.txt')))
class TestMd5CheckerMd5cmpFiles(unittest.TestCase):
    """Tests for the 'md5cmp_files' method of the Md5Checker class

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

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

    def test_cmp_identical_files(self):
        """Md5Checker.md5cmp_files compare identical files
        """
        self.assertEqual(Md5Checker.MD5_OK,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                                 self.example_dir.path('spider2.txt')))
        self.assertEqual(Md5Checker.MD5_OK,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider2.txt'),
                                                 self.example_dir.path('spider.txt')))

    def test_cmp_different_files(self):
        """Md5Checker.md5cmp_files compare different files
        """
        self.assertEqual(Md5Checker.MD5_FAILED,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                                 self.example_dir.path('fly.txt')))
        self.assertEqual(Md5Checker.MD5_FAILED,
                         Md5Checker.md5cmp_files(self.example_dir.path('fly.txt'),
                                                 self.example_dir.path('spider.txt')))

    def test_cmp_missing_reference(self):
        """Md5Checker.md5cmp_files with missing reference file
        """
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('missing.txt'),
                                                 self.example_dir.path('spider.txt')))

    def test_cmp_missing_target(self):
        """Md5Checker.md5cmp_files with missing target file
        """
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                                 self.example_dir.path('missing.txt')))

    def test_cmp_file_and_link(self):
        """Md5Checker.md5cmp_files with a file against a symlink
        """
        self.assertEqual(Md5Checker.MD5_OK,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                                 self.example_dir.path('itsy-bitsy.txt')))
        self.assertEqual(Md5Checker.MD5_OK,
                         Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy.txt'),
                                                 self.example_dir.path('spider.txt')))
        self.assertEqual(Md5Checker.MD5_FAILED,
                         Md5Checker.md5cmp_files(self.example_dir.path('fly.txt'),
                                                 self.example_dir.path('itsy-bitsy.txt')))
        self.assertEqual(Md5Checker.MD5_FAILED,
                         Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy.txt'),
                                                 self.example_dir.path('fly.txt')))

    def test_cmp_identical_links(self):
        """Md5Checker.md5cmp_files with symlinks pointing to identical files
        """
        self.assertEqual(Md5Checker.MD5_OK,
                         Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy.txt'),
                                                 self.example_dir.path('itsy-bitsy2.txt')))
        self.assertEqual(Md5Checker.MD5_OK,
                         Md5Checker.md5cmp_files(self.example_dir.path('itsy-bitsy2.txt'),
                                                 self.example_dir.path('itsy-bitsy.txt')))

    def test_cmp_broken_link(self):
        """Md5Checker.md5cmp_files with a broken symlink
        """
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                                 self.example_dir.path('broken.txt')))
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('broken.txt'),
                                                 self.example_dir.path('spider.txt')))        

    def test_cmp_identical_broken_links(self):
        """Md5Checker.md5cmp_files with identical broken links
        """
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('broken.txt'),
                                                 self.example_dir.path('broken2.txt')))
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('broken2.txt'),
                                                 self.example_dir.path('broken.txt')))        

    def test_cmp_file_and_directory(self):
        """Md5Checker.md5cmp_files when one 'file' is a directory
        """
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.path('spider.txt'),
                                                 self.example_dir.dirn))
        self.assertEqual(Md5Checker.MD5_ERROR,
                         Md5Checker.md5cmp_files(self.example_dir.dirn,
                                                 self.example_dir.path('spider.txt')))