~click-hackers/click/trunk

« back to all changes in this revision

Viewing changes to click/tests/test_install.py

  • Committer: Colin Watson
  • Date: 2014-03-03 17:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 354.
  • Revision ID: cjwatson@canonical.com-20140303170137-4gs1zjmqtgkvzphq
Move an initial core of functionality (database, hooks, osextras, query,
user) from Python into a new "libclick" library, allowing
performance-critical clients to avoid the cost of starting a new Python
interpreter (LP: #1282311).

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from unittest import skipUnless
35
35
 
36
36
from debian.deb822 import Deb822
 
37
from gi.repository import Click
37
38
 
38
 
from click import install, osextras
 
39
from click import install
39
40
from click.build import ClickBuilder
40
 
from click.database import ClickDB
41
41
from click.install import (
42
42
    ClickInstaller,
43
43
    ClickInstallerAuditError,
68
68
    def setUp(self):
69
69
        super(TestClickInstaller, self).setUp()
70
70
        self.use_temp_dir()
71
 
        self.db = ClickDB(self.temp_dir)
 
71
        self.db = Click.DB()
 
72
        self.db.add(self.temp_dir)
72
73
 
73
74
    def make_fake_package(self, control_fields=None, manifest=None,
74
75
                          control_scripts=None, data_files=None):
90
91
        for name, contents in control_scripts.items():
91
92
            with mkfile(os.path.join(control_dir, name)) as script:
92
93
                script.write(contents)
93
 
        osextras.ensuredir(data_dir)
 
94
        Click.ensuredir(data_dir)
94
95
        for name, path in data_files.items():
95
96
            if path is None:
96
97
                touch(os.path.join(data_dir, name))
108
109
        old_dir = install.frameworks_dir
109
110
        try:
110
111
            install.frameworks_dir = os.path.join(self.temp_dir, "frameworks")
111
 
            osextras.ensuredir(install.frameworks_dir)
 
112
            Click.ensuredir(install.frameworks_dir)
112
113
            touch(os.path.join(install.frameworks_dir, "%s.framework" % name))
113
114
            yield
114
115
        finally:
115
 
            osextras.unlink_force(
 
116
            Click.unlink_force(
116
117
                os.path.join(install.frameworks_dir, "%s.framework" % name))
117
118
            install.frameworks_dir = old_dir
118
119
 
342
343
    @skipUnless(
343
344
        os.path.exists(ClickInstaller(None)._preload_path()),
344
345
        "preload bits not built; installing packages will fail")
345
 
    @mock.patch("click.install.package_install_hooks")
 
346
    @mock.patch("gi.repository.Click.package_install_hooks")
346
347
    def test_install(self, mock_package_install_hooks):
347
348
        path = self.make_fake_package(
348
349
            control_fields={
361
362
            control_scripts={"preinst": static_preinst},
362
363
            data_files={"foo": None})
363
364
        root = os.path.join(self.temp_dir, "root")
364
 
        db = ClickDB(root)
 
365
        db = Click.DB()
 
366
        db.add(root)
365
367
        installer = ClickInstaller(db)
366
368
        with self.make_framework("ubuntu-sdk-13.10"), \
367
369
             mock_quiet_subprocess_call():
425
427
            control_scripts={"preinst": static_preinst},
426
428
            data_files={"foo": None})
427
429
        root = os.path.join(self.temp_dir, "root")
428
 
        installer = ClickInstaller(ClickDB(root))
 
430
        db = Click.DB()
 
431
        db.add(root)
 
432
        installer = ClickInstaller(db)
429
433
        with self.make_framework("ubuntu-sdk-13.10"), \
430
434
             mock.patch("subprocess.call") as mock_call:
431
435
            mock_call.side_effect = call_side_effect
437
441
    @skipUnless(
438
442
        os.path.exists(ClickInstaller(None)._preload_path()),
439
443
        "preload bits not built; installing packages will fail")
440
 
    @mock.patch("click.install.package_install_hooks")
 
444
    @mock.patch("gi.repository.Click.package_install_hooks")
441
445
    def test_upgrade(self, mock_package_install_hooks):
 
446
        os.environ["TEST_QUIET"] = "1"
442
447
        path = self.make_fake_package(
443
448
            control_fields={
444
449
                "Package": "test-package",
460
465
        inst_dir = os.path.join(package_dir, "current")
461
466
        os.makedirs(os.path.join(package_dir, "1.0"))
462
467
        os.symlink("1.0", inst_dir)
463
 
        db = ClickDB(root)
 
468
        db = Click.DB()
 
469
        db.add(root)
464
470
        installer = ClickInstaller(db)
465
471
        with self.make_framework("ubuntu-sdk-13.10"), \
466
472
             mock_quiet_subprocess_call():
494
500
    @skipUnless(
495
501
        os.path.exists(ClickInstaller(None)._preload_path()),
496
502
        "preload bits not built; installing packages will fail")
497
 
    @mock.patch("click.install.package_install_hooks")
 
503
    @mock.patch("gi.repository.Click.package_install_hooks")
498
504
    def test_world_readable(self, mock_package_install_hooks):
499
505
        owner_only_file = os.path.join(self.temp_dir, "owner-only-file")
500
506
        touch(owner_only_file)
521
527
                "world-readable-dir": owner_only_dir,
522
528
            })
523
529
        root = os.path.join(self.temp_dir, "root")
524
 
        db = ClickDB(root)
 
530
        db = Click.DB()
 
531
        db.add(root)
525
532
        installer = ClickInstaller(db)
526
533
        with self.make_framework("ubuntu-sdk-13.10"), \
527
534
             mock_quiet_subprocess_call():
538
545
    @skipUnless(
539
546
        os.path.exists(ClickInstaller(None)._preload_path()),
540
547
        "preload bits not built; installing packages will fail")
541
 
    @mock.patch("click.install.package_install_hooks")
 
548
    @mock.patch("gi.repository.Click.package_install_hooks")
542
549
    @mock.patch("click.install.ClickInstaller._dpkg_architecture")
543
550
    def test_single_architecture(self, mock_dpkg_architecture,
544
551
                                 mock_package_install_hooks):
560
567
            },
561
568
            control_scripts={"preinst": static_preinst})
562
569
        root = os.path.join(self.temp_dir, "root")
563
 
        db = ClickDB(root)
 
570
        db = Click.DB()
 
571
        db.add(root)
564
572
        installer = ClickInstaller(db)
565
573
        with self.make_framework("ubuntu-sdk-13.10"), \
566
574
             mock_quiet_subprocess_call():
571
579
    @skipUnless(
572
580
        os.path.exists(ClickInstaller(None)._preload_path()),
573
581
        "preload bits not built; installing packages will fail")
574
 
    @mock.patch("click.install.package_install_hooks")
 
582
    @mock.patch("gi.repository.Click.package_install_hooks")
575
583
    @mock.patch("click.install.ClickInstaller._dpkg_architecture")
576
584
    def test_multiple_architectures(self, mock_dpkg_architecture,
577
585
                                    mock_package_install_hooks):
593
601
            },
594
602
            control_scripts={"preinst": static_preinst})
595
603
        root = os.path.join(self.temp_dir, "root")
596
 
        db = ClickDB(root)
 
604
        db = Click.DB()
 
605
        db.add(root)
597
606
        installer = ClickInstaller(db)
598
607
        with self.make_framework("ubuntu-sdk-13.10"), \
599
608
             mock_quiet_subprocess_call():