Example #1
0
 def test_file_match_no_dups(self):
     tree = self.make_branch_and_tree('tree')
     rn = RenameMap(tree)
     rn.add_edge_hashes(self.a_lines, 'aid')
     self.build_tree_contents([('tree/a', ''.join(self.a_lines))])
     self.build_tree_contents([('tree/b', ''.join(self.b_lines))])
     self.build_tree_contents([('tree/c', ''.join(self.b_lines))])
     self.assertEqual({'a': 'aid'}, rn.file_match(['a', 'b', 'c']))
Example #2
0
 def test_file_match_no_dups(self):
     tree = self.make_branch_and_tree('tree')
     rn = RenameMap(tree)
     rn.add_edge_hashes(self.a_lines, 'aid')
     self.build_tree_contents([('tree/a', ''.join(self.a_lines))])
     self.build_tree_contents([('tree/b', ''.join(self.b_lines))])
     self.build_tree_contents([('tree/c', ''.join(self.b_lines))])
     self.assertEqual({'a': 'aid'},
                      rn.file_match(['a', 'b', 'c']))
Example #3
0
 def test_add_file_edge_hashes(self):
     tree = self.make_branch_and_tree('tree')
     self.build_tree_contents([('tree/a', ''.join(self.a_lines))])
     tree.add('a', 'a')
     rn = RenameMap(tree)
     rn.add_file_edge_hashes(tree, ['a'])
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('a\n', 'b\n'))])
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('b\n', 'c\n'))])
     self.assertIs(None, rn.edge_hashes.get(myhash(('c\n', 'd\n'))))
Example #4
0
 def test_add_file_edge_hashes(self):
     tree = self.make_branch_and_tree('tree')
     self.build_tree_contents([('tree/a', ''.join(self.a_lines))])
     tree.add('a', 'a')
     rn = RenameMap(tree)
     rn.add_file_edge_hashes(tree, ['a'])
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('a\n', 'b\n'))])
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('b\n', 'c\n'))])
     self.assertIs(None, rn.edge_hashes.get(myhash(('c\n', 'd\n'))))
