Source

foonc / foonctest / foonctest.py

import unittest

from foonc.core import *
from foonc.core import _compose2

from foonc import accessors

def inc(x):
    return x + 1

class FooncTests(unittest.TestCase):
    def setUp(self):
        super(FooncTests, self).setUp()

    def test_const(self):
        self.assertEqual(42, const(42)('whatever', is_passed='in'))

    def test_compose2(self):
        f = _compose2(inc, int)
        self.assertEqual(42, f('41'))

    def test_compose_args(self):
        f = compose(str, inc, int)
        self.assertEqual('42', f('41'))

    def test_compose_list(self):
        f = compose([str, inc, int])
        self.assertEqual('42', f('41'))

    def test_flip(self):
        def f(*args):
            return args
        flipped = flip(f)
        self.assertEqual((3, 2, 1), flipped(1, 2, 3))


class FooncWrapperTests(unittest.TestCase):
    def setUp(self):
        super(FooncWrapperTests, self).setUp()

    def test_left_shift(self):
        f = wrap(int) >> inc
        self.assertEqual(42, f('41'))


class GetTests(unittest.TestCase):
    def test_get(self):
        obj = {'foo':{'bar':{'baz':42}}}
        f = accessors.get('foo.bar.baz')
        self.assertEqual(42, f(obj))