~brz/brz-debian/byoci

« back to all changes in this revision

Viewing changes to tests/test_builder.py

  • Committer: James Westby
  • Date: 2009-02-18 18:36:18 UTC
  • mto: This revision was merged to the branch mainline in revision 323.
  • Revision ID: jw+debian@jameswestby.net-20090218183618-0wuajt2nbtpcooag
Kill off export-upstream mode.

merge-upstream will be improved to merge the upstream branch, store it with
pristine-tar, and then produce the tarball as needed.

Using export-upstream for snapshots is now incorrect. You should use
"merge-upstream" every time instead, which will track if there is nothing
to do, and handle conflicts. You can autocommit the merge and build the
result if you like.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                     DebNativeBuild,
42
42
                     DebSplitBuild,
43
43
                     DebMergeBuild,
44
 
                     DebMergeExportUpstreamBuild,
45
 
                     DebExportUpstreamBuild,
46
 
                     UpstreamExporter,
47
44
                     )
48
45
from bzrlib.plugins.builddeb import errors
49
46
from bzrlib.plugins.builddeb.properties import BuildProperties
753
750
    self.failUnlessExists(join(self.source_dir, 'a'))
754
751
 
755
752
 
756
 
class TestMergeExportUpstreamBuilder(BuilderTestCase):
757
 
 
758
 
  upstream_branch = 'upstream'
759
 
  upstream_parent = 'parent'
760
 
 
761
 
  def get_builder(self, wt=None, version=None, larstiq=False,
762
 
                  export_revision=None, export_prepull=False,
763
 
                  stop_on_no_change=False):
764
 
    if wt is None:
765
 
      wt = self.make_branch_and_tree('.')
766
 
    changelog = self.make_changelog(version=version)
767
 
    properties = self.make_properties(changelog, larstiq)
768
 
    return DebMergeExportUpstreamBuild(properties, wt, self.upstream_branch,
769
 
                                       export_revision, export_prepull,
770
 
                                       stop_on_no_change,
771
 
                                       _is_working_tree=True)
772
 
 
773
 
  def test__find_tarball(self):
774
 
    """Test that the tarball is located in the build dir."""
775
 
    builder = self.get_builder()
776
 
    self.assertEqual(builder._find_tarball(), join(self.build_dir,
777
 
                     self.tarball_name))
778
 
 
779
 
  def make_upstream_branch(self):
780
 
    """Make the upstream branch that will be exported."""
781
 
    wt = self.make_branch_and_tree(self.upstream_branch)
782
 
    files = ['a', 'dir/', 'dir/b']
783
 
    newfiles = [join(self.upstream_branch, f) for f in files]
784
 
    self.build_tree(newfiles)
785
 
    wt.add(files)
786
 
    wt.commit('commit one', rev_id='rev1')
787
 
    self.build_tree([join(self.upstream_branch, 'c')])
788
 
    wt.add('c')
789
 
    wt.commit('commit two', rev_id='rev2')
790
 
    self.build_tree([join(self.upstream_branch, f) for f in
791
 
                                          ['added', 'unknown']])
792
 
    wt.add('added')
793
 
 
794
 
  def test_export_has_correct_file(self):
795
 
    """A check that the top level export works as expected,"""
796
 
    builder = self.get_builder()
797
 
    self.make_upstream_branch()
798
 
    builder.prepare()
799
 
    builder.export()
800
 
    for f in ['a', 'dir', 'dir/b', 'c']:
801
 
      self.failUnlessExists(join(self.source_dir, f))
802
 
 
803
 
 
804
 
class TestDefaultExportUpstreamBuilder(BuilderTestCase):
805
 
 
806
 
  upstream_branch = 'upstream'
807
 
  upstream_parent = 'parent'
808
 
 
809
 
  def get_builder(self, wt=None, version=None, larstiq=False,
810
 
                  export_revision=None, export_prepull=False,
811
 
                  stop_on_no_change=False):
812
 
    if wt is None:
813
 
      wt = self.make_branch_and_tree('.')
814
 
    changelog = self.make_changelog(version=version)
815
 
    properties = self.make_properties(changelog, larstiq)
816
 
    return DebExportUpstreamBuild(properties, wt, self.upstream_branch,
817
 
                                  export_revision, export_prepull,
818
 
                                  stop_on_no_change,
819
 
                                  _is_working_tree=True)
820
 
 
821
 
  def test__find_tarball(self):
822
 
    """Test that the tarball is located in the build dir."""
823
 
    builder = self.get_builder()
824
 
    self.assertEqual(builder._find_tarball(), join(self.build_dir,
825
 
                     self.tarball_name))
826
 
 
827
 
  def make_upstream_branch(self):
828
 
    """Make the upstream branch that will be exported."""
