From 5b40f8a23faa842dea54c77e104ecb1a7b66cf46 Mon Sep 17 00:00:00 2001 From: mozillazg Date: Fri, 1 Nov 2019 22:49:12 +0800 Subject: [PATCH] Setup CI --- .travis.yml | 43 +++++++++++++++++++++++++++++ README.md | 3 ++ setup.py | 1 + tests/test_kazoo_client/conftest.py | 2 +- tools/ci/ensure-zookeeper-env.sh | 36 ++++++++++++++++++++++++ tox.ini | 9 +++--- 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 .travis.yml create mode 100644 tools/ci/ensure-zookeeper-env.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..19a7cb7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,43 @@ +sudo: false +dist: xenial +addons: + apt: + packages: + - libevent-dev +cache: + pip: true + directories: + - zookeeper +language: python +python: +- '2.7' +matrix: + include: + - python: '2.7' + env: TOX_ENV=py27 + # - python: '3.4' + # env: TOX_ENV=py34 + # - python: '3.5' + # env: TOX_ENV=py35 + # - python: '3.6' + # env: TOX_ENV=py36 + # - python: '3.7' + # env: TOX_ENV=py37 + # - python: '3.8' + # env: TOX_ENV=py38 + # - python: pypy + # env: TOX_ENV=pypy + # - python: pypy3 + # env: TOX_ENV=pypy3 +notifications: + email: false +install: + - pip install tox codecov + - ZOOKEEPER_VERSION=3.4.9 bash -x ./tools/ci/ensure-zookeeper-env.sh +script: | + export ZOOKEEPER_VERSION=3.4.9 + export ZOOKEEPER_PATH="$(pwd)/zookeeper/3.4.9" + + tox -e $TOX_ENV + + codecov diff --git a/README.md b/README.md index fe93791..6d6e81e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Huskar SDK +[![Build Status](https://travis-ci.com/huskar-org/huskar-python.svg?branch=master)](https://travis-ci.com/huskar-org/huskar-python) +[![codecov](https://codecov.io/gh/huskar-org/huskar-python/branch/master/graph/badge.svg)](https://codecov.io/gh/huskar-org/huskar-python) + - [Documentation](https://github.com/huskar-org/huskar-python) - [Toturial](https://github.com/huskar-org/huskar-python) diff --git a/setup.py b/setup.py index eaa894b..0304b44 100644 --- a/setup.py +++ b/setup.py @@ -62,6 +62,7 @@ def run_tests(self): "pytest-cov==2.5.1", "pytest-xdist==1.20.0", "pytest-mock==1.6.2", + "pytest-forked==0.2", "mock==2.0.0"] setup( diff --git a/tests/test_kazoo_client/conftest.py b/tests/test_kazoo_client/conftest.py index 8a433eb..ec406ec 100644 --- a/tests/test_kazoo_client/conftest.py +++ b/tests/test_kazoo_client/conftest.py @@ -117,7 +117,7 @@ def _func(*args): pool = [C(target=run(func, l), args=(i,)) for i, (l, r) in ps] [c.start() for c in pool] - [c.join() for c in pool] + [c.join(timeout=3) for c in pool] return [r.recv() for _, (l, r) in ps] return pool_map diff --git a/tools/ci/ensure-zookeeper-env.sh b/tools/ci/ensure-zookeeper-env.sh new file mode 100644 index 0000000..ae5b803 --- /dev/null +++ b/tools/ci/ensure-zookeeper-env.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# base on https://github.com/python-zk/kazoo/blob/master/ensure-zookeeper-env.sh + +set -euo pipefail +set -x +IFS=$'\n\t' + +HERE=$(pwd) +ZOO_BASE_DIR="$HERE/zookeeper" +ZOOKEEPER_VERSION=${ZOOKEEPER_VERSION:-3.4.9} +ZOOKEEPER_PATH="$ZOO_BASE_DIR/$ZOOKEEPER_VERSION" +ZOOKEEPER_PREFIX="${ZOOKEEPER_PREFIX:-}" +ZOOKEEPER_SUFFIX="${ZOOKEEPER_SUFFIX:-}" +ZOOKEEPER_LIB="${ZOOKEEPER_LIB:-}" +ZOO_MIRROR_URL="http://archive.apache.org/dist" + + +function download_zookeeper(){ + mkdir -p "$ZOO_BASE_DIR" + cd "$ZOO_BASE_DIR" + curl --silent -C - "$ZOO_MIRROR_URL/zookeeper/zookeeper-$ZOOKEEPER_VERSION/${ZOOKEEPER_PREFIX}zookeeper-${ZOOKEEPER_VERSION}${ZOOKEEPER_SUFFIX}.tar.gz" | tar -zx + mv "${ZOOKEEPER_PREFIX}zookeeper-${ZOOKEEPER_VERSION}${ZOOKEEPER_SUFFIX}" "$ZOOKEEPER_VERSION" + chmod a+x "$ZOOKEEPER_PATH/bin/zkServer.sh" +} + +if [ ! -d "$ZOOKEEPER_PATH" ]; then + download_zookeeper + echo "Downloaded zookeeper $ZOOKEEPER_VERSION to $ZOOKEEPER_PATH" +else + echo "Already downloaded zookeeper $ZOOKEEPER_VERSION to $ZOOKEEPER_PATH" +fi + +# Used as install_path when starting ZK +export ZOOKEEPER_PATH="${ZOOKEEPER_PATH}/${ZOOKEEPER_LIB}" +echo "$ZOOKEEPER_PATH" diff --git a/tox.ini b/tox.ini index c538fe5..74f78f9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,19 @@ [tox] minversion = 2.5 -envlist = erase,py27,py34,py35 +envlist = erase,py27,py34,py35,py36,py37,py38,pypy,pypy3 [testenv] -changedir = {toxinidir}/.tox deps = flake8 extras = test bootstrap setenv = +passenv = + ZOOKEEPER_* commands = - flake8 --exclude=.tox,.venv,docs,build {toxinidir} - py.test --cov={envsitepackagesdir}/huskar_sdk_v2 --cov-append --boxed {toxinidir} {posargs} + flake8 --exclude=.tox,.venv,docs,build,zookeeper huskar_sdk_v2 + py.test -v --cov=huskar_sdk_v2 tests/ [testenv:erase] basepython = python2.7