From 8189cc9e01ed42f67b20d59a9f18247779a86ed4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lo=C3=AFc=20Minier?= Date: Fri, 8 Apr 2011 03:32:17 +0200 Subject: [PATCH] Add tests for orig autodetection --- tests/05_test_detection.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/05_test_detection.py diff --git a/tests/05_test_detection.py b/tests/05_test_detection.py new file mode 100644 index 0000000..1454e4d --- /dev/null +++ b/tests/05_test_detection.py @@ -0,0 +1,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)) + -- 2.7.4