/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_util.py

  • Committer: Jelmer Vernooij
  • Date: 2020-01-20 02:18:12 UTC
  • Revision ID: jelmer@jelmer.uk-20200120021812-sdrjkeq0cf7tn7yj
Don't follow symlinks when exporting directories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
        self.assertPathExists('a/d/e')
111
111
        self.assertPathExists('a/f')
112
112
 
 
113
    def test_recursive_copy_symlink(self):
 
114
        os.mkdir('a')
 
115
        os.symlink('c', 'a/link')
 
116
        os.mkdir('b')
 
117
        recursive_copy('a', 'b')
 
118
        self.assertPathExists('b')
 
119
        self.assertPathExists('b/link')
 
120
        self.assertEqual('c', os.readlink('b/link'))
 
121
 
113
122
 
114
123
class SafeDecodeTests(TestCase):
115
124
 
193
202
        tree = self.make_branch_and_tree('.')
194
203
        self.write_changelog('changelog')
195
204
        tree.add(['changelog'])
196
 
        self.assertRaises(MissingChangelogError, find_changelog, tree, merge=False)
 
205
        self.assertRaises(
 
206
            MissingChangelogError, find_changelog, tree, merge=False)
197
207
 
198
208
    def test_find_changelog_nochangelog(self):
199
209
        tree = self.make_branch_and_tree('.')
200
210
        self.write_changelog('changelog')
201
 
        self.assertRaises(MissingChangelogError, find_changelog, tree, merge=False)
 
211
        self.assertRaises(
 
212
            MissingChangelogError, find_changelog, tree, merge=False)
202
213
 
203
214
    def test_find_changelog_nochangelog_merge(self):
204
215
        tree = self.make_branch_and_tree('.')
205
 
        self.assertRaises(MissingChangelogError, find_changelog, tree, merge=True)
 
216
        self.assertRaises(
 
217
            MissingChangelogError, find_changelog, tree, merge=True)
206
218
 
207
219
    def test_find_changelog_symlink(self):
208
220
        """When there was a symlink debian -> . then the code used to break"""
616
628
    def test_get_commit_info_none(self):
617
629
        wt = self.make_branch_and_tree(".")
618
630
        changelog = Changelog()
619
 
        message, authors, thanks, bugs = \
620
 
                get_commit_info_from_changelog(changelog, wt.branch,
621
 
                        _lplib=MockLaunchpad())
 
631
        message, authors, thanks, bugs = get_commit_info_from_changelog(
 
632
            changelog, wt.branch, _lplib=MockLaunchpad())
622
633
        self.assertEqual(None, message)
623
634
        self.assertEqual([], authors)
624
635
        self.assertEqual([], thanks)
631
642
                   "  * Second change, thanks to B. Hacker"]
632
643
        author = "J. Maintainer <maint@example.com"
633
644
        changelog.new_block(changes=changes, author=author)
634
 
        message, authors, thanks, bugs = \
635
 
                get_commit_info_from_changelog(changelog, wt.branch,
636
 
                        _lplib=MockLaunchpad())
 
645
        message, authors, thanks, bugs = get_commit_info_from_changelog(
 
646
            changelog, wt.branch, _lplib=MockLaunchpad())
637
647
        self.assertEqual("\n".join(strip_changelog_message(changes)), message)
638
648
        self.assertEqual([author]+find_extra_authors(changes), authors)
639
649
        self.assertEqual(text_type, type(authors[0]))
640
650
        self.assertEqual(find_thanks(changes), thanks)
641
 
        self.assertEqual(find_bugs_fixed(changes, wt.branch,
642
 
                    _lplib=MockLaunchpad()), bugs)
 
651
        self.assertEqual(find_bugs_fixed(
 
652
            changes, wt.branch, _lplib=MockLaunchpad()), bugs)
643
653
 
644
654
    def assertUnicodeCommitInfo(self, changes):
645
655
        wt = self.make_branch_and_tree(".")
646
656
        changelog = Changelog()
647
657
        author = "J. Maintainer <maint@example.com>"
648
658
        changelog.new_block(changes=changes, author=author)
649
 
        message, authors, thanks, bugs = \