829
 
    wt = self.make_branch_and_tree(self.upstream_branch)
830
 
    files = ['a', 'dir/', 'dir/b']
831
 
    newfiles = [join(self.upstream_branch, f) for f in files]
832
 
    self.build_tree(newfiles)
833
 
    wt.add(files)
834
 
    wt.commit('commit one', rev_id='rev1')
835
 
    self.build_tree([join(self.upstream_branch, 'c')])
836
 
    wt.add('c')
837
 
    wt.commit('commit two', rev_id='rev2')
838
 
    self.build_tree([join(self.upstream_branch, f) for f in
839
 
                                          ['added', 'unknown']])
840
 
    wt.add('added')
841
 
 
842
 
  def test_export_has_correct_file(self):
843
 
    """A check that the top level export works as expected,"""
844
 
    wt = self.make_branch_and_tree('.')
845
 
    f = open('a', 'wb')
846
 
    try:
847
 
      f.write('branch\n')
848
 
    finally:
849
 
      f.close()
850
 
    wt.add('a')
851
 
    builder = self.get_builder(wt)
852
 
    self.make_upstream_branch()
853
 
    builder.prepare()
854
 
    builder.export()
855
 
    self.assertFileEqual('branch\n', join(self.source_dir, 'a'))
856
 
    self.failIfExists(join(self.source_dir, 'dir'))
857
 
 
858
 
 
859
 
class TestUpstreamExporter(BuilddebTestCase):
860
 
 
861
 
  upstream_branch = 'upstream'
862
 
  upstream_parent = 'parent'
863
 
  tarball = 'upstream.tar.gz'
864
 
  basedir = 'test-0.1'
865
 
 
866
 
  def make_upstream_branch(self, parent=None):
867
 
    """Make the upstream branch that will be exported."""
868
 
    wt = self.make_branch_and_tree(self.upstream_branch)
869
 
    files = ['a', 'dir/', 'dir/b']
870
 
    newfiles = [join(self.upstream_branch, f) for f in files]
871
 
    self.build_tree(newfiles)
872
 
    wt.add(files)
873
 
    wt.commit('commit one', rev_id='rev1')
874
 
    self.build_tree([join(self.upstream_branch, 'c')])
875
 
    wt.add('c')
876
 
    wt.commit('commit two', rev_id='rev2')
877
 
    self.build_tree([join(self.upstream_branch, f) for f in
878
 
                                          ['added', 'unknown']])
879
 
    wt.add('added')
880
 
    if parent is not None:
881
 
      wt.branch.set_parent(parent)
882
 
    self._upstream_tree = wt
883
 
    return wt
884
 
 
885
 
  def make_upstream_parent_no_changes(self):
886
 
    """Makes the upstream parent by just sprouting it off the upstream."""
887
 
    upstream = self._upstream_tree
888
 
    upstream.branch.bzrdir.sprout(os.path.abspath(self.upstream_parent))
889
 
 
890
 
  def make_upstream_parent_changes(self):
891
 
    """Makes the upstream parent and adds a commit."""
892
 
    self.make_upstream_parent_no_changes()
893
 
    parent_location = os.path.abspath(self.upstream_parent)
894
 
    parent = WorkingTree.open_containing(parent_location)[0]
895
 
    self.build_tree([join(self.upstream_parent, 'parent'),
896
 
                     join(self.upstream_parent, 'parent2')])
897
 
    parent.add(['parent'])
898
 
    parent.commit('parent commit 1', rev_id='parent1')
899
 
    parent.add(['parent2'])
900
 
    parent.commit('parent commit 2', rev_id='parent2')
901
 
 
902
 
  def get_exporter(self, export_prepull=False, stop_on_no_change=False,
903
 
                   export_revision=None):
904
 
    path = self.upstream_branch
905
 
    return UpstreamExporter(path, self.tarball, self.basedir,
906
 
                            export_prepull=export_prepull,
907
 
                            stop_on_no_change=stop_on_no_change,
908
 
                            export_revision=export_revision)
909
 
 
910
 
  def test_exporter_errors_export_prepull_no_default(self):
911
 
    """Test that the export_prepull fails if the default location is not set."""
912
 
    wt = self.make_upstream_branch()
913
 
    exporter = self.get_exporter(export_prepull=True)
914
 
    self.assertRaises(errors.DebianError, exporter.export)
915
 
 
916
 
  def test_exporter_errors_invalid_parent(self):
917
 
    """Test that the export_prepull fails if the parent doesn't exist."""
918
 
    wt = self.make_upstream_branch(parent='invalid')
919
 
    exporter = self.get_exporter(export_prepull=True)
920
 
    self.assertRaises(NotBranchError, exporter.export)
