def test_retrieve_a_variant(self): fn = "FOO" _variants = ["foo", "bar", "bazz"] self.backend.add_functionality(Feature(fn, variants=_variants)) f = self.backend.get_functionality(fn) f.name | should.eql(fn) f.percentage | should.eql(100) self.backend.variant(fn, 'juan') | should.be_in(f.variants) self.backend.variant(fn, 'juan2') | should.be_in(f.variants)
def test_executes_catch_only_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield v = value.to_xxx() if destination is not None: destination.send(v) class Foo(object): def __init__(self, value): self.value = value def to_xxx(self): return self def __repr__(self): return self.value register(to_xxx) values = (Foo('10'), Foo('20'), Foo('30'), '1', '2') _pipeline = (pipeline((x for x in values)).to_xxx().catch( collect(self.recollector)).collect(self.recollector)) _pipeline() all_of([x for (i, x) in enumerate(values) if i < 4]) | should.be_in( self.recollector) len(self.recollector) | should.be(4)
def test_add_a_functionality_with_variants(self): fn = "FOO" _variants = ["foo", "bar", "bazz"] self.backend.add_functionality(Feature(fn, variants=_variants)) f = self.backend._get_functionality(fn) f.name | should.eql(fn) f.percentage | should.eql(100) all_of(["foo", "bar", "bazz"]) | should.be_in(f.variants)
def is_running(self): start_sbo = os.getenv("TEST_ACCEPTANCE_START_SBO") start_sbo | should_not.be_none.desc("TEST_ACCEPTANCE_START_SBO is set") start_sbo | should.be_in({"local", "operator-hub"}) if start_sbo == "local": os.getenv("TEST_ACCEPTANCE_SBO_STARTED") | should_not.start_with("FAILED").desc("TEST_ACCEPTANCE_SBO_STARTED is not FAILED") elif start_sbo == "operator-hub": return False return self.check_resources()
def test_executes_catch_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield value.to_xxx() register(to_xxx) _pipeline = (pipeline( (x for x in ('foo', 'bar', 'bazz'))).uppercase().to_xxx().catch( collect(self.recollector))) _pipeline() 'FOO' | should.be_in(self.recollector) len(self.recollector) | should.be(1)
def test_executes_catch_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield value.to_xxx() register(to_xxx) _pipeline = ( pipeline((x for x in ('foo', 'bar', 'bazz'))) .uppercase() .to_xxx() .catch(collect(self.recollector)) ) _pipeline() 'FOO' | should.be_in(self.recollector) len(self.recollector) | should.be(1)
def test_executes_catch_only_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield v = value.to_xxx() if destination is not None: destination.send(v) class Foo(object): def __init__(self, value): self.value = value def to_xxx(self): return self def __repr__(self): return self.value register(to_xxx) values = (Foo('10'), Foo('20'), Foo('30'), '1', '2') _pipeline = ( pipeline((x for x in values)) .to_xxx() .catch(collect(self.recollector)) .collect(self.recollector) ) _pipeline() all_of( [x for (i, x) in enumerate(values) if i < 4] ) | should.be_in(self.recollector) len(self.recollector) | should.be(4)
def test_chains_coroutines(self): self.pipeline() all_of(('FOO', 'BAR', 'BAZZ')) | should.be_in(self.recollector) len(self.recollector) | should.be(3)
def test_create_feature_with_variants(self): FN = 'bar' _variants = ['BAR', 'BAZZ'] self.rollout.add_func(FN, variants=_variants) self.rollout.set_percentage(FN, 100) self.rollout.variant('bar', 'user') | should.be_in(_variants)
def test_register_two_functionalities(self): self.rollout.add_func('bar', lambda x: x.id, percentage=0) self.rollout.backend.get_functionalities() | should.have_len(2) all_of([self.FN, 'bar']) | should.be_in(self.rollout.backend.get_functionalities())