Skip to content

Commit

Permalink
v2.2.2 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
c3kay authored Jan 7, 2024
2 parents a8c944d + 349687c commit 57be3a7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 54 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# directories
.pytest_cache/
.tox/
__pycache__
venv/
dist/
build/
src/*.egg-info/

# coverage files
*/.coverage
*/coverage.xml
.coverage
coverage.xml
24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools >= 65.0.0", "setuptools_scm[toml] >= 7.0.0"]
requires = ["setuptools == 69.0.2", "setuptools_scm[toml] == 8.0.4"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -34,22 +34,22 @@ classifiers = [
"Topic :: Internet :: WWW/HTTP :: Dynamic Content :: News/Diary"
]
dependencies = [
"aiohttp >= 3.8.4",
"aiofiles >= 23.1.0",
"pydantic >= 1.10.11, < 2",
'tomli >= 2.0.1 ; python_version < "3.11"'
"aiohttp == 3.9.1",
"aiofiles == 23.2.1",
"pydantic == 1.10.13, < 2",
'tomli == 2.0.1 ; python_version < "3.11"'
]
dynamic = ["version"]

[project.optional-dependencies]
dev = [
"tox >= 4.6.4",
"pytest >= 7.4.0",
"pytest-asyncio >= 0.21.0",
"pytest-cov >= 4.1.0",
"pytest-mock >= 3.11.1",
"atoma >= 0.0.17",
"langdetect >= 1.0.9"
"tox == 4.11.4",
"pytest == 7.4.4",
"pytest-asyncio == 0.23.3",
"pytest-cov == 4.1.0",
"pytest-mock == 3.12.0",
"atoma == 0.0.17",
"langdetect == 1.0.9"
]

[project.urls]
Expand Down
6 changes: 6 additions & 0 deletions src/hoyolabrssfeeds/hoyolab.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Any
from typing import Dict
from typing import List
Expand Down Expand Up @@ -67,6 +68,11 @@ def _transform_post(post: Dict[str, Any]) -> Dict[str, Any]:
"hoyolab-upload-private", "upload-os-bbs"
)

# weird hoyolab bug/feature, where the content html is just a language code.
# could be fixed by parsing the structured_content and creating html from it.
if re.fullmatch(r"^[a-z]{2}-[a-z]{2}$", post["post"]["content"]):
post["post"]["content"] = "<em>Content not available...</em>"

return post

async def get_news_list(
Expand Down
32 changes: 5 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import re
from datetime import datetime
from pathlib import Path
from platform import system
from typing import Any
from typing import AsyncGenerator
from typing import Dict
from typing import Generator
from typing import List
from unittest.mock import MagicMock
from xml.etree import ElementTree
Expand All @@ -21,33 +19,13 @@
from hoyolabrssfeeds.writers import AbstractFeedFileWriter


# ---- SESSION FIXTURES ----
# ---- GENERAL FIXTURES ----


@pytest.fixture(scope="session")
def event_loop() -> Generator[asyncio.AbstractEventLoop, Any, None]:
if system() == "Windows":
# default policy not working on windows
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore

loop = asyncio.get_event_loop()

yield loop

pending = asyncio.tasks.all_tasks(loop)
loop.run_until_complete(asyncio.gather(*pending))
loop.run_until_complete(asyncio.sleep(1))

loop.close()

# https://stackoverflow.com/questions/65740542/exception-ignored-runtimeerror-event-loop-is-closed-when-using-pytest-asynci


@pytest.fixture(scope="session")
async def client_session(
event_loop: asyncio.AbstractEventLoop,
) -> AsyncGenerator[aiohttp.ClientSession, Any]:
async with aiohttp.ClientSession(loop=event_loop, raise_for_status=True) as cs:
@pytest.fixture()
async def client_session() -> AsyncGenerator[aiohttp.ClientSession, Any]:
loop = asyncio.get_running_loop()
async with aiohttp.ClientSession(loop=loop, raise_for_status=True) as cs:
yield cs


Expand Down
23 changes: 21 additions & 2 deletions tests/test_hoyolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,20 @@ async def test_get_feed_item(
assert fetched_item == feed_item


def test_transform_post() -> None:
def test_leading_line_breaks() -> None:
post = {"post": {"content": "<p><br></p>Hello World"}}

expected = {"post": {"content": "Hello World"}}

transformed_post = hoyolab.HoyolabNews._transform_post(post)

assert transformed_post == expected


def test_private_link_bug() -> None:
post = {
"post": {
"content": '<p><br></p><img src="https://hoyolab-upload-private.hoyolab.com/test.jpg">'
"content": '<img src="https://hoyolab-upload-private.hoyolab.com/test.jpg">'
}
}

Expand All @@ -183,6 +193,15 @@ def test_transform_post() -> None:
assert transformed_post == expected


def test_content_html_bug() -> None:
post = {"post": {"content": "en-us"}}

transformed_post = hoyolab.HoyolabNews._transform_post(post)

# test that the content was replaced/fixed
assert transformed_post["post"]["content"] != "en-us"


# ---- HELPER FUNCTIONS ----


Expand Down
22 changes: 11 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ python =

[testenv]
deps =
pytest >= 7.1.3
pytest-asyncio >= 0.20.1
pytest-cov >= 4.0.0
pytest-mock >= 3.10.0
coverage[toml] >= 6.5.0
atoma >= 0.0.17
langdetect >= 1.0.9
pytest == 7.4.4
pytest-asyncio == 0.23.3
pytest-cov == 4.1.0
pytest-mock == 3.12.0
coverage[toml] == 7.4.0
atoma == 0.0.17
langdetect == 1.0.9
commands = pytest {posargs}

[testenv:type]
deps =
mypy >= 0.991
mypy == 1.8.0
{[testenv]deps}
commands = mypy --install-types --non-interactive {posargs}

[testenv:clean]
skip_install = true
deps = coverage[toml] >= 6.5.0
deps = coverage[toml] == 7.4.0
commands = coverage erase

[testenv:black]
skip_install = true
deps = black >= 22.10.0
deps = black == 23.12.1
commands = black src tests {posargs}

[testenv:flake]
skip_install = true
deps = flake8 >= 5.0.4
deps = flake8 == 7.0.0
commands = flake8 {posargs}


Expand Down

0 comments on commit 57be3a7

Please sign in to comment.