summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2013-03-29 15:55:12 +0100
committerGuido Günther <agx@sigxcpu.org>2013-04-13 14:26:24 +0200
commita60f37dab018ee827aef631f0e1646e720194655 (patch)
tree78e4185d2a5ed9c58544aad4cd4360c6c6904793 /tests
parent8fd5ec31272984a7fcff628c50b4c22d7e4107ec (diff)
Introduce Source class
so we don't have to expose all the details of Debian's different files and conventions.
Diffstat (limited to 'tests')
-rw-r--r--tests/15_test_DebianSource.py84
-rw-r--r--tests/context.py2
-rw-r--r--tests/test_GitRepository.py3
-rw-r--r--tests/test_GitVfs.py10
-rw-r--r--tests/testutils.py1
5 files changed, 91 insertions, 9 deletions
diff --git a/tests/15_test_DebianSource.py b/tests/15_test_DebianSource.py
new file mode 100644
index 0000000..4896b31
--- /dev/null
+++ b/tests/15_test_DebianSource.py
@@ -0,0 +1,84 @@
+# vim: set fileencoding=utf-8 :
+# (C) 2013 Guido Günther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Test L{gbp.pq}"""
+
+from . import context
+
+import os
+import testutils
+from gbp.deb.source import DebianSource, DebianSourceError
+from gbp.deb.format import DebianSourceFormat
+from gbp.git.vfs import GitVfs
+
+class TestDebianSource(testutils.DebianGitTestRepo):
+ """Test L{gbp.deb.source}'s """
+
+ def setUp(self):
+ testutils.DebianGitTestRepo.setUp(self)
+ context.chdir(self.repo.path)
+
+ def test_is_native_file_3_file(self):
+ """Test native package of format 3"""
+ source = DebianSource('.')
+ os.makedirs('debian/source')
+ self.assertRaises(DebianSourceError,
+ source.is_native)
+
+ dsf = DebianSourceFormat.from_content("3.0", "native")
+ self.assertEqual(dsf.type, 'native')
+ self.assertTrue(source.is_native())
+
+ dsf = DebianSourceFormat.from_content("3.0", "quilt")
+ self.assertEqual(dsf.type, 'quilt')
+ self.assertFalse(source.is_native())
+
+ def test_is_native_fallback_file(self):
+ """Test native package without a debian/source/format file"""
+ source = DebianSource('.')
+ os.makedirs('debian/')
+ self.assertRaises(DebianSourceError,
+ source.is_native)
+
+ with file('debian/changelog', 'w') as f:
+ f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low
+
+ * git doesn't like '~' in tag names so replace this with a dot when tagging
+
+ -- Guido Guenther <agx@sigxcpu.org> Mon, 2 Oct 2006 18:30:20 +0200
+""")
+ source = DebianSource('.')
+ self.assertTrue(source.is_native())
+
+ def _commit_format(self, version, format):
+ # Commit a format file to disk
+ if not os.path.exists('debian/source'):
+ os.makedirs('debian/source')
+ dsf = DebianSourceFormat.from_content(version, format)
+ self.assertEqual(dsf.type, format)
+ self.repo.add_files('.')
+ self.repo.commit_all('foo')
+ os.unlink('debian/source/format')
+ self.assertFalse(os.path.exists('debian/source/format'))
+
+ def test_is_native_file_3_git(self):
+ """Test native package of format 3 from git"""
+ self._commit_format('3.0', 'native')
+ source = DebianSource(GitVfs(self.repo))
+ self.assertTrue(source.is_native())
+
+ self._commit_format('3.0', 'quilt')
+ source = DebianSource(GitVfs(self.repo))
+ self.assertFalse(source.is_native())
diff --git a/tests/context.py b/tests/context.py
index 22a9e29..cc3e25d 100644
--- a/tests/context.py
+++ b/tests/context.py
@@ -29,7 +29,7 @@ def chdir(dir):
def new_tmpdir(name):
global _tmpdirs
prefix='gbp_%s_' % name
- tmpdir=TmpDir(prefix)
+ tmpdir = TmpDir(prefix)
_tmpdirs.append(tmpdir)
return tmpdir
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index a91ee06..5e11fad 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -13,7 +13,6 @@ This testcase creates several repositores:
from . import context
-import os
import gbp.log
gbp.log.setup(color=False, verbose=True)
@@ -73,7 +72,7 @@ def test_add_files():
Properties tested:
- L{gbp.git.GitRepository.head}
- >>> import gbp.git, shutil
+ >>> import gbp.git, shutil, os
>>> repo = gbp.git.GitRepository(repo_dir)
>>> shutil.copy(os.path.join(repo.path, ".git/HEAD"), \
os.path.join(repo.path, "testfile"))
diff --git a/tests/test_GitVfs.py b/tests/test_GitVfs.py
index c4e2694..05ff545 100644
--- a/tests/test_GitVfs.py
+++ b/tests/test_GitVfs.py
@@ -4,12 +4,12 @@
Test L{gbp.git.GitVfs}
"""
-import os
import gbp.log
from . import context
gbp.log.setup(color=False, verbose=True)
+import gbp.git
def test_read():
repo_dir = context.new_tmpdir(__name__)
@@ -18,10 +18,10 @@ def test_read():
Methods tested:
- L{gbp.git.GitVfs.open}
- - L{gbp.git._File.readline}
- - L{gbp.git._File.readlines}
- - L{gbp.git._File.read}
- - L{gbp.git._File.close}
+ - L{gbp.git.GitVfs._File.readline}
+ - L{gbp.git.GitVfs._File.readlines}
+ - L{gbp.git.GitVfs._File.read}
+ - L{gbp.git.GitVfs._File.close}
>>> import os, gbp.git.vfs
>>> repo = gbp.git.GitRepository.create(str(repo_dir))
diff --git a/tests/testutils.py b/tests/testutils.py
index 112bb04..38e0ac3 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -3,7 +3,6 @@
from . import context
import os
-import shutil
import unittest
import gbp.log