def test_collate_cf_mismatch(): with raises(AssertionError): collate_rules('', [ ([('a', 'A0')], 0), ]) with raises(AssertionError): collate_rules('abc', [ ([('D', 'D0')], 0), ])
def test_collate_conflict(caplog): expected = { 'A0': { 'B0': { None: 2 }, None: { None: 5 } }, None: { 'B1': { None: 3 }, None: { None: 0 } } } with assert_logs(caplog, ERROR): assert collate_rules('abc', [ ([], 0), ([('a', 'A0')], 1), ([('a', 'A0'), ('b', 'B0')], 2), ([('b', 'B1')], 3), ([('a', 'A0')], 5), ]) == expected
def test_collate(): expected = { 'A0': { 'B0': { None: 2 }, None: { None: 1 } }, None: { 'B1': { None: 3 }, None: { None: 0 } } } assert collate_rules('abc', [([], 0), ([('a', 'A0')], 1), ([('a', 'A0'), ('b', 'B0')], 2), ([('b', 'B1')], 3)]) == expected
def update(self, client, rules: Iterable[Tuple[T, QueriedRule]]): """ Update a setting's rules from a client Args: client: The client updating the setting. rules: An iterable of rules to collate. """ if self.last_ruleset: last_client = self.last_ruleset.client() if last_client and last_client is not client: logger.warning( 'setting received rule set from multiple clients', extra={ 'setting': self.name, 'new_client': client, 'last_client': last_client }) validated_rules = [(rule.context_features, value) for (value, rule) in rules] root = collate_rules(self.configurable_features, validated_rules) self.last_ruleset = RuleSet(ref(client), root)
def test_collate_conflict_nill(caplog): with assert_logs(caplog, ERROR): assert collate_rules('', [([], 0), ([], 1)]) == 1
def test_collate_norules_nocf(): assert collate_rules('', []) == {}
def test_collate_norules(features): assert collate_rules(features, []) == {}
def test_collate_null(): assert collate_rules('', [([], 0)]) == 0