def test_old_make_match_re(self):
        """
        Test utility for making matched file name regexes.

        ###################################################
        THIS TESTS THE OBSOLETE LOCAL VERSION OF makeExRE()
        ###################################################

        """
        match_re = MerkleDoc.make_match_re(None)
        self.assertEqual(None, match_re)

        matches = []
        matches.append('^foo')
        matches.append('bar$')
        matches.append('^junk*')
        match_re = MerkleDoc.make_match_re(matches)
        self._expected_matches(match_re, ['foo', 'foolish', 'roobar', 'junky'])
        self._expected_match_failures(match_re, [' foo', 'roobarf', 'myjunk'])

        matches = [r'\.tgz$']
        match_re = MerkleDoc.make_match_re(matches)
        self._expected_matches(match_re, ['junk.tgz', 'notSoFoolish.tgz'])
        self._expected_match_failures(match_re,
                                      ['junk.tar.gz', 'foolish.tar.gz'])

        matches = [r'\.tgz$', r'\.tar\.gz$']
        match_re = MerkleDoc.make_match_re(matches)
        self._expected_matches(
            match_re,
            ['junk.tgz', 'notSoFoolish.tgz', 'junk.tar.gz', 'ohHello.tar.gz'])
        self._expected_match_failures(match_re, ['junk.gz', 'foolish.tar'])
    def test_old_make_ex_re(self):
        """
        Test utility for making excluded file name regexes.

        ###################################################
        THIS TESTS THE OBSOLETE LOCAL VERSION OF makeExRE()
        ###################################################

        """
        ex_re = MerkleDoc.make_ex_re(None)
        self.assertTrue(ex_re is not None)
        self._expected_exclusions(ex_re)

        # should not be present
        self.assertTrue(ex_re.search('bar') is None)
        self.assertTrue(ex_re.search('foo') is None)

        exc = []
        exc.append('^foo')
        exc.append('bar$')
        exc.append('^junk*')
        ex_re = MerkleDoc.make_ex_re(exc)
        self._expected_exclusions(ex_re)

        self.assertTrue(ex_re.search('foobarf'))
        self.assertTrue(ex_re.search(' foobarf') is None)
        self.assertFalse(ex_re.search(' foobarf'))

        # bear in mind that match must be at the beginning
        self.assertFalse(ex_re.match('ohMybar'))
        self.assertTrue(ex_re.search('ohMybar'))

        self.assertFalse(ex_re.match('ohMybarf'))
        self.assertTrue(ex_re.search('junky'))
        self.assertFalse(ex_re.match(' junk'))
    def test_old_make_ex_re(self):
        """
        Test utility for making excluded file name regexes.

        ###################################################
        THIS TESTS THE OBSOLETE LOCAL VERSION OF makeExRE()
        ###################################################

        """
        ex_re = MerkleDoc.make_ex_re(None)
        self.assertTrue(ex_re is not None)
        self._expected_exclusions(ex_re)

        # should not be present
        self.assertTrue(ex_re.search('bar') is None)
        self.assertTrue(ex_re.search('foo') is None)

        exc = []
        exc.append('^foo')
        exc.append('bar$')
        exc.append('^junk*')
        ex_re = MerkleDoc.make_ex_re(exc)
        self._expected_exclusions(ex_re)

        self.assertTrue(ex_re.search('foobarf'))
        self.assertTrue(ex_re.search(' foobarf') is None)
        self.assertFalse(ex_re.search(' foobarf'))

        # bear in mind that match must be at the beginning
        self.assertFalse(ex_re.match('ohMybar'))
        self.assertTrue(ex_re.search('ohMybar'))

        self.assertFalse(ex_re.match('ohMybarf'))
        self.assertTrue(ex_re.search('junky'))
        self.assertFalse(ex_re.match(' junk'))