650
 
                get_commit_info_from_changelog(changelog, wt.branch,
651
 
                        _lplib=MockLaunchpad())
 
659
        message, authors, thanks, bugs = get_commit_info_from_changelog(
 
660
            changelog, wt.branch, _lplib=MockLaunchpad())
652
661
        self.assertEqual(u'[ \xc1. Hacker ]\n'
653
662
                         u'* First ch\xe1nge, LP: #12345\n'
654
663
                         u'* Second change, thanks to \xde. Hacker',
668
677
class MockLaunchpad(object):
669
678
 
670
679
    def __init__(self, debian_bug_to_ubuntu_bugs={},
671
 
            ubuntu_bug_to_debian_bugs={}):
 
680
                 ubuntu_bug_to_debian_bugs={}):
672
681
        self.debian_bug_to_ubuntu_bugs = debian_bug_to_ubuntu_bugs
673
682
        self.ubuntu_bug_to_debian_bugs = ubuntu_bug_to_debian_bugs
674
683
        self.debian_bug_lookups = []
726
735
        author = "J. Maintainer <maint@example.com>"
727
736
        for version, distro in versions_and_distributions:
728
737
            cl.new_block(changes=changes, author=author,
729
 
                                distributions=distro, version=version)
 
738
                         distributions=distro, version=version)
730
739
        return cl
731
740
 
732
741
    def test_find_previous_upload_debian(self):
733
 
        cl = self.make_changelog([("0.1-1", "unstable"),
734
 
                ("0.1-2", "unstable")])
 
742
        cl = self.make_changelog(
 
743
            [("0.1-1", "unstable"),
 
744
             ("0.1-2", "unstable")])
735
745
        self.assertEqual(Version("0.1-1"), changelog_find_previous_upload(cl))
736
 
        cl = self.make_changelog([("0.1-1", "unstable"),
737
 
                ("0.1-1.1", "stable-security"), ("0.1-2", "unstable")])
 
746
        cl = self.make_changelog(
 
747
            [("0.1-1", "unstable"),
 
748
             ("0.1-1.1", "stable-security"), ("0.1-2", "unstable")])
738
749
        self.assertEqual(Version("0.1-1"), changelog_find_previous_upload(cl))
739
750
 
740
751
    def test_find_previous_upload_ubuntu(self):
741
 
        cl = self.make_changelog([("0.1-1", "lucid"),
742
 
                ("0.1-2", "lucid")])
 
752
        cl = self.make_changelog(
 
753
            [("0.1-1", "lucid"),
 
754
             ("0.1-2", "lucid")])
743
755
        self.assertEqual(Version("0.1-1"), changelog_find_previous_upload(cl))
744
 
        cl = self.make_changelog([("0.1-1", "lucid"),
745
 
                ("0.1-1.1", "unstable"), ("0.1-2", "maverick")])
 
756
        cl = self.make_changelog(
 
757
            [("0.1-1", "lucid"),
 
758
             ("0.1-1.1", "unstable"), ("0.1-2", "maverick")])
746
759
        self.requireFeature(DistroInfoFeature)
747
 
        self.assertEqual(Version("0.1-1"), changelog_find_previous_upload(cl))
 
760
        self.assertEqual(
 
761
                Version("0.1-1"), changelog_find_previous_upload(cl))
748
762
 
749
763
    def test_find_previous_upload_ubuntu_pocket(self):
750
 
        cl = self.make_changelog([("0.1-1", "lucid-updates"),
751
 
                ("0.1-2", "lucid-updates")])
 
764
        cl = self.make_changelog(
 
765
            [("0.1-1", "lucid-updates"),
 
766
             ("0.1-2", "lucid-updates")])
752
767
        self.assertEqual(Version("0.1-1"), changelog_find_previous_upload(cl))
753
768
 
754
769
    def test_find_previous_upload_unknown(self):
755
 
        cl = self.make_changelog([("0.1-1", "lucid"),
756
 
                ("0.1-2", "dunno")])
 
770
        cl = self.make_changelog(
 
771
            [("0.1-1", "lucid"),
 
772
             ("0.1-2", "dunno")])
