22_test_gbp_buildpackage.py 4.99 KB
Newer Older
1 2 3
# vim: set fileencoding=utf-8 :
"""Test L{gbp.command_wrappers.Command}'s tarball unpack"""

4 5 6
from gbp.scripts.buildpackage import (get_pbuilder_dist,
                                      setup_pbuilder,
                                      GbpError)
7 8 9 10 11
from . testutils import DebianGitTestRepo

from mock import patch


12
class TestGbpBuildpackageDep14(DebianGitTestRepo):
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    class Options(object):
        pass

    def setUp(self):
        DebianGitTestRepo.setUp(self)
        self.add_file('doesnotmatter')
        self.options = self.Options()
        self.options.pbuilder_dist = 'DEP14'

    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_no_dep14(self, patch):
        self.options.pbuilder_dist = 'notdep14'
        self.assertEqual(get_pbuilder_dist(self.options, self.repo),
                         self.options.pbuilder_dist)

    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_debian_sid(self, patch):
        branch = 'debian/sid'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), '')
        patch.assert_called_once_with()

36 37 38 39 40 41 42 43
    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_debian_master(self, patch):
        branch = 'debian/master'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), '')
        patch.assert_called_once_with()

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_debian_suite(self, patch):
        branch = 'debian/squeeze-lts'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'squeeze-lts')
        patch.assert_called_once_with()

    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_debian_native(self, patch):
        self.assertEqual(get_pbuilder_dist(self.options, self.repo, True), '')

    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_vendor_sid(self, patch):
        branch = 'downstream/sid'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'downstream_sid')
        patch.assert_called_once_with()

    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_vendor_suite(self, patch):
        branch = 'downstream/mies-lts'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'downstream_mies-lts')

    @patch('gbp.deb.get_vendor', return_value='Debian')
72
    def test_get_pbuilder_dist_dep14_no_vendor_sid(self, patch):
73 74 75
        branch = 'sid'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
76 77 78 79 80 81 82 83 84 85
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), '')
        patch.assert_called_once_with()

    @patch('gbp.deb.get_vendor', return_value='Debian')
    def test_get_pbuilder_dist_dep14_no_vendor(self, patch):
        branch = 'wheezy'
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'wheezy')
        patch.assert_called_once_with()
86 87

    def test_get_pbuilder_dist_dep14_too_many_slashes(self):
88
        branch = 'too/many/slashes'
89 90 91
        self.repo.create_branch(branch)
        self.repo.set_branch(branch)
        with self.assertRaisesRegexp(GbpError,
92
                                     "DEP14 DIST: Current branch 'too/many/slashes' does not match vendor/suite"):
93
            get_pbuilder_dist(self.options, self.repo)
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126


class TestGbpBuildpackageSetupPbuilder(DebianGitTestRepo):
    class Options(object):
        use_pbuilder = True
        pbuilder_dist = 'sid'
        pbuilder_arch = ''
        use_qemubuilder = False
        pbuilder_autoconf = True
        pbuilder_options = ''

    def setUp(self):
        DebianGitTestRepo.setUp(self)
        self.options = self.Options()

    def test_setup_pbuilder(self):
        self.assertEqual(setup_pbuilder(self.options,
                                        self.repo,
                                        True),
                         ({'GBP_PBUILDER_DIST': 'sid', 'DIST': 'sid'},
                          {'GBP_PBUILDER_DIST': 'sid'}))

    def test_setup_pbuilder_arch(self):
        self.options.pbuilder_arch = 'arm64'
        self.assertEqual(setup_pbuilder(self.options,
                                        self.repo,
                                        True),
                         ({'ARCH': 'arm64',
                           'DIST': 'sid',
                           'GBP_PBUILDER_ARCH': 'arm64',
                           'GBP_PBUILDER_DIST': 'sid'},
                          {'GBP_PBUILDER_ARCH': 'arm64',
                           'GBP_PBUILDER_DIST': 'sid'}))