Skip to content

Commit

Permalink
run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyheppell committed Jul 2, 2024
1 parent 5a6e8c6 commit 5750743
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/extractor/extractors/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def load_media(path: Path, link_registry: LinkRegistry) -> Optional[pd.DataFrame

media_df = media_df[media_df.columns.intersection(EXPORT_COLUMNS)]

media_df = media_df.rename(columns=RENAME_COLUMNS, errors='ignore')
media_df = media_df.rename(columns=RENAME_COLUMNS, errors="ignore")

link_registry.add_linkables(
"media", media_df["source_url"].to_list(), media_df.index.to_list()
Expand Down
2 changes: 1 addition & 1 deletion src/extractor/extractors/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def load_pages(path: Path, link_registry: LinkRegistry) -> Optional[pd.DataFrame
)

pages_df = pages_df[pages_df.columns.intersection(EXPORT_COLUMNS)]
pages_df = pages_df.rename(columns=RENAME_COLUMNS, errors='ignore')
pages_df = pages_df.rename(columns=RENAME_COLUMNS, errors="ignore")

link_registry.add_linkables(
"pages", pages_df["link"].to_list(), pages_df.index.to_list()
Expand Down
2 changes: 1 addition & 1 deletion src/extractor/extractors/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def load_posts(
)

posts_df = posts_df[posts_df.columns.intersection(EXPORT_COLUMNS)]
posts_df = posts_df.rename(columns=RENAME_COLUMNS, errors='ignore')
posts_df = posts_df.rename(columns=RENAME_COLUMNS, errors="ignore")

return posts_df

Expand Down
9 changes: 4 additions & 5 deletions tests/extractors/test_posts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from datetime import datetime
from pathlib import Path

Expand All @@ -15,9 +14,8 @@
)
from extractor.parse.translations._resolver import TranslationLink
from helpers.df import ordered_col
from pytest_mock import MockerFixture

from helpers.file import json_without_cols
from pytest_mock import MockerFixture


def mock_translation_extractor(post_bs: BeautifulSoup, link: str, translation_pickers):
Expand Down Expand Up @@ -202,8 +200,9 @@ def test_resolves_media(posts_df_and_registry):
idx=1,
)


def test_no_yoast_columns(datadir, scrape_urls_files):
path = json_without_cols(datadir / "posts.json", {'yoast_head', 'yoast_head_json'})
path = json_without_cols(datadir / "posts.json", {"yoast_head", "yoast_head_json"})

posts_df = load_posts(path, LinkRegistry(), scrape_urls_files, None)
assert posts_df.iloc[0].og_image_url is None
assert posts_df.iloc[0].og_image_url is None
5 changes: 3 additions & 2 deletions tests/extractors/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def test_user_load(datadir, users_df):
expected_df = pd.read_json(datadir / "users_df_out.json", orient="table")
assert users_df.equals(expected_df)


def test_no_yoast_columns(datadir):
path = json_without_cols(datadir / "users.json", {'yoast_head', 'yoast_head_json'})
path = json_without_cols(datadir / "users.json", {"yoast_head", "yoast_head_json"})
users_df = load_users(path)
assert users_df.iloc[0].avatar is None
assert users_df.iloc[0].avatar is None
16 changes: 10 additions & 6 deletions tests/helpers/file.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import json
from pathlib import Path
from typing import List, Set
import tempfile
from pathlib import Path
from typing import Set


def json_without_cols(in_file: Path, del_cols: Set[str]) -> Path:
in_data = json.loads(in_file.read_text())
delete_keys = {'yoast_head', 'yoast_head_json'}
out_data = [{key: item[key] for key, value in item.items() if key not in delete_keys} for item in in_data]
delete_keys = {"yoast_head", "yoast_head_json"}
out_data = [
{key: item[key] for key, value in item.items() if key not in delete_keys}
for item in in_data
]

with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
with tempfile.NamedTemporaryFile(mode="w+", delete=False) as f:
json.dump(out_data, f)
path = f.name

return Path(path)
return Path(path)

0 comments on commit 5750743

Please sign in to comment.