コード例 #1
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_kwargs(self):
        """
        Tests when a function has **kwargs and it was expected.
        """
        def f(**kwargs):
            pass

        verify_callable_argspec(f, expect_kwargs=True)
コード例 #2
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_not_callable(self):
        """
        Check the results of a non-callable object.
        """
        not_callable = 'a'

        with self.assertRaises(NotCallable):
            verify_callable_argspec(not_callable)
コード例 #3
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_default(self):
        """
        Tests when an argument expects a default and it is present.
        """
        def f(a=1):
            pass

        verify_callable_argspec(f, [Argument('a', 1)])
コード例 #4
0
    def test_not_callable(self):
        """
        Check the results of a non-callable object.
        """
        not_callable = "a"

        with pytest.raises(NotCallable):
            verify_callable_argspec(not_callable)
コード例 #5
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_ignore_default(self):
        """
        Tests that ignoring defaults works as intended.
        """
        def f(a=1):
            pass

        verify_callable_argspec(f, [Argument('a')])
コード例 #6
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_not_callable(self):
        """
        Check the results of a non-callable object.
        """
        not_callable = 'a'

        with self.assertRaises(NotCallable):
            verify_callable_argspec(not_callable)
コード例 #7
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_kwargs(self):
        """
        Tests when a function has **kwargs and it was expected.
        """
        def f(**kwargs):
            pass

        verify_callable_argspec(f, expect_kwargs=True)
コード例 #8
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_ignore_default(self):
        """
        Tests that ignoring defaults works as intended.
        """
        def f(a=1):
            pass

        verify_callable_argspec(f, [Argument('a')])
コード例 #9
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_default(self):
        """
        Tests when an argument expects a default and it is present.
        """
        def f(a=1):
            pass

        verify_callable_argspec(f, [Argument('a', 1)])
コード例 #10
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_no_default(self):
        """
        Tests when an argument expects a default and it is not present.
        """
        def f(a):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('a', 1)])
コード例 #11
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_unexcpected_starargs(self):
        """
        Tests a function that unexpectedly accepts *args.
        """
        def f(*args):
            pass

        with self.assertRaises(UnexpectedStarargs):
            verify_callable_argspec(f, expect_starargs=False)
コード例 #12
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_out_of_order(self):
        """
        Tests the case where arguments are not in the correct order.
        """
        def f(a, b):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('b'), Argument('a')])
コード例 #13
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_no_kwargs(self):
        """
        Tests when a function does not have **kwargs and it was expected.
        """
        def f():
            pass

        with self.assertRaises(NoKwargs):
            verify_callable_argspec(f, expect_kwargs=True)
コード例 #14
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_unexcpected_starargs(self):
        """
        Tests a function that unexpectedly accepts *args.
        """
        def f(*args):
            pass

        with self.assertRaises(UnexpectedStarargs):
            verify_callable_argspec(f, expect_starargs=False)
コード例 #15
0
    def test_no_starargs(self):
        """
        Tests when a function does not have *args and it was expected.
        """
        def f(a):
            pass

        with pytest.raises(NoStarargs):
            verify_callable_argspec(f, expect_starargs=True)
コード例 #16
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_out_of_order(self):
        """
        Tests the case where arguments are not in the correct order.
        """
        def f(a, b):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('b'), Argument('a')])
コード例 #17
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_no_default(self):
        """
        Tests when an argument expects a default and it is not present.
        """
        def f(a):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('a', 1)])
コード例 #18
0
    def test_out_of_order(self):
        """
        Tests the case where arguments are not in the correct order.
        """
        def f(a, b):
            pass

        with pytest.raises(MismatchedArguments):
            verify_callable_argspec(f, [Argument("b"), Argument("a")])
コード例 #19
0
    def test_unexpected_kwargs(self):
        """
        Tests a function that unexpectedly accepts **kwargs.
        """
        def f(**kwargs):
            pass

        with pytest.raises(UnexpectedKwargs):
            verify_callable_argspec(f, expect_kwargs=False)
コード例 #20
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_no_kwargs(self):
        """
        Tests when a function does not have **kwargs and it was expected.
        """
        def f():
            pass

        with self.assertRaises(NoKwargs):
            verify_callable_argspec(f, expect_kwargs=True)
