Ejemplo n.º 1
0
import unittest
from unittesthelper import init
init()  # will let you import modules from upper folder
from src.underscore import _
import math
import time


class TestUtility(unittest.TestCase):
    class Namespace():
        pass

    def setUp(self):
        _.templateSettings = {}

    def test_identity(self):
        moe = {"name": 'moe'}
        self.assertEqual(moe, _.identity(moe),
                         "moe is the same as his identity")

    def test_constant(self):
        moe = {"name": 'moe'}
        self.assertEqual(
            _.constant(moe)(), moe,
            'should create a function that returns moe')

    def test_property(self):
        moe = {"name": 'moe'}
        self.assertEqual(
            _.property('name')(moe), 'moe',
            'should return the property with the given name')
Ejemplo n.º 2
0
import unittest
from unittesthelper import init
init()  # will let you import modules from upper folder
from src.underscore import _


class TestCollections(unittest.TestCase):

    eachList = []

    def test_each_list(self):
        def eachTest(val, *args):
            self.eachList.append(val + 1)

        _([1, 2, 3, 4]).each(eachTest)
        self.assertEqual([2, 3, 4, 5], self.eachList,
                         "each for lists did not work for all")
        # test alias
        self.eachList = []
        _([1, 2, 3, 4]).forEach(eachTest)
        self.assertEqual([2, 3, 4, 5], self.eachList,
                         "forEach for lists did not work for all")

    eachSet = set()

    def test_each_dict(self):
        def eachTest(val, key, *args):
            self.eachSet.add(val)
            self.eachSet.add(key)

        _({"foo": "bar", "fizz": "buzz"}).each(eachTest)