diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..3a1f201 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,28 @@ +# .coveragerc to control coverage.py +[run] +branch = True +source = mangadlp + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + + # Don't complain about abstract methods, they aren't run: + @(abc\.)?abstractmethod + +ignore_errors = True + diff --git a/.drone.yml b/.drone.yml index d2f0708..1d08347 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,8 +11,6 @@ platform: arch: amd64 trigger: - branch: - - master event: - push @@ -25,17 +23,30 @@ sq_secrets: &sq_secrets sq_analysis: &sq_analysis image: 'cr.44net.ch/drone-plugins/sonarqube' pull: if-not-exists - group: sonarqube + group: test -# build steps +test_plugin: &test_plugin + image: 'cr.44net.ch/drone-plugins/test' + pull: if-not-exists + group: publish + +# steps steps: + # test python code + - name: 'test code and generate coverage report' + <<: *test_plugin + commands: + - coverage erase + - coverage run -m pytest + - coverage xml -i + + # upload analysis to sonarqube - name: 'sonarqube: analyse code' <<: *sq_analysis settings: <<: *sq_secrets sources: . - exclusions: contrib/** - + exclusions: contrib/**, docker/** --- @@ -151,6 +162,43 @@ depends_on: - docker-build-amd64 - docker-build-arm64 +--- +################# +# gitea release # +################# +kind: pipeline +type: docker +name: gitea-release + +platform: + os: linux + arch: amd64 + +trigger: + event: + - tag + +# anchors +gitea_secrets: &gitea_secrets + api_key: + from_secret: gitea-token + +gitea_plugin: &gitea_plugin + image: plugins/gitea-release + pull: if-not-exists + group: publish + +# publish release on gitea +steps: + - name: 'publish or update pypi package' + <<: *gitea_plugin + settings: + base_url: https://git.44net.ch + files: ./* + title: 'manga-dlp release: ${DRONE_TAG}' + note: CHANGELOG.md + <<: *gitea_secrets + #--- ################# ## publish pypi # @@ -161,7 +209,7 @@ depends_on: # #platform: # os: linux -# arch: arm64 +# arch: amd64 # #trigger: # event: @@ -177,9 +225,9 @@ depends_on: #pypi_plugin: &pypi_plugin # image: plugins/pypi # pull: if-not-exists -# group: build +# group: publish # -## build steps arm64 +## publish package on pypi #steps: # - name: 'publish or update pypi package' # <<: *pypi_plugin diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/sonar-project.properties b/sonar-project.properties index f1bc3af..3aac110 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1 +1,2 @@ sonar.python.version=3.9 +sonar.python.coverage.reportPaths=coverage.xml \ No newline at end of file diff --git a/tests/test_api_mangadex.py b/tests/test_api_mangadex.py index 77f0390..48db976 100644 --- a/tests/test_api_mangadex.py +++ b/tests/test_api_mangadex.py @@ -1,18 +1,47 @@ -import pytest from mangadlp.api.mangadex import Mangadex -def test_uuid(): - url = 'https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu' - lang = 'en' - test = Mangadex(url, lang) - assert test.get_manga_uuid() == 'a96676e5-8ae2-425e-b549-7f15dd34a6d8' + +def test_uuid_link(): + url = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" + lang = "en" + forcevol = False + verbose = False + test = Mangadex(url, lang, forcevol, verbose) + assert test.manga_uuid == "a96676e5-8ae2-425e-b549-7f15dd34a6d8" + + +def test_uuid_pure(): + url = "a96676e5-8ae2-425e-b549-7f15dd34a6d8" + lang = "en" + forcevol = False + verbose = False + test = Mangadex(url, lang, forcevol, verbose) + assert test.manga_uuid == "a96676e5-8ae2-425e-b549-7f15dd34a6d8" def test_title(): - url = 'https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu' - lang = 'en' - test = Mangadex(url, lang) - title = test.get_manga_title(test.get_manga_uuid()) - assert title == 'Komi-san wa Komyushou Desu' + url = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" + lang = "en" + forcevol = False + verbose = False + test = Mangadex(url, lang, forcevol, verbose) + assert test.manga_title == "Komi-san wa Komyushou Desu" +def test_chapter_infos(): + url = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" + lang = "en" + forcevol = False + verbose = False + test = Mangadex(url, lang, forcevol, verbose) + chapter_infos = test.get_chapter_infos("1") + chapter_uuid = chapter_infos["uuid"] + chapter_name = chapter_infos["name"] + chapter_num = chapter_infos["chapter"] + chapter_volume = chapter_infos["volume"] + assert [chapter_uuid, chapter_name, chapter_volume, chapter_num] == [ + "e86ec2c4-c5e4-4710-bfaa-7604f00939c7", + "A Normal Person", + "1", + "1", + ] diff --git a/tests/test.txt b/tests/test_list.txt similarity index 84% rename from tests/test.txt rename to tests/test_list.txt index 0aa07dd..a0d8f57 100644 --- a/tests/test.txt +++ b/tests/test_list.txt @@ -1,3 +1,3 @@ https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu https://mangadex.org/title/bd6d0982-0091-4945-ad70-c028ed3c0917/mushoku-tensei-isekai-ittara-honki-dasu -37f5cce0-8070-4ada-96e5-fa24b1bd4ff9 +37f5cce0-8070-4ada-96e5-fa24b1bd4ff9 \ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py index b5f86fb..a9f3d0a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,18 +1,20 @@ -import pytest from pathlib import Path import mangadlp.main as MdlpMain -import mangadlp.utils as MdlpUtils -import mangadlp.downloader as MdlpDownloader + def test_readin_list(): - list_file = Path('test.txt') - test_list = MdlpMain.readin_list(list_file) + list_file = Path("tests/test_list.txt") + test_list = MdlpMain.readin_list(list_file) - assert test_list == ['https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu', 'https://mangadex.org/title/bd6d0982-0091-4945-ad70-c028ed3c0917/mushoku-tensei-isekai-ittara-honki-dasu'] + assert test_list == [ + "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu", + "https://mangadex.org/title/bd6d0982-0091-4945-ad70-c028ed3c0917/mushoku-tensei-isekai-ittara-honki-dasu", + "37f5cce0-8070-4ada-96e5-fa24b1bd4ff9", + ] def check_api(): - url = 'https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu' - test = MdlpMain.check_api(url) + url = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" + test = MdlpMain.check_api(url) - assert test == eval(mangadlp.api.mangadex.Mangadex) \ No newline at end of file + assert test == eval(mangadlp.api.mangadex.Mangadex)