Skip to content

Commit 324e147

Browse files
authored
Testing with Python 3 and additional testing facilities (#91)
1 parent 1873733 commit 324e147

File tree

10 files changed

+256
-88
lines changed

10 files changed

+256
-88
lines changed

.circleci/config.yml

Lines changed: 121 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
2-
# Python CircleCI 2.0 configuration file
3-
#
4-
# Check https://circleci.com/docs/2.0/language-python/ for more details
5-
#
6-
version: 2
7-
jobs:
8-
build:
9-
docker:
10-
- image: circleci/python:2.7.15
11-
- image: redislabs/redisearch:latest
12-
13-
working_directory: ~/repo
14-
15-
steps:
1+
version: 2.1
2+
3+
commands:
4+
test-steps:
5+
parameters:
6+
python_ver:
7+
type: string
8+
default: "3"
9+
redisearch_ver:
10+
type: string
11+
default: latest
12+
coverage:
13+
type: boolean
14+
default: true
15+
steps:
1616
- checkout
1717

1818
- restore_cache: # Download and cache dependencies
@@ -26,8 +26,16 @@ jobs:
2626
command: |
2727
virtualenv venv
2828
. venv/bin/activate
29+
python --version
2930
pip install -r requirements.txt
30-
pip install codecov
31+
pip install --force-reinstall git+https://github.com/RedisLabs/rmtest.git
32+
<<# parameters.coverage >> pip install codecov <</ parameters.coverage >>
33+
python - \<<'__'
34+
import redis
35+
r = redis.Redis(decode_responses=True)
36+
print(r.execute_command('info server'))
37+
print(r.execute_command('info modules'))
38+
__
3139
3240
- save_cache:
3341
paths:
@@ -42,68 +50,120 @@ jobs:
4250
name: run tests
4351
command: |
4452
. venv/bin/activate
45-
REDIS_PORT=6379 coverage run test/test.py
46-
REDIS_PORT=6379 coverage run -a test/test_builder.py
47-
codecov
48-
53+
<<# parameters.coverage >> COV=1 <</ parameters.coverage >>
54+
if [[ $COV == 1 ]]; then
55+
REDIS_PORT=6379 coverage run test/test.py
56+
REDIS_PORT=6379 coverage run -a test/test_builder.py
57+
codecov
58+
else
59+
REDIS_PORT=6379 python test/test.py
60+
REDIS_PORT=6379 python test/test_builder.py
61+
fi
62+
4963
- store_artifacts:
5064
path: test-reports
5165
destination: test-reports
5266

53-
build_nightly:
54-
docker:
55-
- image: circleci/python:2.7.15
56-
- image: redislabs/redisearch:edge
57-
58-
working_directory: ~/repo
5967

68+
jobs:
69+
test:
70+
parameters:
71+
python_ver:
72+
type: string
73+
default: "3"
74+
redisearch_ver:
75+
type: string
76+
default: latest
77+
coverage:
78+
type: boolean
79+
default: true
80+
docker:
81+
- image: circleci/python:<<parameters.python_ver >>
82+
- image: redislabs/redisearch:<<parameters.redisearch_ver >>
6083
steps:
61-
- checkout
62-
63-
- restore_cache: # Download and cache dependencies
64-
keys:
65-
- v1-dependencies-{{ checksum "requirements.txt" }}
66-
# fallback to using the latest cache if no exact match is found
67-
- v1-dependencies-
84+
- test-steps:
85+
python_ver: <<parameters.python_ver>>
86+
redisearch_ver: <<parameters.redisearch_ver>>
87+
coverage: <<parameters.coverage>>
88+
- store_artifacts:
89+
path: test-reports
90+
destination: test-reports
6891

69-
- run:
70-
name: install dependencies
71-
command: |
72-
virtualenv venv
73-
. venv/bin/activate
74-
pip install -r requirements.txt
75-
76-
- save_cache:
77-
paths:
78-
- ./venv
79-
key: v1-dependencies-{{ checksum "requirements.txt" }}
92+
working_directory: ~/repo
8093

81-
- run:
82-
name: run tests
83-
command: |
84-
. venv/bin/activate
85-
REDIS_PORT=6379 python test/test.py
8694

87-
- run:
88-
name: run query builder tests
89-
command: |
90-
. venv/bin/activate
91-
REDIS_PORT=6379 python test/test_builder.py
95+
on-any-branch: &on-any-branch
96+
filters:
97+
branches:
98+
only: /.*/
99+
tags:
100+
only: /.*/
101+
102+
never: &never
103+
filters:
104+
branches:
105+
ignore: /.*/
106+
tags:
107+
ignore: /.*/
108+
109+
on-master: &on-master
110+
filters:
111+
branches:
112+
only: master
113+
114+
on-version-tags: &on-version-tags
115+
filters:
116+
branches:
117+
ignore: /.*/
118+
tags:
119+
only: /^v[0-9].*/
120+
121+
on-master-and-version-tags: &on-master-and-version-tags
122+
filters:
123+
branches:
124+
only:
125+
- master
126+
tags:
127+
only: /^v[0-9].*/
92128

93-
# no need for store_artifacts on nightly builds
94129

95130
workflows:
96131
version: 2
97132
commit:
98133
jobs:
99-
- build
134+
- test:
135+
name: build
136+
python_ver: "3"
137+
redisearch_ver: latest
138+
coverage: yes
139+
<<: *on-any-branch
140+
- test:
141+
name: test_py2_latest
142+
python_ver: "2.7"
143+
redisearch_ver: latest
144+
coverage: yes
145+
<<: *on-any-branch
146+
- test:
147+
name: test_py3_search1.6
148+
python_ver: "3"
149+
redisearch_ver: "1.6.14"
150+
coverage: yes
151+
<<: *on-any-branch
152+
- test:
153+
name: test_py2_search1.6
154+
python_ver: "2.7"
155+
redisearch_ver: "1.6.14"
156+
coverage: yes
157+
<<: *on-any-branch
158+
100159
nightly:
101160
triggers:
102161
- schedule:
103162
cron: "0 0 * * *"
104-
filters:
105-
branches:
106-
only:
107-
- master
163+
<<: *on-master
108164
jobs:
109-
- build_nightly
165+
- test:
166+
name: test-nightly
167+
python_ver: "3"
168+
redisearch_ver: edge
169+
coverage: no

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/venv*/

.gitignore

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
*
2-
!/**/
3-
build
4-
dist
1+
/build
2+
/dist
53
.env
6-
!.gitignore
7-
!requirements.txt
8-
!**/*.py
9-
!**/*.csv
10-
!**/*.md
11-
!.circleci/config.yml
12-
venv/
4+
/venv*/
5+
*.pyc

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,37 @@ res = client.search(q)
8383
$ pip install redisearch
8484
```
8585

86+
## Testing
8687

88+
Testing can easily be performed using using Docker.
89+
Run the following:
8790

91+
```
92+
make -C test/docker test PYTHON_VER=3
93+
```
94+
95+
(Replace `PYTHON_VER=3` with `PYTHON_VER=2` to test with Python 2.7.)
96+
97+
Alternatively, use the following procedure:
98+
99+
First, run:
100+
101+
```
102+
PYTHON_VER=3 ./test/test-setup.sh
103+
```
104+
105+
This will set up a Python virtual environment in `venv3` (or in `venv2` if `PYTHON_VER=2` is used).
106+
107+
Afterwards, run RediSearch in a container as a daemon:
108+
109+
```
110+
docker run -d -p 6379:6379 redislabs/redisearch:2.0.0
111+
```
112+
113+
Finally, invoke the virtual environment and run the tests:
114+
115+
```
116+
. ./venv3/bin/activate
117+
REDIS_PORT=6379 python test/test.py
118+
REDIS_PORT=6379 python test/test_builder.py
119+
```

redisearch/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ def __init__(self, index_name, host='localhost', port=6379, conn=None, password=
241241
self.index_name = index_name
242242

243243
self.redis = conn if conn is not None else Redis(
244-
connection_pool=ConnectionPool(host=host, port=port, password=password))
244+
connection_pool=ConnectionPool(host=host, port=port, password=password,
245+
decode_responses=True))
245246

246247
def batch_indexer(self, chunk_size=100):
247248
"""

test/docker/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
ARG PYTHON_VER
3+
4+
FROM redislabs/redisearch:2.0.0
5+
6+
RUN set -e ;\
7+
apt-get -qq update ;\
8+
apt-get install -y git
9+
10+
WORKDIR /build
11+
12+
RUN set -e ;\
13+
mkdir -p deps ;\
14+
cd deps ;\
15+
git clone https://github.com/RedisLabsModules/readies.git
16+
17+
RUN if [ "$PYTHON_VER" = 2 ]; then \
18+
PIP=1 ./deps/readies/bin/getpy2 ;\
19+
python2 --version ;\
20+
else \
21+
PIP=1 ./deps/readies/bin/getpy3 ;\
22+
python3 --version ;\
23+
fi
24+
25+
ADD ./ /build
26+
27+
RUN pip install -r requirements.txt
28+
RUN pip install --force-reinstall git+https://github.com/RedisLabs/rmtest.git
29+
30+
ENV REDIS_PORT=6379
31+
32+
ENTRYPOINT [ "/bin/bash", "-c", "/build/test/docker/test.sh" ]

test/docker/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
.PHONY: all build test
3+
4+
PYTHON_VER ?= 3
5+
6+
all: test
7+
8+
build:
9+
docker build --no-cache -t redisearch-py-test -f Dockerfile --build-arg PYTHON_VER=$(PYTHON_VER) ../..
10+
11+
test: build
12+
docker run --rm -it redisearch-py-test

test/docker/test.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ $PYTHON_VER == 2 ]]; then
6+
PYTHON=python2
7+
else
8+
PYTHON=python3
9+
fi
10+
11+
$PYTHON --version
12+
13+
cd /build
14+
redis-server --loadmodule /usr/lib/redis/modules/redisearch.so &
15+
sleep 1
16+
$PYTHON test/test.py
17+
$PYTHON test/test_builder.py

test/test-setup.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
4+
ROOT=$(cd $HERE/..; pwd)
5+
6+
cd $ROOT
7+
8+
(mkdir -p deps; cd deps; git clone https://github.com/RedisLabsModules/readies.git)
9+
10+
if [ "$PYTHON_VER" = 2 ]; then
11+
PIP=1 VENV=1 ./deps/readies/bin/getpy2
12+
python2 -m virtualenv venv2
13+
. ./venv2/bin/activate
14+
else
15+
PIP=1 VENV=1 ./deps/readies/bin/getpy3
16+
python3 -m virtualenv venv3
17+
. ./venv3/bin/activate
18+
fi
19+
20+
python -m pip install -r requirements.txt
21+
python -m pip install --force-reinstall git+https://github.com/RedisLabs/rmtest.git

0 commit comments

Comments
 (0)