Exemple #4
0
    def test_bound_flat_dirs(self):
        """test directory is single level, with four data files"""

        dir_name1, dir_path1, dir_name2, dir_path2 = \
            self.make_two_test_directories(ONE, FOUR)
        doc1 = MerkleDoc.create_from_file_system(dir_path1)
        # pylint: disable=no-member
        tree1 = doc1.tree
        # XXX This succeeds BUT pylint doesn't get this right: it sees
        # doc1.tree as a function
        self.assertTrue(isinstance(tree1, MerkleTree))

        # pylint: disable=no-member
        self.assertEqual(dir_name1, tree1.name)
        self.assertTrue(doc1.bound)
        self.assertEqual(("tmp/%s" % dir_name1), dir_path1)
        # pylint: disable=no-member
        nodes1 = tree1.nodes
        self.assertTrue(nodes1 is not None)
        self.assertEqual(FOUR, len(nodes1))
        self.verify_tree_sha256(tree1, dir_path1)

        doc2 = MerkleDoc.create_from_file_system(dir_path2)
        tree2 = doc2.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name2, tree2.name)
        self.assertTrue(doc2.bound)
        self.assertEqual(("tmp/%s" % dir_name2), dir_path2)
        # pylint: disable=no-member
        nodes2 = tree2.nodes
        self.assertTrue(nodes2 is not None)
        self.assertEqual(FOUR, len(nodes2))
        self.verify_tree_sha256(tree2, dir_path2)

        # pylint: disable=no-member
        self.assertTrue(tree1.equal(tree1))
        # pylint: disable=no-member
        self.assertFalse(tree1.equal(tree2))
        # pylint: disable=no-member
        self.assertFalse(tree1.equal(None))

        doc1_str = doc1.to_string()
        doc1_rebuilt = MerkleDoc.create_from_serialization(doc1_str)
        self.assertTrue(doc1.equal(doc1_rebuilt))  # MANGO
Exemple #5
0
    def test_bound_needle_dirs(self):
        """test directories four deep with one data file at the lowest level"""
        (dir_name1, dir_path1, dir_name2, dir_path2) =\
            self.make_two_test_directories(FOUR, ONE)
        doc1 = MerkleDoc.create_from_file_system(dir_path1)
        tree1 = doc1.tree
        # XXX This succeeds BUT pylint doesn't get this right: it sees
        # doc1.tree as a function
        self.assertTrue(isinstance(tree1, MerkleTree))

        # pylint: disable=no-member
        self.assertEqual(dir_name1, tree1.name)
        self.assertTrue(doc1.bound)
        self.assertEqual(("tmp/%s" % dir_name1), dir_path1)
        # pylint: disable=no-member
        nodes1 = tree1.nodes
        self.assertTrue(nodes1 is not None)
        self.assertEqual(ONE, len(nodes1))
        self.verify_tree_sha256(tree1, dir_path1)

        doc2 = MerkleDoc.create_from_file_system(dir_path2)
        tree2 = doc2.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name2, tree2.name)
        self.assertTrue(doc2.bound)
        self.assertEqual(("tmp/%s" % dir_name2), dir_path2)
        # pylint: disable=no-member
        nodes2 = tree2.nodes
        self.assertTrue(nodes2 is not None)
        self.assertEqual(ONE, len(nodes2))
        self.verify_tree_sha256(tree2, dir_path2)

        self.assertTrue(doc1.equal(doc1))
        self.assertFalse(doc1.equal(doc2))

        doc1_str = doc1.to_string()
        doc1_rebuilt = MerkleDoc.create_from_serialization(doc1_str)
#       # DEBUG
#       print "needle doc:\n" + doc1Str
#       print "rebuilt needle doc:\n" + doc1Rebuilt.toString()
#       # END
        self.assertTrue(doc1.equal(doc1_rebuilt))       # FOO