Example #5
0
 def test_guess_renames_dry_run(self):
     tree = self.make_branch_and_tree('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.build_tree(['tree/file'])
     tree.add('file', 'file-id')
     tree.commit('Added file')
     os.rename('tree/file', 'tree/file2')
     RenameMap.guess_renames(tree, dry_run=True)
     self.assertEqual('file', tree.id2path('file-id'))
Example #6
0
 def test_guess_renames_dry_run(self):
     tree = self.make_branch_and_tree('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.build_tree(['tree/file'])
     tree.add('file', 'file-id')
     tree.commit('Added file')
     os.rename('tree/file', 'tree/file2')
     RenameMap.guess_renames(tree, dry_run=True)
     self.assertEqual('file', tree.id2path('file-id'))
Example #7
0
 def test_match_directories(self):
     tree = self.make_branch_and_tree('tree')
     rn = RenameMap(tree)
     required_parents = rn.get_required_parents({
         'path1': 'a',
         'path2/tr': 'b',
         'path3/path4/path5': 'c',
     })
     self.assertEqual(
         {'path2': set(['b']), 'path3/path4': set(['c']), 'path3': set()},
         required_parents)
Example #8
0
 def test_guess_renames_handles_directories(self):
     tree = self.make_branch_and_tree('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.build_tree(['tree/dir/', 'tree/dir/file'])
     tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
     tree.commit('Added file')
     os.rename('tree/dir', 'tree/dir2')
     RenameMap.guess_renames(tree)
     self.assertEqual('dir2/file', tree.id2path('file-id'))
     self.assertEqual('dir2', tree.id2path('dir-id'))
Example #9
0
 def test_guess_renames_handles_directories(self):
     tree = self.make_branch_and_tree('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.build_tree(['tree/dir/', 'tree/dir/file'])
     tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
     tree.commit('Added file')
     os.rename('tree/dir', 'tree/dir2')
     RenameMap.guess_renames(tree)
     self.assertEqual('dir2/file', tree.id2path('file-id'))
     self.assertEqual('dir2', tree.id2path('dir-id'))
Example #10
0
 def test_guess_renames_preserves_children(self):
     """When a directory has been moved, its children are preserved."""
     tree = self.make_branch_and_tree('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.build_tree_contents([('tree/foo/', ''), ('tree/foo/bar', 'bar'),
                               ('tree/foo/empty', '')])
     tree.add(['foo', 'foo/bar', 'foo/empty'],
              ['foo-id', 'bar-id', 'empty-id'])
     tree.commit('rev1')
     os.rename('tree/foo', 'tree/baz')
     RenameMap.guess_renames(tree)
     self.assertEqual('baz/empty', tree.id2path('empty-id'))
Example #11
0
 def test_match_directories(self):
     tree = self.make_branch_and_tree('tree')
     rn = RenameMap(tree)
     required_parents = rn.get_required_parents({
         'path1': 'a',
         'path2/tr': 'b',
         'path3/path4/path5': 'c',
     })
     self.assertEqual(
         {
             'path2': set(['b']),
             'path3/path4': set(['c']),
             'path3': set()
         }, required_parents)
Example #12
0
 def test_guess_renames_preserves_children(self):
     """When a directory has been moved, its children are preserved."""
     tree = self.make_branch_and_tree('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.build_tree_contents([('tree/foo/', ''),
                               ('tree/foo/bar', 'bar'),
                               ('tree/foo/empty', '')])
     tree.add(['foo', 'foo/bar', 'foo/empty'],
              ['foo-id', 'bar-id', 'empty-id'])
     tree.commit('rev1')
     os.rename('tree/foo', 'tree/baz')
     RenameMap.guess_renames(tree)
     self.assertEqual('baz/empty', tree.id2path('empty-id'))
Example #13
0
 def test_hitcounts(self):
     rn = RenameMap(None)
     rn.add_edge_hashes(self.a_lines, 'a')
     rn.add_edge_hashes(self.b_lines, 'b')
     self.assertEqual({'a': 2.5, 'b': 0.5}, rn.hitcounts(self.a_lines))
     self.assertEqual({'a': 1}, rn.hitcounts(self.a_lines[:-1]))
     self.assertEqual({'b': 2.5, 'a': 0.5}, rn.hitcounts(self.b_lines))
Example #14
0
 def test_find_directory_renames(self):
     tree = self.make_branch_and_tree('tree')
     rn = RenameMap(tree)
     matches = {
         'path1': 'a',
         'path3/path4/path5': 'c',
     }
     required_parents = {
         'path2': set(['b']),
         'path3/path4': set(['c']),
         'path3': set([])}
     missing_parents = {
         'path2-id': set(['b']),
         'path4-id': set(['c']),
         'path3-id': set(['path4-id'])}
     matches = rn.match_parents(required_parents, missing_parents)
     self.assertEqual({'path3/path4': 'path4-id', 'path2': 'path2-id'},
                      matches)
Example #15
0
 def test_hitcounts(self):
     rn = RenameMap(None)
     rn.add_edge_hashes(self.a_lines, 'a')
     rn.add_edge_hashes(self.b_lines, 'b')
     self.assertEqual({'a': 2.5, 'b': 0.5}, rn.hitcounts(self.a_lines))
     self.assertEqual({'a': 1}, rn.hitcounts(self.a_lines[:-1]))
     self.assertEqual({'b': 2.5, 'a': 0.5}, rn.hitcounts(self.b_lines))
Example #16
0
 def test_find_directory_renames(self):
     tree = self.make_branch_and_tree('tree')
     rn = RenameMap(tree)
     matches = {
         'path1': 'a',
         'path3/path4/path5': 'c',
     }
     required_parents = {
         'path2': set(['b']),
         'path3/path4': set(['c']),
         'path3': set([])
     }
     missing_parents = {
         'path2-id': set(['b']),
         'path4-id': set(['c']),
         'path3-id': set(['path4-id'])
     }
     matches = rn.match_parents(required_parents, missing_parents)
     self.assertEqual({
         'path3/path4': 'path4-id',
         'path2': 'path2-id'
     }, matches)
Example #17
0
 def test_add_edge_hashes(self):
     rn = RenameMap(None)
     rn.add_edge_hashes(self.a_lines, 'a')
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('a\n', 'b\n'))])
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('b\n', 'c\n'))])
     self.assertIs(None, rn.edge_hashes.get(myhash(('c\n', 'd\n'))))
Example #18
0
 def test_add_edge_hashes(self):
     rn = RenameMap(None)
     rn.add_edge_hashes(self.a_lines, 'a')
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('a\n', 'b\n'))])
     self.assertEqual(set(['a']), rn.edge_hashes[myhash(('b\n', 'c\n'))])
     self.assertIs(None, rn.edge_hashes.get(myhash(('c\n', 'd\n'))))