~ubuntu-langpack/langpack-o-matic/main

« back to all changes in this revision

Viewing changes to test/import

  • Committer: Martin Pitt
  • Date: 2010-08-18 09:09:42 UTC
  • Revision ID: martin.pitt@canonical.com-20100818090942-mdnijwr8ympo4eey
first version of test/import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
'''Integration test for "import" script.'''
 
4
 
 
5
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
 
6
#
 
7
# (C) 2010 Canonical Ltd.
 
8
 
 
9
import subprocess
 
10
import unittest
 
11
import shutil
 
12
import tempfile
 
13
import os.path
 
14
import sys
 
15
 
 
16
class_domain_expected = {
 
17
        '': 'pg_dump-8.4',
 
18
        'gnome-': 'gnome-session-2.0',
 
19
        'kde-': 'knetworkconf'
 
20
}
 
21
 
 
22
class _T(unittest.TestCase):
 
23
    def setUp(self):
 
24
        self.outdir = tempfile.mkdtemp()
 
25
        self.srcroot = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
 
26
        self.mirror = 'file://%s/test/archive' % self.srcroot
 
27
        self.full_tar = os.path.join(self.srcroot, 'test', 'test-full.tar.gz')
 
28
        self.update_tar = os.path.join(self.srcroot, 'test', 'test-update.tar.gz')
 
29
        self.import_path = os.path.join(self.srcroot, 'import')
 
30
        self.updated_packages = os.path.join(self.srcroot, 'updated-packages')
 
31
        assert not os.path.exists(self.updated_packages), 'updated-packages already exists, please clean up first'
 
32
 
 
33
    def tearDown(self):
 
34
        shutil.rmtree(self.outdir)
 
35
        if os.path.exists(self.updated_packages):
 
36
            os.unlink(self.updated_packages)
 
37
 
 
38
    def test_full_classes_nostatic(self):
 
39
        '''full tarball, classes, no static'''
 
40
 
 
41
        i = subprocess.Popen([self.import_path, '-s', '--mirror', self.mirror,
 
42
            self.full_tar, 'lucid', self.outdir], stdout=subprocess.PIPE,
 
43
            stderr=subprocess.PIPE)
 
44
        out, err = i.communicate()
 
45
        self.assertEqual(i.returncode, 0, 'import script failed:\n' + err)
 
46
        self.assertEqual(err, '')
 
47
 
 
48
        updated = open(self.updated_packages).read()
 
49
 
 
50
        for lang in ('de', 'en', 'pt', 'zh-hans', 'zh-hant'):
 
51
            for cls in ('', 'gnome-', 'kde-'):
 
52
                # base packs should be created and have the expected files
 
53
                dir = os.path.join(self.outdir, 'sources-base',
 
54
                        'language-pack-%s%s-base' % (cls, lang))
 
55
                self.assert_(os.path.isfile(os.path.join(dir, 'debian', 'control')))
 
56
                change = open(os.path.join(dir, 'debian', 'changelog')).readline()
 
57
                self.assertEqual(change, 'language-pack-%s%s-base (1:10.04+20100101) lucid; urgency=low\n' % (cls, lang))
 
58
                locs = os.listdir(os.path.join(dir, 'data'))
 
59
                try:
 
60
                    locs.remove('extra.tar')
 
61
                except ValueError:
 
62
                    pass
 
63
                self.assert_(len(locs) >= 1)
 
64
                for loc in locs:
 
65
                    self.assertEqual(os.listdir(os.path.join(dir, 'data', loc,
 
66
                        'LC_MESSAGES')), [class_domain_expected[cls] + '.po'])
 
67
 
 
68
                self.assert_('sources-base/language-pack-%s%s-base\n' % (cls, lang) in updated)
 
69
 
 
70
                # update packs should be created and be empty
 
71
                dir = os.path.join(self.outdir, 'sources-update',
 
72
                        'language-pack-%s%s' % (cls, lang))
 
73
                self.assert_(os.path.isfile(os.path.join(dir, 'debian', 'control')))
 
74
                change = open(os.path.join(dir, 'debian', 'changelog')).readline()
 
75
                self.assertEqual(change, 'language-pack-%s%s (1:10.04+20100101) lucid; urgency=low\n' % (cls, lang))
 
76
                self.assertEqual(os.listdir(os.path.join(dir, 'data')), [])
 
77
 
 
78
                self.assert_('sources-update/language-pack-%s%s\n' % (cls, lang) in updated)
 
79
 
 
80
        
 
81
unittest.main()
 
82