Setup test coverage

This commit is contained in:
NateScarlet 2019-03-12 22:28:58 +08:00
parent 4e215913c3
commit 79d0177c41
No known key found for this signature in database
GPG Key ID: 5C242793B070309C
7 changed files with 22 additions and 3 deletions

2
.coveragerc Normal file
View File

@ -0,0 +1,2 @@
[run]
omit = tests/*

View File

@ -6,15 +6,20 @@ before_install:
install: install:
- go get github.com/github/hub && hub --version - go get github.com/github/hub && hub --version
- pip install -r requirements.txt - 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: cache:
- pip - pip
before_script: before_script:
- git config credential.helper "store --file=.git/credentials" - git config credential.helper "store --file=.git/credentials"
- echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials - echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials
- git checkout master - git checkout master
- ./cc-test-reporter before-build
script: script:
- pytest - pytest
- ./update.py --release - coverage run -a ./update.py --release
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
branches: branches:
only: only:
- master - master

View File

@ -1,6 +1,6 @@
# holiday-cn # 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)
中国法定节假日数据 自动每日抓取国务院公告 中国法定节假日数据 自动每日抓取国务院公告

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
addopts = --cov=.

View File

@ -1,3 +1,5 @@
requests ~= 2.21.0 requests ~= 2.21.0
beautifulsoup4 ~= 4.7.1 beautifulsoup4 ~= 4.7.1
tqdm ~= 4.30.0 tqdm ~= 4.30.0
pytest ~= 4.3.0
pytest-cov ~= 2.6.1

View File

@ -1,9 +1,17 @@
"""Test module `fetch_holidays`. """ """Test module `fetch_holidays`. """
import json import json
import os
import sys import sys
from fetch_holidays import CustomJSONEncoder, DescriptionParser 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): def _normalize(iterable):
return sorted(json.loads(json.dumps(list(iterable), cls=CustomJSONEncoder)), return sorted(json.loads(json.dumps(list(iterable), cls=CustomJSONEncoder)),
@ -11,7 +19,7 @@ def _normalize(iterable):
def _generate_tests(): 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) cases = json.load(f)
def create_test(case): def create_test(case):