757
773
        self.assertRaises(NoPreviousUpload, changelog_find_previous_upload, cl)
758
774
 
759
775
    def test_find_previous_upload_missing(self):
760
 
        cl = self.make_changelog([("0.1-1", "unstable"),
761
 
                ("0.1-2", "lucid")])
 
776
        cl = self.make_changelog(
 
777
            [("0.1-1", "unstable"),
 
778
             ("0.1-2", "lucid")])
762
779
        self.assertRaises(NoPreviousUpload, changelog_find_previous_upload, cl)
763
780
        cl = self.make_changelog([("0.1-1", "unstable")])
764
781
        self.assertRaises(NoPreviousUpload, changelog_find_previous_upload, cl)
765
782
 
766
783
    def test_find_previous_upload_unreleased(self):
767
 
        cl = self.make_changelog([("0.1-1", "unstable"),
768
 
                ("0.1-2", "UNRELEASED")])
 
784
        cl = self.make_changelog(
 
785
            [("0.1-1", "unstable"),
 
786
             ("0.1-2", "UNRELEASED")])
769
787
        self.assertEqual(Version("0.1-1"), changelog_find_previous_upload(cl))
770
788
 
771
789
 
777
795
 
778
796
    def test_source_format_newline(self):
779
797
        tree = self.make_branch_and_tree('.')
780
 
        self.build_tree_contents([("debian/", ), ("debian/source/",),
781
 
            ("debian/source/format", "3.0 (native)\n")])
 
798
        self.build_tree_contents(
 
799
            [("debian/", ), ("debian/source/",),
 
800
             ("debian/source/format", "3.0 (native)\n")])
782
801
        tree.add(["debian", "debian/source", "debian/source/format"])
783
802
        self.assertEquals("3.0 (native)", tree_get_source_format(tree))
784
803
 
785
804
    def test_source_format(self):
786
805
        tree = self.make_branch_and_tree('.')
787
 
        self.build_tree_contents([("debian/",), ("debian/source/",),
788
 
            ("debian/source/format", "3.0 (quilt)")])
 
806
        self.build_tree_contents(
 
807
            [("debian/",), ("debian/source/",),
 
808
             ("debian/source/format", "3.0 (quilt)")])
789
809
        tree.add(["debian", "debian/source", "debian/source/format"])
790
810
        self.assertEquals("3.0 (quilt)", tree_get_source_format(tree))
791
811
 
792
812
    def test_source_format_file_unversioned(self):
793
813
        tree = self.make_branch_and_tree('.')
794
 
        self.build_tree_contents([("debian/",), ("debian/source/",),
795
 
            ("debian/source/format", "3.0 (quilt)")])
 
814
        self.build_tree_contents(
 
815
            [("debian/",), ("debian/source/",),
 
816
             ("debian/source/format", "3.0 (quilt)")])
796
817
        self.assertEquals("3.0 (quilt)", tree_get_source_format(tree))
797
818
 
798
819
 
805
826
        :param tree: Tree to write to.
806
827
        :param format_string: Format string to write.
