diff --git a/ramda/private/_has.py b/ramda/private/_has.py index 4e84c95..0e48386 100644 --- a/ramda/private/_has.py +++ b/ramda/private/_has.py @@ -1,4 +1,9 @@ def _has(obj, key): + ''' + Since python object can not have None property, we just check for dict. + ''' + if key is None: + return isinstance(obj, dict) and key in obj if isinstance(obj, dict): return key in obj or hasattr(obj, key) return hasattr(obj, key) diff --git a/test/test_ap.py b/test/test_ap.py new file mode 100644 index 0000000..781300d --- /dev/null +++ b/test/test_ap.py @@ -0,0 +1,25 @@ + +import unittest + +import ramda as R + +""" +https://github.com/ramda/ramda/blob/master/test/ap.js +""" + + +class TestAp(unittest.TestCase): + def test_returns_an_array_of_tuples(self): + a = [1, 2, 3] + b = [100, 200, 300] + self.assertEqual([[1, 100], [2, 200], [3, 300]], R.zip(a, b)) + + def test_returns_a_list_as_long_as_the_shorter_of_the_lists_input(self): + a = [1, 2, 3] + b = [100, 200, 300, 400] + c = [10, 20] + self.assertEqual([[1, 100], [2, 200], [3, 300]], R.zip(a, b)) + self.assertEqual([[1, 10], [2, 20]], R.zip(a, c)) + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_into.py b/test/test_into.py index 66f903e..a727f53 100644 --- a/test/test_into.py +++ b/test/test_into.py @@ -21,20 +21,28 @@ class TestInto(unittest.TestCase): def test_transduces_into_arrays(self): self.assertEqual([2, 3, 4, 5], R.into([], R.map(add(1)), [1, 2, 3, 4])) self.assertEqual([1, 3], R.into([], R.filter(isOdd), [1, 2, 3, 4])) - # TODO: take + self.assertEqual([2, 3], R.into([], R.compose(R.map(add(1)), R.take(2)), [1, 2, 3, 4])) def test_transduces_into_strings(self): self.assertEqual('2345', R.into('', R.map(add(1)), [1, 2, 3, 4])) self.assertEqual('13', R.into('', R.filter(isOdd), [1, 2, 3, 4])) - # TODO: take + self.assertEqual('23', R.into('', R.compose(R.map(add(1)), R.take(2)), [1, 2, 3, 4])) def test_transduces_into_dicts(self): self.assertEqual({'a': 1, 'b': 2}, R.into({}, R.identity, [['a', 1], ['b', 2]])) self.assertEqual({'a': 1, 'b': 2, 'c': 3}, R.into({}, R.identity, [{'a': 1}, {'b': 2, 'c': 3}])) def test_dispatches_to_objects_that_implement_reduce(self): - pass - # TODO: we do not support object currently + class Obj: + def __init__(self, x): + self.x = x + + def reduce(self, f, acc): + return 'override' + + obj = Obj([1, 2, 3]) + self.assertEqual('override', R.into([], R.map(add(1)), obj)) + self.assertEqual('override', R.into([], R.filter(isOdd), obj)) def test_allows_custom_transformer(self): intoSum = R.into(addXf) diff --git a/test/test_juxt.py b/test/test_juxt.py index 63aef92..60e20f0 100644 --- a/test/test_juxt.py +++ b/test/test_juxt.py @@ -2,6 +2,7 @@ import unittest import ramda as R +from ramda.private._inspect import funcArgsLength """ https://github.com/ramda/ramda/blob/master/test/juxt.js @@ -42,8 +43,8 @@ def test_works_with_some_functions_and_some_value(self): self.assertEqual([5, 6], R.juxt([R.add, R.multiply])(2, 3)) def test_retains_the_highest_arity(self): - # TODO: nAry - pass + f = R.juxt([R.nAry(1, R.T), R.nAry(3, R.T), R.nAry(2, R.T)]) + self.assertEqual(3, funcArgsLength(f)) def test_returns_a_curried_function(self): self.assertEqual([6, 5], R.juxt([R.multiply, R.add])(2)(3)) diff --git a/test/test_prop.py b/test/test_prop.py index 55e8b95..74b15d8 100644 --- a/test/test_prop.py +++ b/test/test_prop.py @@ -27,11 +27,9 @@ def test_shows_the_same_behaviour_as_path_for_a_nonexistent_property(self): self.assertEqual(propResult, pathResult) def test_shows_the_same_behaviour_as_path_for_a_None_property(self): - # TODO: fix getAttribute - # propResult = R.prop(None, fred) - # pathResult = R.path([None], fred) - # self.assertEqual(propResult, pathResult) - pass + propResult = R.prop(None, fred) + pathResult = R.path([None], fred) + self.assertEqual(propResult, pathResult) def test_shows_the_same_behaviour_as_path_for_a_valid_property_and_object(self): propResult = R.prop('age', fred) @@ -59,11 +57,9 @@ def test_shows_the_same_behaviour_as_path_for_a_nonexistent_property(self): self.assertEqual(propResult, pathResult) def test_shows_the_same_behaviour_as_path_for_a_None_property(self): - # TODO: fix getAttribute - # propResult = R.prop(None, fredObj) - # pathResult = R.path([None], fredObj) - # self.assertEqual(propResult, pathResult) - pass + propResult = R.prop(None, fredObj) + pathResult = R.path([None], fredObj) + self.assertEqual(propResult, pathResult) def test_shows_the_same_behaviour_as_path_for_a_valid_property_and_object(self): propResult = R.prop('age', fredObj)