921
 
 
922
 
  def test_exporter_stops_on_trivial(self):
923
 
    """Test that StopBuild is raised if there are no changes to pull."""
924
 
    wt = self.make_upstream_branch(parent=
925
 
        os.path.abspath(self.upstream_parent))
926
 
    exporter = self.get_exporter(export_prepull=True,
927
 
                                 stop_on_no_change=True)
928
 
    self.make_upstream_parent_no_changes()
929
 
    self.assertRaises(errors.StopBuild, exporter.export)
930
 
 
931
 
  def test_exporter_doesnt_stop_on_trivial(self):
932
 
    """Test that the build normally doesn't stop if there is nothing to do."""
933
 
    wt = self.make_upstream_branch(parent=
934
 
        os.path.abspath(self.upstream_parent))
935
 
    exporter = self.get_exporter(export_prepull=True)
936
 
    self.make_upstream_parent_no_changes()
937
 
    exporter.export()
938
 
 
939
 
  def test_exporter_doesnt_stop_on_changes(self):
940
 
    """Test the the build doesn't stop if there is something to do."""
941
 
    wt = self.make_upstream_branch(
942
 
        parent=os.path.abspath(self.upstream_parent))
943
 
    exporter = self.get_exporter(export_prepull=True,
944
 
                                 stop_on_no_change=True)
945
 
    self.make_upstream_parent_changes()
946
 
    exporter.export()
947
 
 
948
 
  def test_exporter_has_correct_files(self):
949
 
    """Test that the upstream tarball has the correct files."""
950
 
    wt = self.make_upstream_branch()
951
 
    exporter = self.get_exporter()
952
 
    exporter.export()
953
 
    self.failUnlessExists(self.tarball)
954
 
    expected = ['a', 'dir/', 'dir/b', 'c']
955
 
    self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
956
 
                                skip_basedir=True)
957
 
 
958
 
  def test_exporter_has_correct_files_pull_no_changes(self):
959
 
    """Test that the upstream tarball has the correct files."""
960
 
    wt = self.make_upstream_branch(parent=
961
 
         os.path.abspath(self.upstream_parent))
962
 
    exporter = self.get_exporter(export_prepull=True)
963
 
    self.make_upstream_parent_no_changes()
964
 
    exporter.export()
965
 
    self.failUnlessExists(self.tarball)
966
 
    expected = ['a', 'dir/', 'dir/b', 'c']
967
 
    self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
968
 
                                skip_basedir=True)
969
 
 
970
 
  def test_exporter_has_correct_files_pull_changes(self):
971
 
    """Test that the upstream tarball has the correct files."""
972
 
    wt = self.make_upstream_branch(parent=
973
 
        os.path.abspath(self.upstream_parent))
974
 
    exporter = self.get_exporter(export_prepull=True)
975
 
    self.make_upstream_parent_changes()
976
 
    exporter.export()
977
 
    self.failUnlessExists(self.tarball)
978
 
    expected = ['a', 'dir/', 'dir/b', 'c', 'parent', 'parent2']
979
 
    self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
980
 
                                skip_basedir=True)
981
 
 
982
 
  def test_exporter_selects_correct_revision(self):
983
 
    """Test that if an upstream revision is selected it will be used."""
984
 
    wt = self.make_upstream_branch(parent=
985
 
        os.path.abspath(self.upstream_parent))
986
 
    exporter = self.get_exporter(export_prepull=True,
987
 
                               export_revision='revid:rev1')
988
 
    self.make_upstream_parent_no_changes()
989
 
    exporter.export()
990
 
    self.failUnlessExists(self.tarball)
991
 
    expected = ['a', 'dir/', 'dir/b']
992
 
    self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
993
 
                                skip_basedir=True)
994
 
 
995
 
  def test_exporter_can_select_parent_revision(self):
996
 
    """Test that if an upstream parent revision is selected it will be used."""
997
 
    wt = self.make_upstream_branch(parent=
998
 
        os.path.abspath(self.upstream_parent))
999
 
    exporter = self.get_exporter(export_prepull=True,
1000
 
                               export_revision='revid:parent1')
1001
 
    self.make_upstream_parent_changes()
1002
 
    exporter.export()
1003
 
    self.failUnlessExists(self.tarball)
1004
 
    expected = ['a', 'dir/', 'dir/b', 'c', 'parent']
1005
 
    self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
1006
 
                                skip_basedir=True)
1007
 
 
1008
 
  def test_exporter_returns_true(self):
1009
 
    """Sanity check that the function returns true."""
1010
 
    wt = self.make_upstream_branch()
1011
 
    exporter = self.get_exporter()
1012
 
    self.assertEqual(exporter.export(), True)
1013
 
 
1014
753
# vim: ts=2 sts=2 sw=2