コード例 #21
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_wrong_default(self):
        """
        Tests the case where a default is expected, but the default provided
        does not match the one expected.
        """
        def f(a=1):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('a', 2)])
コード例 #22
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_wrong_default(self):
        """
        Tests the case where a default is expected, but the default provided
        does not match the one expected.
        """
        def f(a=1):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('a', 2)])
コード例 #23
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_arg_subset(self):
        """
        Tests when the args are a subset of the expectations.
        """
        def f(a, b):
            pass

        with self.assertRaises(NotEnoughArguments):
            verify_callable_argspec(
                f, [Argument('a'), Argument('b'), Argument('c')]
            )
コード例 #24
0
    def test_arg_subset(self):
        """
        Tests when the args are a subset of the expectations.
        """
        def f(a, b):
            pass

        with pytest.raises(NotEnoughArguments):
            verify_callable_argspec(
                f, [Argument("a"), Argument("b"),
                    Argument("c")])
コード例 #25
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_arg_subset(self):
        """
        Tests when the args are a subset of the expectations.
        """
        def f(a, b):
            pass

        with self.assertRaises(NotEnoughArguments):
            verify_callable_argspec(
                f, [Argument('a'), Argument('b'),
                    Argument('c')])
コード例 #26
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_ignore_starargs(self):
        """
        Tests checking a function ignoring the presence of *args.
        """
        def f(*args):
            pass

        def g():
            pass

        verify_callable_argspec(f, expect_starargs=Argument.ignore)
        verify_callable_argspec(g, expect_starargs=Argument.ignore)
コード例 #27
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_ignore_starargs(self):
        """
        Tests checking a function ignoring the presence of *args.
        """
        def f(*args):
            pass

        def g():
            pass

        verify_callable_argspec(f, expect_starargs=Argument.ignore)
        verify_callable_argspec(g, expect_starargs=Argument.ignore)
コード例 #28
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_bound_method(self):
        class C(object):
            def f(self, a, b):
                pass

        method = C().f

        verify_callable_argspec(method, [Argument('a'), Argument('b')])
        with self.assertRaises(NotEnoughArguments):
            # Assert that we don't count self.
            verify_callable_argspec(
                method,
                [Argument('self'), Argument('a'), Argument('b')],
            )
コード例 #29
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_bound_method(self):
        class C:
            def f(self, a, b):
                pass

        method = C().f

        verify_callable_argspec(method, [Argument('a'), Argument('b')])
        with self.assertRaises(NotEnoughArguments):
            # Assert that we don't count self.
            verify_callable_argspec(
                method,
                [Argument('self'),
                 Argument('a'), Argument('b')],
            )
コード例 #30
0
    def test_bound_method(self):
        class C(object):
            def f(self, a, b):
                pass

        method = C().f

        verify_callable_argspec(method, [Argument("a"), Argument("b")])
        with self.assertRaises(NotEnoughArguments):
            # Assert that we don't count self.
            verify_callable_argspec(
                method,
                [Argument("self"),
                 Argument("a"), Argument("b")],
            )
コード例 #31
0
ファイル: events.py プロジェクト: MridulS/zipline
    def __new__(cls, rule=None, callback=None, check_args=True):
        callback = callback or (lambda *args, **kwargs: None)
        if check_args:
            # Check the callback provided.
            verify_callable_argspec(callback, [
                Argument('context' if check_args else Argument.ignore),
                Argument('data' if check_args else Argument.ignore)
            ])

            # Make sure that the rule's should_trigger is valid. This will
            # catch potential errors much more quickly and give a more helpful
            # error.
            verify_callable_argspec(getattr(rule, 'should_trigger'),
                                    [Argument('dt')])

        return super(cls, cls).__new__(cls, rule=rule, callback=callback)
