File: make_runtime_features_utilities_unittest.py

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (89 lines) | stat: -rw-r--r-- 3,248 bytes parent folder | download | duplicates (11)
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
80
81
82
83
84
85
86
87
88
89
# Copyright 2019 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import unittest

import make_runtime_features_utilities as util
from blinkbuild.name_style_converter import NameStyleConverter


def _feature(name,
             depends_on=[],
             implied_by=[],
             origin_trial_feature_name=None):
    return {
        'name': name,
        'depends_on': depends_on,
        'implied_by': implied_by,
        'origin_trial_feature_name': origin_trial_feature_name
    }


class MakeRuntimeFeaturesUtilitiesTest(unittest.TestCase):
    def test_cycle(self):
        # Cycle: 'c' => 'd' => 'e' => 'c'
        with self.assertRaisesRegexp(
                AssertionError, 'Cycle found in depends_on/implied_by graph'):
            util.origin_trials([
                _feature('a', depends_on=['b']),
                _feature('b'),
                _feature('c', implied_by=['a', 'd']),
                _feature('d', depends_on=['e']),
                _feature('e', implied_by=['c'])
            ])

    def test_bad_dependency(self):
        with self.assertRaisesRegexp(AssertionError,
                                     'a: Depends on non-existent-feature: x'):
            util.origin_trials([_feature('a', depends_on=['x'])])

    def test_bad_implication(self):
        with self.assertRaisesRegexp(AssertionError,
                                     'a: Implied by non-existent-feature: x'):
            util.origin_trials([_feature('a', implied_by=['x'])])
        with self.assertRaisesRegexp(
                AssertionError,
                'a: A feature must be in origin trial if implied by an origin trial feature: b'
        ):
            util.origin_trials([
                _feature('a', implied_by=['b']),
                _feature('b', origin_trial_feature_name='b')
            ])

    def test_both_dependency_and_implication(self):
        with self.assertRaisesRegexp(
                AssertionError,
                'c: Only one of implied_by and depends_on is allowed'):
            util.origin_trials([
                _feature('a'),
                _feature('b'),
                _feature('c', depends_on=['a'], implied_by=['b'])
            ])

    def test_origin_trials(self):
        features = [
            _feature(NameStyleConverter('a')),
            _feature(
                NameStyleConverter('b'),
                depends_on=['a'],
                origin_trial_feature_name='b'),
            _feature(NameStyleConverter('c'), depends_on=['b']),
            _feature(NameStyleConverter('d'), depends_on=['b']),
            _feature(NameStyleConverter('e'), depends_on=['d'])
        ]
        self.assertSetEqual(util.origin_trials(features), {'b', 'c', 'd', 'e'})

        features = [
            _feature('a'),
            _feature('b', depends_on=['x', 'y']),
            _feature('c', depends_on=['y', 'z']),
            _feature('x', depends_on=['a']),
            _feature('y', depends_on=['x'], origin_trial_feature_name='y'),
            _feature('z', depends_on=['y'])
        ]
        self.assertSetEqual(util.origin_trials(features), {'b', 'c', 'y', 'z'})


if __name__ == "__main__":
    unittest.main()