Exemple #6
0
    def test_bound_flat_dirs(self):
        """test directory is single level, with four data files"""

        dir_name1, dir_path1, dir_name2, dir_path2 = \
            self.make_two_test_directories(ONE, FOUR)
        doc1 = MerkleDoc.create_from_file_system(dir_path1)
        # pylint: disable=no-member
        tree1 = doc1.tree
        self.assertTrue(isinstance(tree1, MerkleTree))

        # pylint: disable=no-member
        self.assertEqual(dir_name1, tree1.name)
        self.assertTrue(doc1.bound)
        self.assertEqual(("tmp/%s" % dir_name1), dir_path1)
        # pylint: disable=no-member
        nodes1 = tree1.nodes
        self.assertTrue(nodes1 is not None)
        self.assertEqual(FOUR, len(nodes1))
        self.verify_tree_sha256(tree1, dir_path1)

        doc2 = MerkleDoc.create_from_file_system(dir_path2)
        tree2 = doc2.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name2, tree2.name)
        self.assertTrue(doc2.bound)
        self.assertEqual(("tmp/%s" % dir_name2), dir_path2)
        # pylint: disable=no-member
        nodes2 = tree2.nodes
        self.assertTrue(nodes2 is not None)
        self.assertEqual(FOUR, len(nodes2))
        self.verify_tree_sha256(tree2, dir_path2)

        # pylint: disable=no-member
        self.assertTrue(tree1 == tree1)
        # pylint: disable=no-member
        self.assertFalse(tree1 == tree2)
        # pylint: disable=no-member
        self.assertFalse(tree1 is None)

        doc1_str = doc1.to_string()
        doc1_rebuilt = MerkleDoc.create_from_serialization(doc1_str)
        self.assertTrue(doc1 == doc1_rebuilt)
Exemple #7
0
    def do_test_bound_flat_dirs(self, hashtype):
        """ Test two flat directories with the specified hash type. """

        (dir_name1, dir_path1, dir_name2, dir_path2) =\
            self.make_two_test_directories(ONE, FOUR)

        doc1 = MerkleDoc.create_from_file_system(dir_path1, hashtype)
        tree1 = doc1.tree
        self.assertTrue(isinstance(tree1, MerkleTree))
        # pylint: disable=no-member
        self.assertEqual(dir_name1, tree1.name)
        self.assertTrue(doc1.bound)
        self.assertEqual(("tmp/%s" % dir_name1), dir_path1)
        # pylint: disable=no-member
        nodes1 = tree1.nodes
        self.assertTrue(nodes1 is not None)
        self.assertEqual(FOUR, len(nodes1))
        self.verify_tree_hash(tree1, dir_path1, hashtype)

        doc2 = MerkleDoc.create_from_file_system(dir_path2, hashtype)
        tree2 = doc2.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name2, tree2.name)
        self.assertTrue(doc2.bound)
        self.assertEqual(("tmp/%s" % dir_name2), dir_path2)
        # pylint: disable=no-member
        nodes2 = tree2.nodes
        self.assertTrue(nodes2 is not None)
        self.assertEqual(FOUR, len(nodes2))
        self.verify_tree_hash(tree2, dir_path2, hashtype)

        self.assertEqual(tree1, tree1)
        self.assertFalse(tree1 == tree2)
        self.assertFalse(tree1 is None)

        doc1_str = doc1.to_string()
        doc1_rebuilt = MerkleDoc.create_from_serialization(doc1_str, hashtype)
        # DEBUG
        # print("flat doc:\n" + doc1Str)
        # print("rebuilt flat doc:\n" + doc1Rebuilt.toString())
        # END
        self.assertTrue(doc1 == doc1_rebuilt)
Exemple #8
0
    def test_bound_needle_dirs(self):
        """test directories four deep with one data file at the lowest level"""
        (dir_name1, dir_path1, dir_name2, dir_path2) =\
            self.make_two_test_directories(FOUR, ONE)
        doc1 = MerkleDoc.create_from_file_system(dir_path1)
        tree1 = doc1.tree
        self.assertTrue(isinstance(tree1, MerkleTree))

        # pylint: disable=no-member
        self.assertEqual(dir_name1, tree1.name)
        self.assertTrue(doc1.bound)
        self.assertEqual(("tmp/%s" % dir_name1), dir_path1)
        # pylint: disable=no-member
        nodes1 = tree1.nodes
        self.assertTrue(nodes1 is not None)
        self.assertEqual(ONE, len(nodes1))
        self.verify_tree_sha256(tree1, dir_path1)

        doc2 = MerkleDoc.create_from_file_system(dir_path2)
        tree2 = doc2.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name2, tree2.name)
        self.assertTrue(doc2.bound)
        self.assertEqual(("tmp/%s" % dir_name2), dir_path2)
        # pylint: disable=no-member
        nodes2 = tree2.nodes
        self.assertTrue(nodes2 is not None)
        self.assertEqual(ONE, len(nodes2))
        self.verify_tree_sha256(tree2, dir_path2)

        self.assertTrue(doc1 == doc1)
        self.assertFalse(doc1 == doc2)

        doc1_str = doc1.to_string()
        doc1_rebuilt = MerkleDoc.create_from_serialization(doc1_str)
