use coverage

This commit is contained in:
felinae98 2021-06-18 10:24:24 +08:00
parent d6192153da
commit c62a8d2f5e
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610
4 changed files with 25 additions and 31 deletions

View File

@ -12,10 +12,7 @@ orbs:
workflows:
build-test-publish:
jobs:
- python/test:
pkg-manager: poetry
test-tool: pytest
version: "3.9"
- test:
filters:
tags:
only: /.*/
@ -29,29 +26,24 @@ workflows:
only: /^v.*/
jobs:
# test:
# docker:
# - image: cimg/python:3.9
# steps:
# - checkout
# # - run: sed -e '41,45d' -i pyproject.toml
# - restore_cache:
# keys:
# - venv-cache-{{ checksum "poetry.lock" }}
# - run:
# name: Poetry install
# command: |
# poetry config virtualenvs.in-project true
# poetry install -v
# - save_cache:
# paths:
# - .venv
# key: venv-cache-{{ checksum "poetry.lock" }}
# - run:
# name: pytest
# command: poetry run pytest --junitxml=test-results/junit.xml
# - store_test_results:
# path: test-results
test:
docker:
- image: cimg/python:3.9
steps:
- checkout
# - run: sed -e '41,45d' -i pyproject.toml
- python/install-packages:
pkg-manager: poetry
- run:
name: Coverage test
command: poetry run coverage run -m pytest --junitxml=test-results/junit.xml
- store_test_results:
path: test-results
- run:
name: Collect coverage
command: coverage html --include='src/*'
- store_artifacts:
path: htmlcov
build-publish:
docker:
- image: cimg/python:3.9

View File

@ -4,7 +4,7 @@
[![pypi](https://badgen.net/pypi/v/nonebot-hk-reporter)](https://pypi.org/project/nonebot-hk-reporter/)
[![felinae98](https://circleci.com/gh/felinae98/nonebot-hk-reporter.svg?style=svg)](https://circleci.com/gh/felinae98/nonebot-hk-reporter)
[![felinae98](https://circleci.com/gh/felinae98/nonebot-hk-reporter.svg?style=shield)](https://circleci.com/gh/felinae98/nonebot-hk-reporter)
[![qq group](https://img.shields.io/badge/QQ%E7%BE%A4-868610060-orange )](https://qm.qq.com/cgi-bin/qm/qr?k=pXYMGB_e8b6so3QTqgeV6lkKDtEeYE4f&jump_from=webapi)
</div>

View File

@ -62,11 +62,12 @@ class Weibo(Platform):
def get_tags(self, raw_post: RawPost) -> Optional[list[Tag]]:
"Return Tag list of given RawPost"
text = raw_post['mblog']['text']
soup = bs(text, 'html.parser')
return list(map(
lambda x: x[1:-1],
filter(
lambda s: s[0] == '#' and s[-1] == '#',
map(lambda x:x.text, text.find_all('span', class_='surl-text'))
map(lambda x:x.text, soup.find_all('span', class_='surl-text'))
)
))

View File

@ -74,5 +74,6 @@ async def test_parse_long(weibo):
assert(not '全文' in post.text)
assert(detail_router.called)
def text_tag(weibo, weibo_ak_list_1):
assert(weibo.get_tags(weibo_ak_list_1) == ['明日方舟', '音律联觉'])
def test_tag(weibo, weibo_ak_list_1):
raw_post = weibo_ak_list_1['data']['cards'][0]
assert(weibo.get_tags(raw_post) == ['明日方舟', '音律联觉'])