Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ramda/private/_has.py
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions test/test_ap.py
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 12 additions & 4 deletions test/test_into.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/test_juxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
16 changes: 6 additions & 10 deletions test/test_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down