From 79d0177c4179552c133657759fc37e97cd5d0e11 Mon Sep 17 00:00:00 2001 From: NateScarlet Date: Tue, 12 Mar 2019 22:28:58 +0800 Subject: [PATCH] Setup test coverage --- .coveragerc | 2 ++ .travis.yml | 7 ++++++- README.md | 2 +- pytest.ini | 2 ++ requirements.txt | 2 ++ .../description_parsing_cases.json | 0 test_fetch_holidays.py => tests/test_fetch_holidays.py | 10 +++++++++- 7 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 .coveragerc create mode 100644 pytest.ini rename description_parsing_cases.json => tests/description_parsing_cases.json (100%) rename test_fetch_holidays.py => tests/test_fetch_holidays.py (77%) diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..c712d25 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = tests/* diff --git a/.travis.yml b/.travis.yml index 018f304..7a9ad20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,15 +6,20 @@ before_install: install: - go get github.com/github/hub && hub --version - pip install -r requirements.txt + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter cache: - pip before_script: - git config credential.helper "store --file=.git/credentials" - echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials - git checkout master + - ./cc-test-reporter before-build script: - pytest - - ./update.py --release + - coverage run -a ./update.py --release +after_script: + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT branches: only: - master diff --git a/README.md b/README.md index bf239b3..00fd9a6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # holiday-cn -[![Build Status](https://travis-ci.org/NateScarlet/holiday-cn.svg?branch=master)](https://travis-ci.org/NateScarlet/holiday-cn) [![Release](https://img.shields.io/github/release/NateScarlet/holiday-cn.svg)](https://github.com/NateScarlet/holiday-cn/releases/latest) [![CalVer](https://img.shields.io/badge/calver-YYYY.0M.0D-22bfda.svg)](http://calver.org) [![Maintainability](https://api.codeclimate.com/v1/badges/c8e9d9c51bd2d858c577/maintainability)](https://codeclimate.com/github/NateScarlet/holiday-cn/maintainability) ![Maintenance](https://img.shields.io/maintenance/yes/2019.svg) +[![Build Status](https://travis-ci.org/NateScarlet/holiday-cn.svg?branch=master)](https://travis-ci.org/NateScarlet/holiday-cn) [![Release](https://img.shields.io/github/release/NateScarlet/holiday-cn.svg)](https://github.com/NateScarlet/holiday-cn/releases/latest) [![CalVer](https://img.shields.io/badge/calver-YYYY.0M.0D-22bfda.svg)](http://calver.org) [![Maintainability](https://api.codeclimate.com/v1/badges/c8e9d9c51bd2d858c577/maintainability)](https://codeclimate.com/github/NateScarlet/holiday-cn/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/c8e9d9c51bd2d858c577/test_coverage)](https://codeclimate.com/github/NateScarlet/holiday-cn/test_coverage) ![Maintenance](https://img.shields.io/maintenance/yes/2019.svg) 中国法定节假日数据 自动每日抓取国务院公告 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..1d82b8c --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = --cov=. diff --git a/requirements.txt b/requirements.txt index 4f0073b..57651a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ requests ~= 2.21.0 beautifulsoup4 ~= 4.7.1 tqdm ~= 4.30.0 +pytest ~= 4.3.0 +pytest-cov ~= 2.6.1 diff --git a/description_parsing_cases.json b/tests/description_parsing_cases.json similarity index 100% rename from description_parsing_cases.json rename to tests/description_parsing_cases.json diff --git a/test_fetch_holidays.py b/tests/test_fetch_holidays.py similarity index 77% rename from test_fetch_holidays.py rename to tests/test_fetch_holidays.py index 84c6ece..9c1f105 100644 --- a/test_fetch_holidays.py +++ b/tests/test_fetch_holidays.py @@ -1,9 +1,17 @@ """Test module `fetch_holidays`. """ import json +import os import sys from fetch_holidays import CustomJSONEncoder, DescriptionParser +__dirname__ = os.path.abspath(os.path.dirname(__file__)) + + +def _file_path(*other): + + return os.path.join(__dirname__, *other) + def _normalize(iterable): return sorted(json.loads(json.dumps(list(iterable), cls=CustomJSONEncoder)), @@ -11,7 +19,7 @@ def _normalize(iterable): def _generate_tests(): - with open('description_parsing_cases.json', 'r', encoding='utf-8', ) as f: + with open(_file_path('description_parsing_cases.json'), 'r', encoding='utf-8', ) as f: cases = json.load(f) def create_test(case):