~therp-nl/openerp-web/7.0-lp1013636-x2m_honour_required_attribute

« back to all changes in this revision

Viewing changes to addons/web/test/test_serving_base.py

[MERGE] from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
import random
 
4
import unittest2
 
5
 
 
6
from ..controllers.main import topological_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 = topological_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)