[MERGE] trunk
[odoo/odoo.git] / addons / web / tests / test_serving_base.py
1 # -*- coding: utf-8 -*-
2
3 import random
4 import unittest2
5
6 from ..controllers.main import module_topological_sort as sort
7
8 def sample(population):
9     return random.sample(
10         population,
11             random.randint(0, min(len(population), 5)))
12
13 class TestModulesLoading(unittest2.TestCase):
14     def setUp(self):
15         self.mods = map(str, range(1000))
16     def test_topological_sort(self):
17         random.shuffle(self.mods)
18         modules = [
19             (k, sample(self.mods[:i]))
20             for i, k in enumerate(self.mods)]
21         random.shuffle(modules)
22         ms = dict(modules)
23
24         seen = set()
25         sorted_modules = sort(ms)
26         for module in sorted_modules:
27             deps = ms[module]
28             self.assertGreaterEqual(
29                 seen, set(deps),
30                         'Module %s (index %d), ' \
31                         'missing dependencies %s from loaded modules %s' % (
32                     module, sorted_modules.index(module), deps, seen
33                 ))
34             seen.add(module)