~pkgme-committers/pkgme/trunk

« back to all changes in this revision

Viewing changes to pkgme/tests/test_debuild.py

  • Committer: Tarmac
  • Author(s): Jonathan Lange
  • Date: 2012-09-04 15:27:39 UTC
  • mfrom: (136.4.25 imports-and-tempdir)
  • Revision ID: tarmac-20120904152739-lvhce4cmr06ot2e0
[r=jml] Deprecate TempdirFixture. Use treeshape 0.2.1 instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import tarfile
3
3
 
4
4
from testtools import TestCase
 
5
from treeshape import FileTree
5
6
 
6
 
from pkgme.debuild import (
 
7
from ..debuild import (
7
8
    _find_binary_files_in_dir,
8
9
    build_debian_source_include_binaries_content,
9
10
    build_orig_tar_gz,
10
11
    )
11
 
from pkgme.testing import (
12
 
    TempdirFixture,
13
 
    )
14
 
 
15
 
 
16
 
class DebianTempDirFixture(TempdirFixture):
17
 
    """A temp directory with a "testpkg" directory that contains
18
 
       a skeleton dir debian/ structure
19
 
    """
20
 
 
21
 
    def setUp(self, with_binary_data=False):
22
 
        super(DebianTempDirFixture, self).setUp()
23
 
        self.pkgdir = self.abspath("testpkg")
24
 
        self.icon_path = os.path.join(self.pkgdir, "debian", "icons")
25
 
        self.debian_source_path = os.path.join(self.pkgdir, "debian", "source")
26
 
        # setup fake env
27
 
        os.makedirs(self.icon_path)
28
 
        os.makedirs(self.debian_source_path)
 
12
 
 
13
 
 
14
def DebianTempDirFixture():
 
15
    return FileTree(
 
16
        {'debian/icons/': {},
 
17
         'debian/source/': {}})
29
18
 
30
19
 
31
20
class BuildTarTestCase(TestCase):
32
21
 
33
22
    def test_build_orig_tar_gz(self):
34
23
        tempdir = self.useFixture(DebianTempDirFixture())
35
 
        changelog_path = os.path.join(tempdir.pkgdir, "debian", "changelog")
 
24
        changelog_path = tempdir.join("debian", "changelog")
36
25
        with open(changelog_path, "w") as f:
37
26
            f.write("""
38
27
testpkg (0.1) unstable; urgency=low
41
30
 
42
31
 -- Some Guy <foo@example.com>  Thu, 19 Apr 2012 10:53:30 +0200
43
32
""")
44
 
        with open(os.path.join(tempdir.pkgdir, "canary"), "w") as f:
 
33
        with open(tempdir.join("canary"), "w") as f:
45
34
            f.write("pieep")
46
35
        # build it
47
 
        result_path = build_orig_tar_gz(tempdir.pkgdir)
 
36
        result_path = build_orig_tar_gz(tempdir.path)
48
37
        # verify
49
38
        self.assertEqual(
50
39
            "testpkg_0.1.orig.tar.gz", os.path.basename(result_path))
58
47
 
59
48
    def _make_icons(self, tempdir):
60
49
        for icon_name in ["foo.png", "bar.png"]:
61
 
            with open(os.path.join(tempdir.icon_path, icon_name), "w") as f:
 
50
            icon_path = tempdir.join('debian', 'icons', icon_name)
 
51
            with open(icon_path, "w") as f:
62
52
                f.write("x\0x")
63
53
 
64
54
    def test_find_binary_files(self):
65
55
        tempdir = self.useFixture(DebianTempDirFixture())
66
56
        self._make_icons(tempdir)
67
 
        bin_files = _find_binary_files_in_dir(os.path.join(
68
 
                tempdir.pkgdir, "debian"))
 
57
        bin_files = _find_binary_files_in_dir(tempdir.join('debian'))
69
58
        self.assertEqual(
70
59
            sorted(["icons/foo.png", "icons/bar.png"]),
71
60
            sorted(bin_files))
73
62
    def test_build_debian_source_include_binaries_content(self):
74
63
        tempdir = self.useFixture(DebianTempDirFixture())
75
64
        self._make_icons(tempdir)
76
 
        build_debian_source_include_binaries_content(tempdir.pkgdir)
 
65
        build_debian_source_include_binaries_content(tempdir.path)
77
66
        expected_binaries = sorted(
78
67
            ['debian/icons/foo.png', 'debian/icons/bar.png'])
79
 
        include_binaries = os.path.join(
80
 
            tempdir.debian_source_path, "include-binaries")
 
68
        include_binaries = tempdir.join('debian', 'source', "include-binaries")
81
69
        with open(include_binaries) as f:
82
70
            found_binaries = sorted(line.strip() for line in f.readlines())
83
71
        self.assertEqual(expected_binaries, found_binaries)