10_test_get_upstream_tree.py 2.93 KB
Newer Older
1 2
# vim: set fileencoding=utf-8 :

3
"""Test  L{export_orig}'s git_archive_get_upstream_tree method"""
4

5
from . import context  # noqa: 401
6
from . import testutils
7 8

import gbp.errors
9
import gbp.scripts.export_orig as export_orig
10

11

12 13 14 15 16 17 18 19 20
class MockOptions(object):
    def __init__(self,
                 upstream_branch=None,
                 upstream_tree=None,
                 upstream_tag=None):
        self.upstream_branch = upstream_branch
        self.upstream_tree = upstream_tree
        self.upstream_tag = upstream_tag

21

22
class TestGetUpstreamTree(testutils.DebianGitTestRepo):
23 24 25
    class source:
        upstream_version = '1.0~rc3'

26
    def test_valid_upstream_branch(self):
27
        """Get upstream tree from a valid upstream branch"""
28 29 30 31
        self.add_file('foo')
        self.repo.create_branch('upstream')
        options = MockOptions(upstream_tree='BRANCH',
                              upstream_branch='upstream')
32
        t = export_orig.git_archive_get_upstream_tree(self.repo, None, options)
33 34 35
        self.assertEqual(t, 'upstream')

    def test_invalid_upstream_branch(self):
36
        """Getting upstream tree from a invalid upstream branch must fail"""
37 38 39
        self.add_file('foo')
        options = MockOptions(upstream_tree='BRANCH',
                              upstream_branch='upstream')
40 41
        with self.assertRaises(gbp.errors.GbpError):
            export_orig.git_archive_get_upstream_tree(self.repo, None, options)
42 43

    def test_valid_tree(self):
44
        """Get upstream tree from a valid upstream tree"""
45 46 47
        self.add_file('foo')
        tree = self.repo.rev_parse('master')
        options = MockOptions(upstream_tree=tree)
48
        t = export_orig.git_archive_get_upstream_tree(self.repo, None, options)
49 50 51
        self.assertEqual(t, tree)

    def test_invalid_tree(self):
52
        """Getting upstream tree from an invalid tree must fail"""
53 54
        self.add_file('foo')
        options = MockOptions(upstream_tree='doesnotexist')
55 56
        with self.assertRaises(gbp.errors.GbpError):
            export_orig.git_archive_get_upstream_tree(self.repo, None, options)
57 58

    def test_valid_tag(self):
59
        """Get upstream tree from a valid tag"""
60
        self.add_file('foo')
61
        self.repo.rev_parse('master')
62 63 64
        self.repo.create_tag('upstream/1.0_rc3')
        options = MockOptions(upstream_tree="TAG",
                              upstream_tag="upstream/%(version)s")
65
        tag = export_orig.git_archive_get_upstream_tree(self.repo, self.source, options)
66 67 68
        self.assertEqual(tag, "upstream/1.0_rc3")

    def test_invalid_tag(self):
69
        """Getting upstream tree from an invalid tag must fail"""
70 71 72
        self.add_file('foo')
        options = MockOptions(upstream_tree="TAG",
                              upstream_tag="upstream/%(version)s")
73 74
        with self.assertRaises(gbp.errors.GbpError):
            export_orig.git_archive_get_upstream_tree(self.repo, self.source, options)
75 76

# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: