Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/client/solver.py
blob: 6e35a500d1045e24e4e3e95d894f87851e0fab9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# sugar-lint: disable

import os

from __init__ import tests

from sugar_network.client import IPCConnection, packagekit, solver, clones
from sugar_network.toolkit import lsb_release


class SolverTest(tests.Test):

    def test_select_architecture(self):
        host_arch = os.uname()[-1]
        all_arches = [i for i in solver.machine_ranks.keys() if i]

        self.assertEqual(host_arch, solver.select_architecture(
            sorted(all_arches, cmp=lambda x, y: cmp(solver.machine_ranks[x], solver.machine_ranks[y]))))
        self.assertEqual(host_arch, solver.select_architecture(
            sorted(all_arches, cmp=lambda x, y: cmp(solver.machine_ranks[y], solver.machine_ranks[x]))))
        self.assertEqual(host_arch, solver.select_architecture([host_arch]))
        self.assertEqual(host_arch, solver.select_architecture(['foo', host_arch, 'bar']))

    def test_FirstSuccessfulSolveMighMissImplsDueToPackageDeps(self):
        self.override(packagekit, 'resolve', lambda names:
                dict([(i, {'name': i, 'pk_id': i, 'version': '0', 'arch': '*', 'installed': True}) for i in names]))

        self.touch(('Activities/1/activity/activity.info', [
            '[Activity]',
            'name = name',
            'bundle_id = bundle_id',
            'exec = false',
            'icon = icon',
            'activity_version = 1',
            'license = Public Domain',
            ]))
        self.touch(('Activities/2/activity/activity.info', [
            '[Activity]',
            'name = name',
            'bundle_id = bundle_id',
            'exec = false',
            'icon = icon',
            'activity_version = 2',
            'license = Public Domain',
            'requires = dep',
            ]))

        home_volume = self.start_online_client()
        clones.populate(home_volume['context'], ['Activities'])
        ipc = IPCConnection()

        ipc.post(['context'], {
            'guid': 'dep',
            'type': 'package',
            'title': 'title',
            'summary': 'summary',
            'description': 'description',
            'aliases': {
                lsb_release.distributor_id(): {
                    'status': 'success',
                    'binary': [['dep.bin']],
                    },
                },
            })

        solution = solver.solve(ipc, 'bundle_id', ['stable'])
        self.assertEqual(
                2, len(solution))
        self.assertEqual(
                ('bundle_id', '2'),
                (solution[0]['context'], solution[0]['version']))
        self.assertEqual(
                ('dep', '0'),
                (solution[1]['context'], solution[1]['version']))


if __name__ == '__main__':
    tests.main()