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()
|