Beispiel #1
0
    def test_decorator_enabled_decorator_when_feature_not_exist(self):
        @self.rollout.enabled('bar')
        def foo(name):
            return name

        with should.throw(RolloutException):
            foo('bazz')
Beispiel #2
0
    def test_missing_dependency(self):
        @self.inject
        def foo(missing=InjectorErrorsTests):
            pass

        with should.throw(LookupError):
            foo()
Beispiel #3
0
    def test_missing_dependency(self):
        @self.inject
        def foo(missing=InjectorErrorsTests):
            pass

        with should.throw(LookupError):
            foo()
Beispiel #4
0
    def test_decorator_enabled_decorator_when_feature_disabled(self):
        @self.rollout.enabled(self.FN)
        def foo(name):
            return name

        self.rollout.disable(self.FN)
        with should.throw(RolloutException):
            foo('bazz')
Beispiel #5
0
    def test_patch_hides_previous_deps(self):

        @self.inject
        def test(foo=InjectorPatchTests): pass

        self.inject.patch({})
        with should.throw(LookupError):
            test()

        self.inject.unpatch()
        test()
Beispiel #6
0
    def test_patch_hides_previous_deps(self):
        @self.inject
        def test(foo=InjectorPatchTests):
            pass

        self.inject.patch({})
        with should.throw(LookupError):
            test()

        self.inject.unpatch()
        test()
Beispiel #7
0
    def test_raises_exception_if_invalid_coroutine(self):
        @coroutine
        def to_xxx(destination=None):
            while True:
                value = yield
                value.to_xxx()

        register(to_xxx)
        pipeline = self.pipeline.to_xxx()

        with should.throw(AttributeError):
            pipeline()
Beispiel #8
0
    def test_raises_exception_if_invalid_coroutine(self):
        @coroutine
        def to_xxx(destination=None):
            while True:
                value = yield
                value.to_xxx()

        register(to_xxx)
        pipeline = self.pipeline.to_xxx()

        with should.throw(AttributeError):
            pipeline()
Beispiel #9
0
    def test_basic(self):
        result = 5
        result | should.be_integer()
        (1 + 1) | should_not.equal(1)
        "foo" | should.equal('foo')
        len([1, 2, 3]) | should.be_greater_than(2)

        result += 0.5

        result | should.equal(1 / 2 + 5)
        1 | should_not.eq(2)
        # Matchers not requiring a param can skip the call parens
        True | should.be_truthy

        # Check for exceptions with the context manager interface
        with should.throw(TypeError):
            raise TypeError('foo')

        with should.not_raise:  # will report a failure
            fp = open('does-not-exists.txt')

        # Apply our custom logic for a test
        'FooBarBaz' | should.pass_callback(lambda x: x[3:6] == 'Bar')
Beispiel #10
0
 def test_backend_should_not_be_none(self):
     rollout = Rollout(None)
     with should.throw(TypeError):
         rollout.backend
Beispiel #11
0
 def test_descriptor_no_type_found(self):
     Foo.DEPS.clear()
     Foo.DEPS[InjectorErrorsTests] = self
     with should.throw(LookupError):
         foo = Foo()
         foo.bar()
Beispiel #12
0
 def test_name_should_be_a_string(self):
     with should.throw(AttributeError):
         Feature(1, lambda x: True, '100')
Beispiel #13
0
 def test_percentage_should_be_a_number(self):
     with should.throw(AttributeError):
         Feature('foo', lambda x: True, 'bar')
Beispiel #14
0
 def test_get_functionalities_not_implemented(self):
     with should.throw(NotImplementedError):
         self.backend.get_functionalities()
Beispiel #15
0
 def test_name_cannot_be_None(self):
     with should.throw(AttributeError):
         Feature(None, lambda x: True, '100')
Beispiel #16
0
    def test_cannot_set_invalid_attributes(self):
        f = Feature('foo', lambda x: True, 100)

        with should.throw(AttributeError):
            f.bar
Beispiel #17
0
 def test_percentage_should_be_greater_than_0(self):
     with should.throw(AttributeError):
         Feature('foo', lambda x: True, -1)
Beispiel #18
0
 def test_percentage_should_be_lower_than_100(self):
     with should.throw(AttributeError):
         Feature('foo', lambda x: True, 101)
Beispiel #19
0
 def test_percentage_should_be_a_number(self):
     with should.throw(AttributeError):
         Feature('foo', lambda x: True, 'bar')
Beispiel #20
0
    def test_name_is_read_only(self):
        f = Feature("foo", lambda x: True, 20)

        with should.throw(RuntimeError):
            f.name = "bar"
Beispiel #21
0
 def test_get_functionalities_not_implemented(self):
     with should.throw(NotImplementedError):
         self.backend.get_functionalities()
Beispiel #22
0
 def test_missing_dependency_descriptor(self):
     egg = Eggs()
     with should.throw(LookupError):
         egg.missing_descriptor
Beispiel #23
0
 def test_positional_arg(self):
     foo = self.inject(lambda param=unittest.TestCase: None)
     with should.throw(TypeError):
         foo(self)
Beispiel #24
0
 def test_descriptor_no_type_found(self):
     Foo.DEPS.clear()
     Foo.DEPS[InjectorErrorsTests] = self
     with should.throw(LookupError):
         foo = Foo()
         foo.bar()