807
828
        """
808
 
        self.build_tree_contents([("debian/",), ("debian/source/",),
809
 
            ("debian/source/format", format_string)])
 
829
        self.build_tree_contents(
 
830
            [("debian/",), ("debian/source/",),
 
831
             ("debian/source/format", format_string)])
810
832
        tree.add(["debian", "debian/source", "debian/source/format"])
811
833
 
812
834
    def test_normal_source_format(self):
821
843
        # Normal source format without upstream source -> MERGE
822
844
        tree = self.make_branch_and_tree('.')
823
845
        self.writeVersionFile(tree, "3.0 (quilt)")
824
 
        self.assertEquals(BUILD_TYPE_MERGE, guess_build_type(tree, None, contains_upstream_source=False))
 
846
        self.assertEquals(
 
847
            BUILD_TYPE_MERGE,
 
848
            guess_build_type(tree, None, contains_upstream_source=False))
825
849
 
826
850
    def test_native_source_format(self):
827
851
        # Native source format -> NATIVE
828
852
        tree = self.make_branch_and_tree('.')
829
853
        self.writeVersionFile(tree, "3.0 (native)")
830
 
        self.assertEquals(BUILD_TYPE_NATIVE, guess_build_type(tree, None, contains_upstream_source=True))
 
854
        self.assertEquals(
 
855
            BUILD_TYPE_NATIVE,
 
856
            guess_build_type(tree, None, contains_upstream_source=True))
831
857
 
832
858
    def test_prev_version_native(self):
833
859
        # Native package version -> NATIVE
834
860
        tree = self.make_branch_and_tree('.')
835
 
        self.assertEquals(BUILD_TYPE_NATIVE,
836
 
            guess_build_type(tree, Version("1.0"), contains_upstream_source=True))
 
861
        self.assertEquals(
 
862
            BUILD_TYPE_NATIVE,
 
863
            guess_build_type(
 
864
                tree, Version("1.0"), contains_upstream_source=True))
837
865
 
838
866
    def test_empty(self):
839
867
        # Empty tree and a non-native package -> NORMAL
840
868
        tree = self.make_branch_and_tree('.')
841
 
        self.assertEquals(BUILD_TYPE_NORMAL,
842
 
            guess_build_type(tree, Version("1.0-1"), contains_upstream_source=None))
 
869
        self.assertEquals(
 
870
            BUILD_TYPE_NORMAL,
 
871
            guess_build_type(
 
872
                tree, Version("1.0-1"), contains_upstream_source=None))
843
873
 
844
874
    def test_no_upstream_source(self):
845
875
        # No upstream source code and a non-native package -> MERGE
846
876
        tree = self.make_branch_and_tree('.')
847
877
        tree.mkdir("debian")
848
 
        self.assertEquals(BUILD_TYPE_MERGE,
849
 
            guess_build_type(tree, Version("1.0-1"), contains_upstream_source=False))
 
878
        self.assertEquals(
 
879
            BUILD_TYPE_MERGE,
 
880
            guess_build_type(
 
881
                tree, Version("1.0-1"), contains_upstream_source=False))
850
882
 
851
883
    def test_default(self):
852
884
        # Upstream source code and a non-native package -> NORMAL
853
885
        tree = self.make_branch_and_tree('.')
854
 
        self.assertEquals(BUILD_TYPE_NORMAL,
855
 
            guess_build_type(tree, Version("1.0-1"), contains_upstream_source=True))
 
886
        self.assertEquals(
 
887
            BUILD_TYPE_NORMAL,
 
888
            guess_build_type(
 
889
                tree, Version("1.0-1"), contains_upstream_source=True))
856
890
 
857
891
    def test_inconsistent(self):
858
 
        # If version string and source format disagree on whether the package is native,
859
 
        # raise an exception.
 
892
        # If version string and source format disagree on whether the package
 
893
        # is native, raise an exception.
860
894
        tree = self.make_branch_and_tree('.')
861
895
        self.writeVersionFile(tree, "3.0 (native)")
862
 
        e = self.assertRaises(InconsistentSourceFormatError, guess_build_type, tree,
 
896
        e = self.assertRaises(
 
897
            InconsistentSourceFormatError, guess_build_type, tree,
863
898
            Version("1.0-1"), contains_upstream_source=True)
864
899
        self.assertEquals(
865
 
            "Inconsistency between source format and version: version is not native, "
866
 
            "format is native.", str(e))
 
900
            "Inconsistency between source format and version: "
 
901
            "version is not native, format is native.", str(e))
867
902
 
868
903
 
869
904
class TestExtractOrigTarballs(TestCaseInTempDir):
889
924
                import lzma
890
925
                f = lzma.LZMAFile(tar_path, "w")
891
926
            else:
892
 
                raise AssertionError("Unknown compressin type %r" %
893
 
                    compression)
 
927
                raise AssertionError(
 
928
                    "Unknown compressin type %r" % compression)
894
929
            try:
895
930
                tf = tarfile.open(None, 'w', f)
896
931
                try:
906
941
    def test_single_orig_tar_gz(self):
907
942
        tar_path = self.create_tarball("package", "0.1", "gz")
908
943
        os.mkdir("target")
909
 
        extract_orig_tarballs([(tar_path, None)], "target",
910
 
            strip_components=1)
 
944
        extract_orig_tarballs(
 
945
            [(tar_path, None)], "target", strip_components=1)
911
946
        self.assertEquals(os.listdir("target"), ["README"])
912
947
 
913
948
    def test_single_orig_tar_bz2(self):
914
949
        tar_path = self.create_tarball("package", "0.1", "bz2")
915
950
        os.mkdir("target")
916
 
        extract_orig_tarballs([(tar_path, None)], "target",
917
 
            strip_components=1)
 
951
        extract_orig_tarballs(
 
952
            [(tar_path, None)], "target", strip_components=1)
918
953
        self.assertEquals(os.listdir("target"), ["README"])
919
954
 
920
955
    def test_single_orig_tar_xz(self):
921
956
        self.requireFeature(LzmaFeature)
922
957
        tar_path = self.create_tarball("package", "0.1", "xz")
923
958
        os.mkdir("target")
924
 
        extract_orig_tarballs([(tar_path, None)], "target",
925
 
            strip_components=1)
 
959
        extract_orig_tarballs(
 
960
            [(tar_path, None)], "target", strip_components=1)
926
961
        self.assertEquals(os.listdir("target"), ["README"])
927
962
 
928
963
    def test_multiple_tarballs(self):
929
964
        base_tar_path = self.create_tarball("package", "0.1", "bz2")
930
 
        tar_path_extra = self.create_tarball("package", "0.1", "bz2", part="extra")
 
965
        tar_path_extra = self.create_tarball(
 
966
            "package", "0.1", "bz2", part="extra")
931
967
        os.mkdir("target")
932
 
        extract_orig_tarballs([(base_tar_path, None), (tar_path_extra, "extra")], "target",
 
968
        extract_orig_tarballs(
 
969
            [(base_tar_path, None), (tar_path_extra, "extra")], "target",
933
970
            strip_components=1)
934
 
        self.assertEquals(sorted(os.listdir("target")),
 
971
        self.assertEquals(
 
972
            sorted(os.listdir("target")),
935
973
            sorted(["README", "extra"]))
936
974
 
937
975
 
938
976
class ComponentFromOrigTarballTests(TestCase):
939
977
 
940
978
    def test_base_tarball(self):
941
 
        self.assertIs(None,
942
 
            component_from_orig_tarball("foo_0.1.orig.tar.gz", "foo", "0.1"))
943
 
        self.assertRaises(ValueError,
 
979
        self.assertIs(
 
980
            None,
 
981
            component_from_orig_tarball(
 
982
                "foo_0.1.orig.tar.gz", "foo", "0.1"))
 
983
        self.assertRaises(
 
984
            ValueError,
944
985
            component_from_orig_tarball, "foo_0.1.orig.tar.gz", "bar", "0.1")
945
986
 
946
987
    def test_invalid_extension(self):
947
 
        self.assertRaises(ValueError,
 
988
        self.assertRaises(
 
989
            ValueError,
948
990
            component_from_orig_tarball, "foo_0.1.orig.unknown", "foo", "0.1")
949
991
 
950
992
    def test_component(self):
951
 
        self.assertEquals("comp",
952
 
            component_from_orig_tarball("foo_0.1.orig-comp.tar.gz", "foo", "0.1"))
953
 
        self.assertEquals("comp-dash",
954
 
            component_from_orig_tarball("foo_0.1.orig-comp-dash.tar.gz", "foo", "0.1"))
 
993
        self.assertEquals(
 
994
            "comp",
 
995
            component_from_orig_tarball(
 
996
                "foo_0.1.orig-comp.tar.gz", "foo", "0.1"))
 
997
        self.assertEquals(
 
998
            "comp-dash",
 
999
            component_from_orig_tarball(
 
1000
                "foo_0.1.orig-comp-dash.tar.gz", "foo", "0.1"))
955
1001
 
956
1002
    def test_invalid_character(self):
957
 
        self.assertRaises(ValueError,
 
1003
        self.assertRaises(
 
1004
            ValueError,
958
1005
            component_from_orig_tarball, "foo_0.1.orig;.tar.gz", "foo", "0.1")
959
1006
 
960
1007