コード例 #32
0
ファイル: events.py プロジェクト: shs161/zipline
    def __new__(cls, rule=None, callback=None, check_args=True):
        callback = callback or (lambda *args, **kwargs: None)
        if check_args:
            # Check the callback provided.
            verify_callable_argspec(
                callback,
                [Argument('context' if check_args else Argument.ignore),
                 Argument('data' if check_args else Argument.ignore)]
            )

            # Make sure that the rule's should_trigger is valid. This will
            # catch potential errors much more quickly and give a more helpful
            # error.
            verify_callable_argspec(
                getattr(rule, 'should_trigger'),
                [Argument('dt')]
            )

        return super(cls, cls).__new__(cls, rule=rule, callback=callback)
コード例 #33
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_ignore_args(self):
        """
        Tests the ignore argument list feature.
        """
        def f(a):
            pass

        def g():
            pass

        h = 'not_callable'

        verify_callable_argspec(f)
        verify_callable_argspec(g)
        with self.assertRaises(NotCallable):
            verify_callable_argspec(h)
コード例 #34
0
    def test_ignore_args(self):
        """
        Tests the ignore argument list feature.
        """
        def f(a):
            pass

        def g():
            pass

        h = "not_callable"

        verify_callable_argspec(f)
        verify_callable_argspec(g)
        with pytest.raises(NotCallable):
            verify_callable_argspec(h)
コード例 #35
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_ignore_args(self):
        """
        Tests the ignore argument list feature.
        """
        def f(a):
            pass

        def g():
            pass

        h = 'not_callable'

        verify_callable_argspec(f)
        verify_callable_argspec(g)
        with self.assertRaises(NotCallable):
            verify_callable_argspec(h)
コード例 #36
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_any_default(self):
        """
        Tests the any_default option.
        """
        def f(a=1):
            pass

        def g(a=2):
            pass

        def h(a):
            pass

        expected_args = [Argument('a', Argument.any_default)]
        verify_callable_argspec(f, expected_args)
        verify_callable_argspec(g, expected_args)
        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(h, expected_args)
コード例 #37
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_ignore_name(self):
        """
        Tests ignoring a param name.
        """
        def f(a):
            pass

        def g(b):
            pass

        def h(c=1):
            pass

        expected_args = [Argument(Argument.ignore, Argument.no_default)]
        verify_callable_argspec(f, expected_args)
        verify_callable_argspec(f, expected_args)
        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(h, expected_args)
コード例 #38
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_ignore_name(self):
        """
        Tests ignoring a param name.
        """
        def f(a):
            pass

        def g(b):
            pass

        def h(c=1):
            pass

        expected_args = [Argument(Argument.ignore, Argument.no_default)]
        verify_callable_argspec(f, expected_args)
        verify_callable_argspec(f, expected_args)
        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(h, expected_args)
コード例 #39
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_any_default(self):
        """
        Tests the any_default option.
        """
        def f(a=1):
            pass

        def g(a=2):
            pass

        def h(a):
            pass

        expected_args = [Argument('a', Argument.any_default)]
        verify_callable_argspec(f, expected_args)
        verify_callable_argspec(g, expected_args)
        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(h, expected_args)
コード例 #40
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_arg_superset(self):
        def f(a, b, c):
            pass

        with self.assertRaises(TooManyArguments):
            verify_callable_argspec(f, [Argument('a'), Argument('b')])
コード例 #41
0
ファイル: test_argcheck.py プロジェクト: 1TTT9/zipline
    def test_mismatched_args(self):
        def f(a, b):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('c'), Argument('d')])
コード例 #42
0
    def test_arg_superset(self):
        def f(a, b, c):
            pass

        with pytest.raises(TooManyArguments):
            verify_callable_argspec(f, [Argument("a"), Argument("b")])
コード例 #43
0
    def test_mismatched_args(self):
        def f(a, b):
            pass

        with pytest.raises(MismatchedArguments):
            verify_callable_argspec(f, [Argument("c"), Argument("d")])
コード例 #44
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_arg_superset(self):
        def f(a, b, c):
            pass

        with self.assertRaises(TooManyArguments):
            verify_callable_argspec(f, [Argument('a'), Argument('b')])
コード例 #45
0
ファイル: test_argcheck.py プロジェクト: fangchenli/zipline
    def test_mismatched_args(self):
        def f(a, b):
            pass

        with self.assertRaises(MismatchedArguments):
            verify_callable_argspec(f, [Argument('c'), Argument('d')])