Beispiel #25
0
 def test_name_should_be_a_string(self):
     with should.throw(AttributeError):
         Feature(1, lambda x: True, '100')
Beispiel #26
0
 def test_percentage_should_be_greater_than_0(self):
     with should.throw(AttributeError):
         Feature('foo', lambda x: True, -1)
Beispiel #27
0
    def test_name_is_read_only(self):
        f = Feature("foo", lambda x: True, 20)

        with should.throw(RuntimeError):
            f.name = "bar"
Beispiel #28
0
 def test_missing_dependency_descriptor(self):
     egg = Eggs()
     with should.throw(LookupError):
         egg.missing_descriptor
Beispiel #29
0
 def test_percentage_should_be_lower_than_100(self):
     with should.throw(AttributeError):
         Feature('foo', lambda x: True, 101)
Beispiel #30
0
 def test_name_cannot_be_None(self):
     with should.throw(AttributeError):
         Feature(None, lambda x: True, '100')
Beispiel #31
0
    def test_cannot_set_invalid_attributes(self):
        f = Feature('foo', lambda x: True, 100)

        with should.throw(AttributeError):
            f.bar
Beispiel #32
0
    def test_unpatch_error(self):
        self.inject.patch({})
        self.inject.unpatch()

        with should.throw(RuntimeError):
            self.inject.unpatch()
Beispiel #33
0
 def test_positional_arg(self):
     foo = self.inject(lambda param=unittest.TestCase: None)
     with should.throw(TypeError):
         foo(self)
Beispiel #34
0
 def test_using_injector_as_decorator(self):
     with should.throw(RuntimeError):
         @injector
         def foo(): pass
Beispiel #35
0
    def test_unpatch_error(self):
        self.inject.patch({})
        self.inject.unpatch()

        with should.throw(RuntimeError):
            self.inject.unpatch()
Beispiel #36
0
 def test_set_percentage_to_negative(self):
     with should.throw(AttributeError):
         self.rollout.set_percentage(self.FN, -1)
Beispiel #37
0
 def test_proxy_dependency_missing(self):
     dm = DependencyMap()
     l = dm.proxy("hi")
     with should.throw(LookupError):
         l.foo()
Beispiel #38
0
 def test_proxy_dependency_missing(self):
     dm = DependencyMap()
     l = dm.proxy("hi")
     with should.throw(LookupError):
         l.foo()
Beispiel #39
0
    def test_using_injector_as_decorator(self):
        with should.throw(RuntimeError):

            @injector
            def foo():
                pass
def pyshould_test_sample():
    import unittest
    # from pyshould import *
    import pyshould.patch
    from pyshould import should
    result | should.be_integer()
    (1 + 1) | should_not.equal(1)
    "foo" | should.equal('foo')
    len([1, 2, 3]) | should.be_greater_than(2)
    result | should.equal(1 / 2 + 5)
    1 | should_not.eq(2)
    # Matchers not requiring a param can skip the call parens
    True | should.be_truthy
    # Check for exceptions with the context manager interface
    with should.throw(TypeError):
        raise TypeError('foo')
    with should.not_raise:  # will report a failure
        fp = open('does-not-exists.txt')
    # Apply our custom logic for a test
    'FooBarBaz' | should.pass_callback(lambda x: x[3:6] == 'Bar')
    should.be_an_integer.or_string.and_equal(1)
    # (integer) OR (string AND equal 1)
    should.be_an_integer.or_a_float.or_a_string
    # (integer) OR (float) OR (string)
    should.be_an_integer.or_a_string.and_equal_to(10).or_a_float
    # (integer) OR (string AND equal 10) OR (float)
    should.be_an_integer.or_a_string.but_less_than(10)
    # (integer OR string) AND (less than 10)
    # Note: we can use spacing to make them easier to read
    should.be_an_integer.or_a_string.and_equal(0).or_a_float
    # (integer) OR (string AND equal 0) OR (float)
    # Note: in this case we use capitalization to make them more obvious
    should.be_an_integer.Or_a_string.And_equal(1).But_Not_be_a_float
    # ( (integer) OR (string AND equal 1) ) AND (not float)
    # Note: if no matchers are given the last one is used
    should.be_equal_to(10).Or(20).Or(30)
    # (equal 10) OR (equal 20) OR (equal 30)
    # Note: If no combinator is given AND is used by default
    should.integer.greater_than(10).less_than(20)
    # (integer) AND (greater than 10) AND (less than 20)
    # Note: But by using should_either we can set OR as default
    should_either.equal(10).equal(20).equal(30)

    class TestSequenceFunctions1(unittest.TestCase):
        def setUp(self):
            self.seq = list(range(10))

        def test_shuffle(self):
            # make sure the shuffled sequence does not lose any elements
            random.shuffle(self.seq)
            self.seq.sort()
            self.assertEqual(self.seq, list(range(10)))
            # should raise an exception for an immutable sequence
            self.assertRaises(TypeError, random.shuffle, (1, 2, 3))

        def test_choice(self):
            element = random.choice(self.seq)
            a = 10
            a | should.gt(20)

        def test_sample(self):
            with self.assertRaises(ValueError):
                random.sample(self.seq, 20)
            for element in random.sample(self.seq, 5):
                self.assertTrue(element in self.seq)

    unittest.main()