Example #1
0
 def test_add_a_functionality_with_percentage(self):
     fn = "FOO"
     self.backend.add_functionality(Feature(fn, None, 50))
     self.backend.get_functionalities() | should.have_len(1)
     f, users = self.backend._get_functionality(fn)
     f.name | should.eql(fn)
     f.percentage | should.eql(50)
     users | should.be_empty().and_array()
Example #2
0
    def test_warns_when_unneeded(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            foo = self.inject(lambda: True)

            w | should.have_len(1)
            w[0].category | should.be(UserWarning)
Example #3
0
 def test_add_a_functionality_with_percentage(self):
     fn = "FOO"
     self.backend.add_functionality(Feature(fn, None, 50))
     self.backend.get_functionalities() | should.have_len(1)
     f, users = self.backend._get_functionality(fn)
     f.name | should.eql(fn)
     f.percentage | should.eql(50)
     users | should.be_empty().and_array()
Example #4
0
    def test_warns_when_unneeded(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            foo = self.inject(lambda: True)

            w | should.have_len(1)
            w[0].category | should.be(UserWarning)
Example #5
0
 def test_add_existing_an_user(self):
     fn = "FOO"
     self.backend.add_functionality(Feature(fn))
     self.backend.get_functionalities() | should.have_len(1)
     f, users = self.backend._get_functionality(fn)
     users | should.be_empty().and_array()
     self.backend.add(fn, "bar")
     self.backend.add(fn, "bar")
     f, users = self.backend._get_functionality(fn)
     users | should.eql(['bar'])
Example #6
0
 def test_add_existing_an_user(self):
     fn = "FOO"
     self.backend.add_functionality(Feature(fn))
     self.backend.get_functionalities() | should.have_len(1)
     f, users = self.backend._get_functionality(fn)
     users | should.be_empty().and_array()
     self.backend.add(fn, "bar")
     self.backend.add(fn, "bar")
     f, users = self.backend._get_functionality(fn)
     users | should.eql(['bar'])
Example #7
0
 def test_add_a_disabled_functionality_with_percentage(self):
     fn = "FOO"
     func = Feature(fn, None, 50)
     func.enabled = False
     self.backend.add_functionality(func)
     self.backend.get_functionalities() | should.have_len(1)
     f, users = self.backend._get_functionality(fn)
     f.name | should.eql(fn)
     f.percentage | should.eql(50)
     f.enabled | should.be_falsy()
     users | should.be_empty().and_array()
Example #8
0
 def test_add_a_disabled_functionality_with_percentage(self):
     fn = "FOO"
     func = Feature(fn, None, 50)
     func.enabled = False
     self.backend.add_functionality(func)
     self.backend.get_functionalities() | should.have_len(1)
     f, users = self.backend._get_functionality(fn)
     f.name | should.eql(fn)
     f.percentage | should.eql(50)
     f.enabled | should.be_falsy()
     users | should.be_empty().and_array()
Example #9
0
    def test_no_warns_when_unneeded(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            class NoUse(object):
                __metaclass__ = MetaInject(self.inject)

                def foo(self):
                    pass

            NoUse()

            w | should.have_len(0)
Example #10
0
    def test_no_warns_when_unneeded(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            class NoUse(object):
                __metaclass__ = MetaInject(self.inject)

                def foo(self):
                    pass

            NoUse()

            w | should.have_len(0)
Example #11
0
    def test_deprecated_property(self):
        @self.inject
        def test(foo=InjectorPatchTests):
            return foo

        self.inject.dependencies = {InjectorPatchTests: 'foo'}

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            test() | should.eql('foo')

            w | should.have_len(1)
            w[0].category | should.be(UserWarning)
Example #12
0
    def test_deprecated_property(self):
        @self.inject
        def test(foo=InjectorPatchTests):
            return foo

        self.inject.dependencies = {InjectorPatchTests: 'foo'}

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            test() | should.eql('foo')

            w | should.have_len(1)
            w[0].category | should.be(UserWarning)
Example #13
0
 def test_overrides_a_functionality_with_same_name(self):
     self.rollout.add_func(self.FN, lambda x: x.id)
     self.rollout.backend.get_functionalities() | should.have_len(1)
Example #14
0
 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())
Example #15
0
 def test_register_a_functionality(self):
     self.rollout.backend.get_functionalities() | should.have_len(1)