/breezy-debian/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy-debian/trunk

« back to all changes in this revision

Viewing changes to tests/test_import_dsc.py

  • Committer: Jelmer Vernooij
  • Date: 2018-10-10 21:43:37 UTC
  • Revision ID: jelmer@jelmer.uk-20181010214337-ffmg6a8np2ywc67h
Python3 compatibility fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 
85
85
 
86
86
def write_to_file(filename, contents):
87
 
    f = open(filename, 'wb')
88
 
    try:
 
87
    with open(filename, 'wb') as f:
89
88
        f.write(contents)
90
 
    finally:
91
 
        f.close()
92
89
 
93
90
 
94
91
class DistributionBranchTests(BuilddebTestCase):
526
523
        revid3 = self.tree1.commit("three")
527
524
        self.db1.tag_version(version3)
528
525
        up_revid1 = self.up_tree1.commit("upstream one")
529
 
        self.tag_upstream_version(self.db1, version1.upstream_version.decode())
 
526
        self.tag_upstream_version(self.db1, version1.upstream_version)
530
527
        self.up_tree2.pull(self.up_tree1.branch)
531
 
        self.tag_upstream_version(self.db2, version2.upstream_version.decode())
 
528
        self.tag_upstream_version(self.db2, version2.upstream_version)
532
529
        up_revid2 = self.up_tree1.commit("upstream two")
533
 
        self.tag_upstream_version(self.db1, version3.upstream_version.decode())
 
530
        self.tag_upstream_version(self.db1, version3.upstream_version)
534
531
        self.up_tree2.pull(self.up_tree1.branch)
535
 
        self.tag_upstream_version(self.db2, version4.upstream_version.decode())
 
532
        self.tag_upstream_version(self.db2, version4.upstream_version)
536
533
        versions = [version4, version3, version2, version1]
537
534
        # no upstream parent as the lesser branch has already merged it
538
535
        self.assertEqual(self.db2.get_parents_with_upstream(
849
846
        name = "package"
850
847
        basedir = name + "-" + str(version1.upstream_version)
851
848
        os.mkdir(basedir)
852
 
        write_to_file(os.path.join(basedir, "README"), "Hi\n")
853
 
        write_to_file(os.path.join(basedir, "BUGS"), "")
854
 
        write_to_file(os.path.join(basedir, "COPYING"), "")
 
849
        write_to_file(os.path.join(basedir, "README"), b"Hi\n")
 
850
        write_to_file(os.path.join(basedir, "BUGS"), b"")
 
851
        write_to_file(os.path.join(basedir, "COPYING"), b"")
855
852
        self.db1.import_upstream(basedir, "package", version1.upstream_version, {},
856
853
            [(None, None, None)])
857
854
        basedir = name + "-" + str(version2.upstream_version)
858
855
        os.mkdir(basedir)
859
 
        write_to_file(os.path.join(basedir, "README"), "Now even better\n")
860
 
        write_to_file(os.path.join(basedir, "BUGS"), "")
861
 
        write_to_file(os.path.join(basedir, "NEWS"), "")
 
856
        write_to_file(os.path.join(basedir, "README"), b"Now even better\n")
 
857
        write_to_file(os.path.join(basedir, "BUGS"), b"")
 
858
        write_to_file(os.path.join(basedir, "NEWS"), b"")
862
859
        self.db1.import_upstream(basedir, "package", version2.upstream_version,
863
860
                { None: [self.up_tree1.branch.last_revision()] }, [(None, None, None)])
864
861
        tree = self.up_tree1
885
882
        name = "package"
886
883
        basedir = name + "-" + str(version.upstream_version)
887
884
        os.mkdir(basedir)
888
 
        write_to_file(os.path.join(basedir, "README"), "Hi\n")
889
 
        write_to_file(os.path.join(basedir, "BUGS"), "")
 
885
        write_to_file(os.path.join(basedir, "README"), b"Hi\n")
 
886
        write_to_file(os.path.join(basedir, "BUGS"), b"")
890
887
        tar_path = "package_0.1.orig.tar.gz"
891
888
        tf = tarfile.open(tar_path, 'w:gz')
892
889
        try:
913
910
        name = "package"
914
911
        basedir = name + "-" + str(version.upstream_version)
915
912
        os.mkdir(basedir)
916
 
        write_to_file(os.path.join(basedir, "README"), "Hi\n")
917
 
        write_to_file(os.path.join(basedir, "BUGS"), "")
 
913
        write_to_file(os.path.join(basedir, "README"), b"Hi\n")
 
914
        write_to_file(os.path.join(basedir, "BUGS"), b"")
918
915
        tar_path = "package_0.1.orig.tar.bz2"
919
916
        tf = tarfile.open(tar_path, 'w:bz2')
920
917
        try:
942
939
        name = "package"
943
940
        basedir = name + "-" + str(version.upstream_version)
944
941
        os.mkdir(basedir)
945
 
        write_to_file(os.path.join(basedir, "README"), "Hi\n")
946
 
        write_to_file(os.path.join(basedir, "BUGS"), "")
 
942
        write_to_file(os.path.join(basedir, "README"), b"Hi\n")
 
943
        write_to_file(os.path.join(basedir, "BUGS"), b"")
947
944
        # Some versions of tar, including that in Ubuntu lucid and maverick,
948
945
        # but not natty and later, have a bug which prevents them from
949
946
        # autodetecting the compression type of files less than 512 bytes in
950
947
        # length. So, add some extra verbiage to push us just above that
951
948
        # boundary. This matters for lzma, but not gz and bz2, because
952
949
        # pristine-tar has its own decompression support for those.
953
 
        write_to_file(os.path.join(basedir, "LOREM"), 
954
 
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
955
 
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
956
 
                "aliqua.  Ut enim ad minim veniam, quis nostrud exercitation "
957
 
                "ullamco laboris nisi ut aliquip ex ea commodo consequat. "
958
 
                "Duis aute irure dolor in reprehenderit in voluptate velit "
959
 
                "esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
960
 
                "occaecat cupidatat non proident, sunt in culpa qui officia "
961
 
                "deserunt mollit anim id est laborum.")
 
950
        write_to_file(os.path.join(basedir, "LOREM"),
 
951
                b"Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
 
952
                b"sed do eiusmod tempor incididunt ut labore et dolore magna "
 
953
                b"aliqua.  Ut enim ad minim veniam, quis nostrud exercitation "
 
954
                b"ullamco laboris nisi ut aliquip ex ea commodo consequat. "
 
955
                b"Duis aute irure dolor in reprehenderit in voluptate velit "
 
956
                b"esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
 
957
                b"occaecat cupidatat non proident, sunt in culpa qui officia "
 
958
                b"deserunt mollit anim id est laborum.")
962
959
        tar_path = "package_0.1.orig.tar.xz"
963
960
        make_new_upstream_tarball_xz(basedir, tar_path)
964
961
        try: