/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_transform.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-06-30 10:19:02 UTC
  • mfrom: (6973.7.13 python3-g-real)
  • Revision ID: breezy.the.bot@gmail.com-20180630101902-thpqkbi44kqom06g
Fix more tests.

Merged from https://code.launchpad.net/~jelmer/brz/python3-g/+merge/348134

Show diffs side-by-side

added added

removed removed

Lines of Context:
381
381
        self.assertEqual(len(transform.find_conflicts()), 0)
382
382
        transform.apply()
383
383
        self.assertRaises(ReusingTransform, transform.find_conflicts)
384
 
        self.assertEqual('contents', file(self.wt.abspath('name')).read())
 
384
        with open(self.wt.abspath('name'), 'r') as f:
 
385
            self.assertEqual('contents', f.read())
385
386
        self.assertEqual(self.wt.path2id('name'), 'my_pretties')
386
387
        self.assertIs(self.wt.is_executable('name'), True)
387
388
        self.assertEqual(self.wt.path2id('oz'), 'oz-id')
452
453
        tip_id = transform.new_file('tip', oz_id, b'ozma', 'tip-id')
453
454
        transform.apply()
454
455
        self.assertEqual(self.wt.path2id('name'), 'my_pretties')
455
 
        self.assertEqual('contents', file(self.wt.abspath('name')).read())
 
456
        with open(self.wt.abspath('name'), 'r') as f:
 
457
            self.assertEqual('contents', f.read())
456
458
        transform2, root = self.get_transform()
457
459
        oz_id = transform2.trans_id_tree_path('oz')
458
460
        newtip = transform2.new_file('tip', oz_id, b'other', 'tip-id')
659
661
        self.assertEqual(mangle_tree.final_parent(mfile2), newdir)
660
662
        self.assertEqual(mangle_tree.final_file_id(mfile2), 'mfile2')
661
663
        mangle_tree.apply()
662
 
        self.assertEqual(file(self.wt.abspath('name1')).read(), 'hello2')
663
 
        self.assertEqual(file(self.wt.abspath('name2')).read(), 'hello1')
 
664
        with open(self.wt.abspath('name1'), 'r') as f:
 
665
            self.assertEqual(f.read(), 'hello2')
 
666
        with open(self.wt.abspath('name2'), 'r') as f:
 
667
            self.assertEqual(f.read(), 'hello1')
664
668
        mfile2_path = self.wt.abspath(pathjoin('new_directory', 'mfile2'))
665
669
        self.assertEqual(mangle_tree.final_parent(mfile2), newdir)
666
 
        self.assertEqual(file(mfile2_path).read(), 'later2')
 
670
        with open(mfile2_path, 'r') as f:
 
671
            self.assertEqual(f.read(), 'later2')
667
672
        self.assertEqual(self.wt.id2path(b'mfile2'), 'new_directory/mfile2')
668
673
        self.assertEqual(self.wt.path2id('new_directory/mfile2'), b'mfile2')
669
674
        newfile_path = self.wt.abspath(pathjoin('new_directory', 'newfile'))
670
 
        self.assertEqual(file(newfile_path).read(), 'hello3')
 
675
        with open(newfile_path, 'r') as f:
 
676
            self.assertEqual(f.read(), 'hello3')
671
677
        self.assertEqual(self.wt.path2id('dying_directory'), b'ddir')
672
678
        self.assertIs(self.wt.path2id('dying_directory/dying_file'), None)
673
679
        mfile2_path = self.wt.abspath(pathjoin('new_directory', 'mfile2'))
1020
1026
            osutils.make_readonly(self.wt.abspath('first-dir'))
1021
1027
        elif os.name == "nt":
1022
1028
            # windows filesystems fail on renaming open files
1023
 
            self.addCleanup(file(self.wt.abspath('myfile')).close)
 
1029
            self.addCleanup(open(self.wt.abspath('myfile')).close)
1024
1030
        else:
1025
1031
            self.skipTest("Can't force a permissions error on rename")
1026
1032
        # now transform to rename
1764
1770
        merge_modified = this.wt.merge_modified()
1765
1771
        self.assertSubset(merge_modified, modified)
1766
1772
        self.assertEqual(len(merge_modified), len(modified))
1767
 
        with file(this.wt.abspath(this.wt.id2path('a')), 'wb') as f: f.write('booga')
 
1773
        with open(this.wt.abspath(this.wt.id2path('a')), 'wb') as f: f.write(b'booga')
1768
1774
        modified.pop(0)
1769
1775
        merge_modified = this.wt.merge_modified()
1770
1776
        self.assertSubset(merge_modified, modified)
1886
1892
        os.mkdir('a')
1887
1893
        a = ControlDir.create_standalone_workingtree('a')
1888
1894
        os.mkdir('a/foo')
1889
 
        with file('a/foo/bar', 'wb') as f: f.write('contents')
 
1895
        with open('a/foo/bar', 'wb') as f: f.write(b'contents')
1890
1896
        os.symlink('a/foo/bar', 'a/foo/baz')
1891
1897
        a.add(['foo', 'foo/bar', 'foo/baz'])
1892
1898
        a.commit('initial commit')
1896
1902
        self.addCleanup(basis.unlock)
1897
1903
        build_tree(basis, b)
1898
1904
        self.assertIs(os.path.isdir('b/foo'), True)
1899
 
        self.assertEqual(file('b/foo/bar', 'rb').read(), "contents")
 
1905
        with open('b/foo/bar', 'rb') as f:
 
1906
            self.assertEqual(f.read(), "contents")
1900
1907
        self.assertEqual(os.readlink('b/foo/baz'), 'a/foo/bar')
1901
1908
 
1902
1909
    def test_build_with_references(self):
1922
1929
                          'file.moved', 'file', None, 'new-file')],
1923
1930
                         target.conflicts())
1924
1931
        target2 = self.make_branch_and_tree('target2')
1925
 
        target_file = file('target2/file', 'wb')
1926
 
        try:
1927
 
            source_file = file('source/file', 'rb')
1928
 
            try:
1929
 
                target_file.write(source_file.read())
1930
 
            finally:
1931
 
                source_file.close()
1932
 
        finally:
1933
 
            target_file.close()
 
1932
        with open('target2/file', 'wb') as target_file, \
 
1933
                open('source/file', 'rb') as source_file:
 
1934
            target_file.write(source_file.read())
1934
1935
        build_tree(source.basis_tree(), target2)
1935
1936
        self.assertEqual([], target2.conflicts())
1936
1937
 
2191
2192
            'rot13', {'yes': [rot13filter]}.get)
2192
2193
        os.mkdir(self.test_home_dir + '/.bazaar')
2193
2194
        rules_filename = self.test_home_dir + '/.bazaar/rules'
2194
 
        f = open(rules_filename, 'wb')
2195
 
        f.write('[name %s]\nrot13=yes\n' % (pattern,))
2196
 
        f.close()
 
2195
        with open(rules_filename, 'wb') as f:
 
2196
            f.write(b'[name %s]\nrot13=yes\n' % (pattern,))
2197
2197
        def uninstall_rules():
2198
2198
            os.remove(rules_filename)
2199
2199
            rules.reset_rules()