Skip to content

Commit

Permalink
ruff check fix
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyheppell committed Jul 2, 2024
1 parent 457f327 commit cf719a1
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 39 deletions.
6 changes: 4 additions & 2 deletions src/extractor/parse/translations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from ._extractor import PickerListType # noqa: F401
from ._extractor import extract_translations # noqa: F401
from ._extractor import (
PickerListType, # noqa: F401
extract_translations, # noqa: F401
)
from ._pickers import LangPicker # noqa: F401
2 changes: 1 addition & 1 deletion src/extractor/util/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def extract_locale(link: str) -> Optional[str]:
parsed_link = urllib.parse.urlparse(link)
path_stripped = remove_ends(parsed_link.path, "/")
path_parts = path_stripped.split("/")
if tag_is_valid(path_parts[0]) and not path_parts[0] in EXCLUDED_TAGS:
if tag_is_valid(path_parts[0]) and path_parts[0] not in EXCLUDED_TAGS:
lang = Language.get(path_parts[0], normalize=True)
if lang.extensions is not None:
# Language tag extensions are very unlikely to be used
Expand Down
1 change: 0 additions & 1 deletion tests/extractors/data/test_link_resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from extractor.extractors.data.link_resolver import resolve_link
from extractor.extractors.data.links import LinkRegistry, ResolvableLink

Expand Down
7 changes: 3 additions & 4 deletions tests/extractors/test_categories.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import numpy as np
import pandas as pd
import pytest
from helpers.df import ordered_col

from extractor.extractors.categories import load_categories
from extractor.extractors.data.links import LinkRegistry
from helpers.df import ordered_col


@pytest.fixture
@pytest.fixture()
def categories_df_and_registry(datadir):
link_registry = LinkRegistry()
return load_categories(datadir / "categories.json", link_registry), link_registry


@pytest.fixture
@pytest.fixture()
def categories_df(categories_df_and_registry):
categories_df, _ = categories_df_and_registry
return categories_df
Expand Down
3 changes: 1 addition & 2 deletions tests/extractors/test_io.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import pandas as pd
from helpers.df import ordered_col

from extractor.extractors.io import (
df_denormalize_to_dict,
export_df,
load_df,
load_from_path,
)
from helpers.df import ordered_col


def test_load_from_path(datadir):
Expand Down
5 changes: 2 additions & 3 deletions tests/extractors/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import pandas as pd
import pytest

from extractor.extractors.data.links import LinkRegistry
from extractor.extractors.media import load_media


@pytest.fixture
@pytest.fixture()
def media_df_and_registry(datadir):
link_registry = LinkRegistry()
return load_media(datadir / "media.json", link_registry), link_registry


@pytest.fixture
@pytest.fixture()
def media_df(media_df_and_registry):
media_df, _ = media_df_and_registry
return media_df
Expand Down
7 changes: 3 additions & 4 deletions tests/extractors/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import pandas as pd
import pytest
from helpers.df import ordered_col

from extractor.extractors.data.links import LinkRegistry
from extractor.extractors.pages import load_pages
from helpers.df import ordered_col


@pytest.fixture
@pytest.fixture()
def pages_df_and_registry(datadir):
link_registry = LinkRegistry()
return load_pages(datadir / "pages.json", link_registry), link_registry


@pytest.fixture
@pytest.fixture()
def pages_df(pages_df_and_registry):
pages_df, _ = pages_df_and_registry
return pages_df
Expand Down
17 changes: 8 additions & 9 deletions tests/extractors/test_posts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from datetime import datetime
from pathlib import Path

import extractor
import pandas as pd
import pytest
from bs4 import BeautifulSoup
from helpers.df import ordered_col
from pytest_mock import MockerFixture

import extractor
from extractor.extractors.data.links import Linkable, LinkRegistry
from extractor.extractors.posts import (
ensure_translations_undirected,
Expand All @@ -16,6 +13,8 @@
resolve_post_translations,
)
from extractor.parse.translations._resolver import TranslationLink
from helpers.df import ordered_col
from pytest_mock import MockerFixture


def mock_translation_extractor(post_bs: BeautifulSoup, link: str, translation_pickers):
Expand Down Expand Up @@ -49,14 +48,14 @@ def mock_translation_extractor(post_bs: BeautifulSoup, link: str, translation_pi
)


@pytest.fixture
@pytest.fixture()
def _do_mock_translation_extractor(mocker: MockerFixture):
mocker.patch(
"extractor.extractors.posts.extract_translations", mock_translation_extractor
)


@pytest.fixture
@pytest.fixture()
def scrape_urls_files(datadir: Path):
def _scrape_path(slug):
return (datadir / "scrape" / slug / "index.html").resolve()
Expand All @@ -70,7 +69,7 @@ def _scrape_path(slug):
}


@pytest.fixture
@pytest.fixture()
def posts_df_and_registry(_do_mock_translation_extractor, datadir, scrape_urls_files):
link_registry = LinkRegistry()
return (
Expand All @@ -79,7 +78,7 @@ def posts_df_and_registry(_do_mock_translation_extractor, datadir, scrape_urls_f
)


@pytest.fixture
@pytest.fixture()
def posts_df(posts_df_and_registry):
posts_df, _ = posts_df_and_registry
return posts_df
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_language(posts_df):
assert posts_df["language"].equals(ordered_col(["en", "fr", None]))


@pytest.fixture
@pytest.fixture()
def spy_extractor_data(mocker: MockerFixture):
return mocker.spy(extractor.extractors.posts, "extract_content_data")

Expand Down
7 changes: 3 additions & 4 deletions tests/extractors/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import pandas as pd
import pytest
from helpers.df import ordered_col

from extractor.extractors.data.links import LinkRegistry
from extractor.extractors.tags import load_tags
from helpers.df import ordered_col


@pytest.fixture
@pytest.fixture()
def tags_df_and_registry(datadir):
link_registry = LinkRegistry()
return load_tags(datadir / "tags.json", link_registry), link_registry


@pytest.fixture
@pytest.fixture()
def tags_df(tags_df_and_registry):
tags_df, _ = tags_df_and_registry
return tags_df
Expand Down
3 changes: 1 addition & 2 deletions tests/extractors/test_users.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pandas as pd
import pytest

from extractor.extractors.users import load_users


@pytest.fixture
@pytest.fixture()
def users_df(datadir):
return load_users(datadir / "users.json")

Expand Down
1 change: 0 additions & 1 deletion tests/parse/test_content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path

from bs4 import BeautifulSoup

from extractor.extractors.data.images import MediaUse, ResolvableMediaUse
from extractor.extractors.data.links import Link, ResolvableLink
from extractor.parse.content import (
Expand Down
5 changes: 2 additions & 3 deletions tests/parse/translations/test_pickers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from pathlib import Path
from typing import Type

import extractor.parse.translations._pickers as pickers
import pytest
from bs4 import BeautifulSoup
from langcodes import Language

import extractor.parse.translations._pickers as pickers
from extractor.parse.translations._resolver import TranslationLink
from langcodes import Language


@pytest.mark.parametrize(
Expand Down
1 change: 0 additions & 1 deletion tests/util/test_args.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from argparse import ArgumentTypeError

import pytest

from extractor.util.args import directory, empty_directory


Expand Down
1 change: 0 additions & 1 deletion tests/util/test_locale.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from extractor.util.locale import extract_locale


Expand Down
1 change: 0 additions & 1 deletion tests/util/test_str.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from extractor.util.str import (
ensure_suffix,
remove_ends,
Expand Down

0 comments on commit cf719a1

Please sign in to comment.