summaryrefslogtreecommitdiff
path: root/tests/05_test_detection.py
blob: 1454e4dad6f6237a410d71a0e43938cd6991a5cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import shutil
import tempfile
import unittest

import git_buildpackage
from gbp.deb import has_orig

class MockGitRepository:
    def __init__(self, with_branch=False, subject=None):
        self.with_branch = with_branch
        self.subject = subject

    def has_branch(self, branch):
        return self.with_branch

    def grep_log(self, regex, branch):
        return None

    def get_subject(self, commit):
        return self.subject

class TestDetection(unittest.TestCase):
    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.tmpdir)

    def test_guess_comp_type_no_pristine_tar(self):
        repo = MockGitRepository(with_branch=False)
        guessed = git_buildpackage.guess_comp_type(repo, 'auto', None, None)
        self.assertEqual('gzip', guessed)

    def test_guess_comp_type_bzip2(self):
        subject = 'pristine-tar data for source_1.2-3.orig.tar.bz2'
        repo = MockGitRepository(with_branch=True, subject=subject)
        guessed = git_buildpackage.guess_comp_type(
            repo, 'auto', 'source', '1.2')
        self.assertEqual("bzip2", guessed)

    def test_has_orig_false(self):
        cp = {'Source': 'source', 'Upstream-Version': '1.2'}
        self.assertFalse(has_orig(cp, 'gzip', self.tmpdir))

    def test_has_orig_true(self):
        cp = {'Source': 'source', 'Upstream-Version': '1.2'}
        open(os.path.join(self.tmpdir, 'source_1.2.orig.tar.gz'), "w").close()
        self.assertTrue(has_orig(cp, 'gzip', self.tmpdir))