# Path: grappa/operators/callable.py
# class CallableOperator(Operator):
#     """
#     Asserts if a given subject is a callable type or an object that
#     implements ``__call__()`` magic method.
# 
#     Example::
# 
#         # Should style
#         (lambda x: x) | should.be.callable
# 
#         # Should style - negation form
#         None | should.not_be.callable
# 
#         # Expect style
#         (lambda x: x) | expect.to.be.callable
# 
#         # Expect style - negation form
#         None | expect.to_not.be.callable
#     """
# 
#     # Is the operator a keyword
#     kind = Operator.Type.ACCESSOR
# 
#     # Disable diff report
#     show_diff = False
# 
#     # Operator keywords
#     operators = ('callable',)
# 
#     # Expected template message
#     expected_message = Operator.Dsl.Message(
#         'a callable object, such as a function or method',
#         'a non callable object, such as a function or method'
#     )
# 
#     # Subject template message
#     subject_message = Operator.Dsl.Message(
#         'an object which is a "{type}" type'
#     )
# 
#     # Assertion information
#     information = (
#         Operator.Dsl.Help(
#             Operator.Dsl.Description(
#                 'Callable objects can be tested via "callable(x)" Python',
#                 'built-in function.'
#             ),
#             Operator.Dsl.Reference(
#                 'https://docs.python.org/3/library/functions.html#callable'
#             ),
#         ),
#         Operator.Dsl.Help(
#             Operator.Dsl.Description(
#                 'Callable objects in Python are functions, methods, classes,',
#                 'or any other object that implements "__call__()" method.'
#             ),
#             Operator.Dsl.Reference(
#                 'http://stackoverflow.com/a/2436614'
#             ),
#         ),
#     )
# 
#     def match(self, value):
#         if value is None:
#             return False, ['a callable value cannot be "None"']
# 
#         # Custom expectations messages
#         self.expected = 'an callable object, such as a function or method'
#         self.value = value
# 
#         return callable(value), []


import pytest
from grappa.operators.callable import CallableOperator
    CallableOperator | should.be.callable
    CallableOperator.match | should.be.callable

    with pytest.raises(AssertionError):
        tuple() | should.be.callable

    with pytest.raises(AssertionError):
        0 | should.be.callable


def test_expect_callable(expect):
    test_expect_callable | expect.to.be.callable
    (lambda x: x) | expect.to.be.callable
    CallableOperator | expect.to.be.callable
    CallableOperator.match | expect.to.be.callable

    with pytest.raises(AssertionError):
        tuple() | expect.to.be.callable

    with pytest.raises(AssertionError):
        0 | expect.to.be.callable


def test_callable_operator(ctx):
    assert CallableOperator(ctx).match(lambda x: x) == (True, [])
    assert CallableOperator(ctx).match(CallableOperator) == (True, [])
    assert CallableOperator(ctx).match(CallableOperator.match) == (True, [])

    assert CallableOperator(ctx).match(0) == (False, [])
    assert CallableOperator(ctx).match('foo') == (False, [])

# Path: grappa/operators/callable.py
# class CallableOperator(Operator):
#     """
#     Asserts if a given subject is a callable type or an object that
#     implements ``__call__()`` magic method.
# 
#     Example::
# 
#         # Should style
#         (lambda x: x) | should.be.callable
# 
#         # Should style - negation form
#         None | should.not_be.callable
# 
#         # Expect style
#         (lambda x: x) | expect.to.be.callable
# 
#         # Expect style - negation form
#         None | expect.to_not.be.callable
#     """
# 
#     # Is the operator a keyword
#     kind = Operator.Type.ACCESSOR
# 
#     # Disable diff report
#     show_diff = False
# 
#     # Operator keywords
#     operators = ('callable',)
# 
#     # Expected template message
#     expected_message = Operator.Dsl.Message(
#         'a callable object, such as a function or method',
#         'a non callable object, such as a function or method'
#     )
# 
#     # Subject template message
#     subject_message = Operator.Dsl.Message(
#         'an object which is a "{type}" type'
#     )
# 
#     # Assertion information
#     information = (
#         Operator.Dsl.Help(
#             Operator.Dsl.Description(
#                 'Callable objects can be tested via "callable(x)" Python',
#                 'built-in function.'
#             ),
#             Operator.Dsl.Reference(
#                 'https://docs.python.org/3/library/functions.html#callable'
#             ),
#         ),
#         Operator.Dsl.Help(
#             Operator.Dsl.Description(
#                 'Callable objects in Python are functions, methods, classes,',
#                 'or any other object that implements "__call__()" method.'
#             ),
#             Operator.Dsl.Reference(
#                 'http://stackoverflow.com/a/2436614'
#             ),
#         ),
#     )
# 
#     def match(self, value):
#         if value is None:
#             return False, ['a callable value cannot be "None"']
# 
#         # Custom expectations messages
#         self.expected = 'an callable object, such as a function or method'
#         self.value = value
# 
#         return callable(value), []


# Path: tests/operators/callable_test.py
import pytest
from grappa.operators.callable import CallableOperator

    CallableOperator | should.be.callable
    CallableOperator.match | should.be.callable

    with pytest.raises(AssertionError):
        tuple() | should.be.callable

    with pytest.raises(AssertionError):
        0 | should.be.callable


def test_expect_callable(expect):
    test_expect_callable | expect.to.be.callable
    (lambda x: x) | expect.to.be.callable
    CallableOperator | expect.to.be.callable
    CallableOperator.match | expect.to.be.callable

    with pytest.raises(AssertionError):
        tuple() | expect.to.be.callable

    with pytest.raises(AssertionError):
        0 | expect.to.be.callable


def test_callable_operator(ctx):
    assert CallableOperator(ctx).match(lambda x: x) == (True, [])
    assert CallableOperator(ctx).match(CallableOperator) == (True, [])
    assert CallableOperator(ctx).match(CallableOperator.match) == (True, [])

    assert CallableOperator(ctx).match(0) == (False, [])
    assert CallableOperator(ctx).match('foo') == (False, [])

    assert CallableOperator(ctx).match(iter([1, 2, 3])) == (False, [])