diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 703124f3..87e052db 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -39,4 +39,4 @@ jobs: run: | mypy - name: Run demo.py - run: python demo.py + run: pytest --cov -v demo.py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 84cc769a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: python - -python: - - "3.6" - -# command to install dependencies -install: pip install -r requirements.txt - -# command to run tests -script: python demo.py - -branches: - only: - - master diff --git a/demo.py b/demo.py index 320c61e4..6dc55f31 100644 --- a/demo.py +++ b/demo.py @@ -22,10 +22,13 @@ # 'verify': False, # PAPI use https, an easy way is disable requests SSL verify } +aapi = AppPixivAPI(**_REQUESTS_KWARGS) +aapi.auth(refresh_token=_REFRESH_TOKEN) + # AppAPI start -def appapi_illust(aapi): +def test_appapi_illust(): json_result = aapi.illust_detail(59580629) print(json_result) illust = json_result.illust @@ -41,7 +44,7 @@ def appapi_illust(aapi): # print(">>> frames=%d %s" % (len(metadata.frames), metadata.zip_urls.medium)) -def appapi_recommend(aapi): +def test_appapi_recommend(): json_result = aapi.illust_recommended(bookmark_illust_ids=[59580629]) print(json_result) illust = json_result.illusts[0] @@ -69,7 +72,7 @@ def appapi_recommend(aapi): print(" > %s, origin url: %s" % (illust.title, illust.image_urls["large"])) -def appapi_users(aapi): +def test_appapi_users(): json_result = aapi.user_detail(275527) print(json_result) user = json_result.user @@ -115,7 +118,7 @@ def appapi_users(aapi): print(json_result) -def appapi_search(aapi): +def test_appapi_search(): first_tag = None response = aapi.trending_tags_illust() for trend_tag in response.trend_tags[:10]: @@ -154,7 +157,7 @@ def appapi_search(aapi): print(">>> %s, origin url: %s" % (novel.title, novel.image_urls["large"])) -def appapi_user_search(aapi): +def test_appapi_user_search(): json_result = aapi.illust_ranking("day_male") name = json_result.illusts[0].user.name print(">>> %s" % name) @@ -173,7 +176,7 @@ def appapi_user_search(aapi): print(">>> %s, origin url: %s" % (illust.title, illust.image_urls["large"])) -def appapi_ranking(aapi): +def test_appapi_ranking(): json_result = aapi.illust_ranking("day_male") print(json_result) illust = json_result.illusts[0] @@ -194,7 +197,7 @@ def appapi_ranking(aapi): print(">>> %s, origin url: %s" % (illust.title, illust.image_urls["large"])) -def appapi_auth_api(aapi): +def test_appapi_auth_api(): json_result = aapi.illust_follow(req_auth=True) print(json_result) illust = json_result.illusts[0] @@ -214,7 +217,7 @@ def appapi_auth_api(aapi): print(">>> %s, origin url: %s" % (illust.title, illust.image_urls["large"])) -def appapi_bookmark_add(aapi): +def test_appapi_bookmark_add(): illust_id = 74187223 tags = ["Fate/GO", "50000users入り", "私服"] json_result = aapi.illust_bookmark_add(illust_id, tags=tags) @@ -229,7 +232,7 @@ def appapi_bookmark_add(aapi): ) -def appapi_novel(aapi): +def test_appapi_novel(): json_result = aapi.user_novels(59216290) print(json_result) novel = json_result.novels[0] @@ -280,23 +283,13 @@ def appapi_novel(aapi): print(">>> %s, novel_text: %s" % (novel.title, json_result.novel_text)) -def main(): - # app-api - aapi = AppPixivAPI(**_REQUESTS_KWARGS) - - aapi.auth(refresh_token=_REFRESH_TOKEN) - - appapi_illust(aapi) - appapi_recommend(aapi) - appapi_users(aapi) - appapi_search(aapi) - appapi_user_search(aapi) - appapi_ranking(aapi) - appapi_bookmark_add(aapi) - appapi_novel(aapi) - - appapi_auth_api(aapi) - - if __name__ == "__main__": - main() + test_appapi_illust() + test_appapi_recommend() + test_appapi_users() + test_appapi_search() + test_appapi_user_search() + test_appapi_ranking() + test_appapi_bookmark_add() + test_appapi_novel() + test_appapi_auth_api() diff --git a/requirements.development.txt b/requirements.development.txt index d14dfbc4..f4582c84 100644 --- a/requirements.development.txt +++ b/requirements.development.txt @@ -2,6 +2,8 @@ setuptools>=59.6.0 mypy>=0.931 flake8>=4.0.1 types-requests>=2.27.10 +pytest>=7.0.1 +pytest-cov>=3.0.0 flake8-black>=0.3.0 black[jupyter]>=22.1.0 isort>=5.10.1 diff --git a/setup.cfg b/setup.cfg index 4ee1ec9c..9602a84c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,8 @@ dev = mypy>=0.931 flake8>=4.0.1 types-requests>=2.27.10 + pytest>=7.0.1 + pytest-cov>=3.0.0 flake8-black>=0.3.0 black[jupyter]>=22.1.0 isort>=5.10.1