753
750
self.failUnlessExists(join(self.source_dir, 'a'))
756
class TestMergeExportUpstreamBuilder(BuilderTestCase):
758
upstream_branch = 'upstream'
759
upstream_parent = 'parent'
761
def get_builder(self, wt=None, version=None, larstiq=False,
762
export_revision=None, export_prepull=False,
763
stop_on_no_change=False):
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,
771
_is_working_tree=True)
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,
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)
786
wt.commit('commit one', rev_id='rev1')
787
self.build_tree([join(self.upstream_branch, 'c')])
789
wt.commit('commit two', rev_id='rev2')
790
self.build_tree([join(self.upstream_branch, f) for f in
791
['added', 'unknown']])
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()
800
for f in ['a', 'dir', 'dir/b', 'c']:
801
self.failUnlessExists(join(self.source_dir, f))
804
class TestDefaultExportUpstreamBuilder(BuilderTestCase):
806
upstream_branch = 'upstream'
807
upstream_parent = 'parent'
809
def get_builder(self, wt=None, version=None, larstiq=False,
810
export_revision=None, export_prepull=False,
811
stop_on_no_change=False):
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,
819
_is_working_tree=True)
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,
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)
834
wt.commit('commit one', rev_id='rev1')
835
self.build_tree([join(self.upstream_branch, 'c')])
837
wt.commit('commit two', rev_id='rev2')
838
self.build_tree([join(self.upstream_branch, f) for f in
839
['added', 'unknown']])
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('.')
851
builder = self.get_builder(wt)
852
self.make_upstream_branch()
855
self.assertFileEqual('branch\n', join(self.source_dir, 'a'))
856
self.failIfExists(join(self.source_dir, 'dir'))
859
class TestUpstreamExporter(BuilddebTestCase):
861
upstream_branch = 'upstream'
862
upstream_parent = 'parent'
863
tarball = 'upstream.tar.gz'
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)
873
wt.commit('commit one', rev_id='rev1')
874
self.build_tree([join(self.upstream_branch, 'c')])
876
wt.commit('commit two', rev_id='rev2')
877
self.build_tree([join(self.upstream_branch, f) for f in
878
['added', 'unknown']])
880
if parent is not None:
881
wt.branch.set_parent(parent)
882
self._upstream_tree = wt
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))
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')
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)
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)
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)
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)
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()
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()
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()
953
self.failUnlessExists(self.tarball)
954
expected = ['a', 'dir/', 'dir/b', 'c']
955
self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
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()
965
self.failUnlessExists(self.tarball)
966
expected = ['a', 'dir/', 'dir/b', 'c']
967
self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
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()
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,
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()
990
self.failUnlessExists(self.tarball)
991
expected = ['a', 'dir/', 'dir/b']
992
self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
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()
1003
self.failUnlessExists(self.tarball)
1004
expected = ['a', 'dir/', 'dir/b', 'c', 'parent']
1005
self.check_tarball_contents(self.tarball, expected, basedir=self.basedir,
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)
1014
753
# vim: ts=2 sts=2 sw=2