import unittest
import jmespath
from jmespath import functions


class CustomFunctions(functions.Functions):

    @functions.signature({'types': ['string', 'array', 'object', 'null']})
    def _func_length0(self, s):
        return 0 if s is None else len(s)


class TestCustomFunctions(unittest.TestCase):

    def setUp(self):
        self.options = jmespath.Options(custom_functions=CustomFunctions())

    def test_null_to_nonetype(self):
        data = {'a': {'b': [1, 2, 3]}}
        self.assertEqual(jmespath.search('length0(a.b)', data, self.options), 3
            )
        self.assertEqual(jmespath.search('length0(a.c)', data, self.options), 0
            )

188015b09fbf21898979b8f7748c00850caab346
<mask token>


class TestCustomFunctions(unittest.TestCase):
    <mask token>
    <mask token>

<mask token>


class CustomFunctions(functions.Functions):
    <mask token>


class TestCustomFunctions(unittest.TestCase):

    def setUp(self):
        self.options = jmespath.Options(custom_functions=CustomFunctions())

    def test_null_to_nonetype(self):
        data = {'a': {'b': [1, 2, 3]}}
        self.assertEqual(jmespath.search('length0(a.b)', data, self.options), 3
            )
        self.assertEqual(jmespath.search('length0(a.c)', data, self.options), 0
            )

<mask token>


class CustomFunctions(functions.Functions):

    @functions.signature({'types': ['string', 'array', 'object', 'null']})
    def _func_length0(self, s):
        return 0 if s is None else len(s)


class TestCustomFunctions(unittest.TestCase):

    def setUp(self):
        self.options = jmespath.Options(custom_functions=CustomFunctions())

    def test_null_to_nonetype(self):
        data = {'a': {'b': [1, 2, 3]}}
        self.assertEqual(jmespath.search('length0(a.b)', data, self.options), 3
            )
        self.assertEqual(jmespath.search('length0(a.c)', data, self.options), 0
            )

import unittest
import jmespath
from jmespath import functions


class CustomFunctions(functions.Functions):

    @functions.signature({'types': ['string', 'array', 'object', 'null']})
    def _func_length0(self, s):
        return 0 if s is None else len(s)


class TestCustomFunctions(unittest.TestCase):

    def setUp(self):
        self.options = jmespath.Options(custom_functions=CustomFunctions())

    def test_null_to_nonetype(self):
        data = {'a': {'b': [1, 2, 3]}}
        self.assertEqual(jmespath.search('length0(a.b)', data, self.options), 3
            )
        self.assertEqual(jmespath.search('length0(a.c)', data, self.options), 0
            )