#       # DEBUG
#       print "needle doc:\n" + doc1Str
#       print "rebuilt needle doc:\n" + doc1Rebuilt.toString()
#       # END
        self.assertTrue(doc1 == doc1_rebuilt)       # FOO
Exemple #9
0
    def do_test_bound_needle_dirs(self, hashtype):
        """ Run tests on two deeper directories. """
        check_hashtype(hashtype)
        (dir_name1, dir_path1, dir_name2, dir_path2) =\
            self.make_two_test_directories(FOUR, ONE)
        doc1 = MerkleDoc.create_from_file_system(dir_path1, hashtype)
        tree1 = doc1.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name1, tree1.name)
        self.assertTrue(doc1.bound)
        self.assertEqual(("tmp/%s" % dir_name1), dir_path1)
        # pylint: disable=no-member
        nodes1 = tree1.nodes
        self.assertTrue(nodes1 is not None)
        self.assertEqual(ONE, len(nodes1))
        self.verify_tree_hash(tree1, dir_path1, hashtype)

        doc2 = MerkleDoc.create_from_file_system(dir_path2, hashtype)
        tree2 = doc2.tree
        # pylint: disable=no-member
        self.assertEqual(dir_name2, tree2.name)
        self.assertTrue(doc2.bound)
        self.assertEqual(("tmp/%s" % dir_name2), dir_path2)
        # pylint: disable=no-member
        nodes2 = tree2.nodes
        self.assertTrue(nodes2 is not None)
        self.assertEqual(ONE, len(nodes2))
        self.verify_tree_hash(tree2, dir_path2, hashtype)

        self.assertTrue(doc1 == doc1)
        self.assertFalse(doc1 == doc2)

        doc1_str = doc1.to_string()
        doc1_rebuilt = MerkleDoc.create_from_serialization(doc1_str, hashtype)
#       # DEBUG
#       print "needle doc:\n" + doc1Str
#       print "rebuilt needle doc:\n" + doc1Rebuilt.toString()
#       # END
        self.assertTrue(doc1 == doc1_rebuilt)
    def test_old_make_match_re(self):
        """
        Test utility for making matched file name regexes.

        ###################################################
        THIS TESTS THE OBSOLETE LOCAL VERSION OF makeExRE()
        ###################################################

        """
        match_re = MerkleDoc.make_match_re(None)
        self.assertEqual(None, match_re)

        matches = []
        matches.append('^foo')
        matches.append('bar$')
        matches.append('^junk*')
        match_re = MerkleDoc.make_match_re(matches)
        self._expected_matches(
            match_re, ['foo', 'foolish', 'roobar', 'junky'])
        self._expected_match_failures(
            match_re, [' foo', 'roobarf', 'myjunk'])

        matches = [r'\.tgz$']
        match_re = MerkleDoc.make_match_re(matches)
        self._expected_matches(
            match_re, ['junk.tgz', 'notSoFoolish.tgz'])
        self._expected_match_failures(
            match_re, ['junk.tar.gz', 'foolish.tar.gz'])

        matches = [r'\.tgz$', r'\.tar\.gz$']
        match_re = MerkleDoc.make_match_re(matches)
        self._expected_matches(
            match_re, ['junk.tgz', 'notSoFoolish.tgz',
                       'junk.tar.gz', 'ohHello.tar.gz'])
        self._expected_match_failures(
            match_re, ['junk.gz', 'foolish.tar'])