Skip to content

Commit

Permalink
Merge pull request #150 from zydmayday/check-different-python-versions
Browse files Browse the repository at this point in the history
try to support different python versions, release 0.4.1
  • Loading branch information
zydmayday authored Jun 24, 2022
2 parents 1a18fc9 + 726a1f0 commit f2a4033
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -22,7 +25,7 @@ jobs:
# Sets up python3
- uses: actions/setup-python@v2
with:
python-version: 3.x
python-version: ${{ matrix.python-version }}

# Install dependencies
- name: "Installs dependencies"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -28,7 +31,7 @@ jobs:
# Sets up python3
- uses: actions/setup-python@v2
with:
python-version: 3.x
python-version: ${{ matrix.python-version }}

# Install dependencies
- name: "Installs dependencies"
Expand Down
6 changes: 2 additions & 4 deletions ramda/private/_flatCat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@


class XPreservingReduced(XfBase):
def __init__(self, xf):
self.xf = xf

def step(self, result, _input):
ret = getAttribute(self.xf, '@@transducer/step')(result, _input)
if getAttribute(ret, '@@transducer/reduced'):
Expand All @@ -19,7 +16,8 @@ def step(self, result, _input):

class XFlatCat(XfBase):
def __init__(self, xf):
self.xf = XPreservingReduced(xf)
super().__init__(XPreservingReduced(xf))


def step(self, result, _input):
if not _isArrayLike(_input):
Expand Down
3 changes: 1 addition & 2 deletions ramda/private/_stepCat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def _array_step(xs, x):

_stepCatDict = {
'@@transducer/init': dict,
# use Python 3.9 feature
'@@transducer/step': lambda result, input: result | (objOf(input[0], input[1]) if _isArrayLike(input) else input),
'@@transducer/step': lambda result, input: {**result, **(objOf(input[0], input[1]) if _isArrayLike(input) else input)},
'@@transducer/result': _identity
}

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xReduceBy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class XReduceBy(XfBase):
def __init__(self, valueFn, valueAcc, keyFn, xf):
super().__init__(xf)
self.valueFn = valueFn
self.valueAcc = valueAcc
self.keyFn = keyFn
self.xf = xf
self.inputs = {}

def result(self, result):
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xall.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XAll(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self.all = True

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xany.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XAny(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self.any = False

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class XDrop(XfBase):
def __init__(self, n, xf):
self.xf = xf
super().__init__(xf)
self.n = n

def step(self, result, _input):
Expand Down
4 changes: 2 additions & 2 deletions ramda/private/_xfBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class XfBase:
For extracting the common part to deal with transducer related logic.
"""

def _init_(self, xf):
def __init__(self, xf):
self.xf = xf

def init(self):
Expand All @@ -17,7 +17,7 @@ def result(self, result):
return getAttribute(self.xf, '@@transducer/result')(result)

def step(self, result, _input):
raise Exception('Child class should implement this')
pass

def get(self, name, default=None):
if name == '@@transducer/init':
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class XFilter(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f

def step(self, result, _input):
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XFind(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self.found = False

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xfindIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XFindIndex(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self.idx = -1
self.found = False
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xfindLast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class XFindLast(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self.last = None

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xfindLastIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class XFindLastIndex(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self.idx = -1
self.lastIdx = -1
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class XMap(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f

def step(self, result, _input):
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xtake.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XTake(XfBase):
def __init__(self, n, xf):
self.xf = xf
super().__init__(xf)
self.n = n
self.i = 0

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xtakeWhile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XTakeWhile(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f

def step(self, result, _input):
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class XTap(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f

def step(self, result, _input):
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xuniqBy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XUniqBy(XfBase):
def __init__(self, f, xf):
self.xf = xf
super().__init__(xf)
self.f = f
self._set = _Set()

Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_xuniqWith.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class XUniqWith(XfBase):
def __init__(self, pred, xf):
self.xf = xf
super().__init__(xf)
self.pred = pred
self.items = []

Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# eg: 1.0.0, 1.0.1, 3.0.2, 5.0-beta, etc.
# You CANNOT upload two versions of your package with the same version number
# This field is REQUIRED
version="0.4.0",
version="0.4.1",

# The packages that constitute your project.
# For my project, I have only one - "pydash".
Expand Down Expand Up @@ -67,7 +67,12 @@
classifiers=[
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.9"
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
],

# Keywords are tags that identify your project and help searching for it
Expand Down
7 changes: 7 additions & 0 deletions test/helpers/listXf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
'@@transducer/step': lambda acc, x: acc + x,
'@@transducer/result': lambda x: x
}


listXfPushData = {
'@@transducer/init': lambda: [],
'@@transducer/step': lambda acc, x: acc + [x],
'@@transducer/result': lambda x: x
}
17 changes: 17 additions & 0 deletions test/private/test__stepCat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

from ramda.private._stepCat import _stepCat

from ..helpers.listXf import listXf


class Test_StepCat(unittest.TestCase):
def test_fix_code_coverage_error(self):
self.assertEqual(listXf, _stepCat(listXf))

with self.assertRaises(Exception):
_stepCat(None)


if __name__ == '__main__':
unittest.main()
15 changes: 15 additions & 0 deletions test/private/test__xfBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from ramda.private._xfBase import XfBase

from ..helpers.listXf import listXf


class Test_XfBase(unittest.TestCase):
def test_fix_code_coverage_error(self):
xfBase = XfBase(listXf)
xfBase.step(None, None)


if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions test/test_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import ramda as R

from .helpers.listXf import listXfPushData

"""
https://github.com/ramda/ramda/blob/master/test/drop.js
"""
Expand Down Expand Up @@ -29,6 +31,11 @@ def test_can_operate_on_strings(self):
self.assertEqual('', R.drop(5, 'Ramda'))
self.assertEqual('', R.drop(6, 'Ramda'))

def test_drop_xf(self):
dropXf = R.drop(2, listXfPushData)
res = R.reduce(dropXf, [], [1, 2, 3, 4, 5])
self.assertEqual([3, 4, 5], res)


if __name__ == '__main__':
unittest.main()
7 changes: 4 additions & 3 deletions test/test_is.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def test_works_with_built_in_types(self):
self.assertTrue(R.Is(dict, dict(a=1, b=2)))

# Union types
u = int | str
self.assertTrue(R.Is(u, 1))
self.assertTrue(R.Is(u, "1"))
# From python 3.10+
# u = int | str
# self.assertTrue(R.Is(u, 1))
# self.assertTrue(R.Is(u, "1"))

# None type
self.assertTrue(R.Is(None, None))
Expand Down
7 changes: 7 additions & 0 deletions test/test_uniqWith.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import ramda as R

from .helpers.listXf import listXfPushData

"""
https://github.com/ramda/ramda/blob/master/test/uniqWith.js
"""
Expand Down Expand Up @@ -38,6 +40,11 @@ def test_can_act_as_a_transducer(self):
# TODO: eqBy
# TODO: transduce

def test_uniqWith_xf(self):
uniqWithXf = R.uniqWith(lambda x, y: x % 2 == y % 2, listXfPushData)
res = R.reduce(uniqWithXf, [], [1, 2, 3, 4, 5])
self.assertEqual([1, 2], res)


if __name__ == '__main__':
unittest.main()

0 comments on commit f2a4033

Please sign in to comment.