Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isort tests/mocks/utils #10094

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions openlibrary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from infogami.infobase.tests.pytest_wildcard import Wildcard
from infogami.utils import template
from infogami.utils.view import render_template as infobase_render_template
from openlibrary.i18n import gettext
from openlibrary.core import helpers

from openlibrary.i18n import gettext
from openlibrary.mocks.mock_ia import mock_ia # noqa: F401 side effects may be needed
from openlibrary.mocks.mock_infobase import (
mock_site, # noqa: F401 side effects may be needed
)
from openlibrary.mocks.mock_ia import mock_ia # noqa: F401 side effects may be needed
from openlibrary.mocks.mock_memcache import (
mock_memcache, # noqa: F401 side effects may be needed
)
Expand Down
1 change: 1 addition & 0 deletions openlibrary/mocks/mock_ia.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

import pytest

from openlibrary.core import ia


Expand Down
8 changes: 4 additions & 4 deletions openlibrary/mocks/mock_infobase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import itertools
import json
import re
from datetime import datetime

import pytest
import web

from datetime import datetime

from infogami.infobase import client, common, account, config as infobase_config
from infogami import config
from infogami.infobase import account, client, common
from infogami.infobase import config as infobase_config
from openlibrary.plugins.upstream.models import Changeset
from openlibrary.plugins.upstream.utils import safeget


key_patterns = {
'work': '/works/OL%dW',
'edition': '/books/OL%dM',
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/mocks/mock_ol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import re

import pytest
import web

from infogami import config
from infogami.utils import delegate

Expand All @@ -9,7 +11,7 @@
except ImportError: # older versions of web.py
from web import AppBrowser

from openlibrary.mocks.mock_infobase import mock_site, MockConnection
from openlibrary.mocks.mock_infobase import MockConnection, mock_site
from openlibrary.plugins import ol_infobase


Expand Down
1 change: 1 addition & 0 deletions openlibrary/mocks/tests/test_mock_infobase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime

import web


Expand Down
3 changes: 2 additions & 1 deletion openlibrary/mocks/tests/test_mock_memcache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .. import mock_memcache
import memcache

from .. import mock_memcache


class Test_mock_memcache:
def test_set(self):
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/tests/accounts/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from openlibrary.accounts import model, InternetArchiveAccount, OpenLibraryAccount
from requests.models import Response
from unittest import mock

from requests.models import Response

from openlibrary.accounts import InternetArchiveAccount, OpenLibraryAccount, model


def get_username(account):
return account and account.value
Expand Down
9 changes: 5 additions & 4 deletions openlibrary/tests/catalog/test_get_ia.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest
from pathlib import Path

import pytest

from openlibrary.catalog import get_ia
from openlibrary.core import ia
from openlibrary.catalog.marc.marc_binary import BadLength, BadMARC, MarcBinary
from openlibrary.catalog.marc.marc_xml import MarcXml
from openlibrary.catalog.marc.marc_binary import MarcBinary, BadLength, BadMARC

from openlibrary.core import ia

TEST_DATA = Path(__file__).parents[2] / 'catalog' / 'marc' / 'tests' / 'test_data'

Expand Down
3 changes: 2 additions & 1 deletion openlibrary/tests/catalog/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta

import pytest

from datetime import datetime, timedelta
from openlibrary.catalog.utils import (
author_dates_match,
flip_name,
Expand Down
1 change: 1 addition & 0 deletions openlibrary/tests/core/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pytest


Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/core/lists/test_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from openlibrary.mocks.mock_infobase import MockSite
import openlibrary.core.lists.model as list_model
from openlibrary.mocks.mock_infobase import MockSite


class TestList:
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/tests/core/test_connections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This will be moved to core soon.
from openlibrary.plugins.openlibrary import connection as connections
import json

from openlibrary.plugins.openlibrary import connection as connections


class MockConnection:
def __init__(self):
Expand Down
5 changes: 3 additions & 2 deletions openlibrary/tests/core/test_db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import web
from openlibrary.core.db import get_db

from openlibrary.core.booknotes import Booknotes
from openlibrary.core.bookshelves import Bookshelves
from openlibrary.core.bookshelves_events import BookshelvesEvents
from openlibrary.core.booknotes import Booknotes
from openlibrary.core.db import get_db
from openlibrary.core.edits import CommunityEditsQueue
from openlibrary.core.observations import Observations
from openlibrary.core.ratings import Ratings
Expand Down
2 changes: 2 additions & 0 deletions openlibrary/tests/core/test_fulltext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from json.decoder import JSONDecodeError
from unittest.mock import Mock, patch

import requests

from infogami import config
from openlibrary.core import fulltext

Expand Down
1 change: 1 addition & 0 deletions openlibrary/tests/core/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import web

from openlibrary.core import helpers as h
from openlibrary.mocks.mock_infobase import MockSite

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/core/test_i18n.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import web
from openlibrary.mocks.mock_infobase import MockSite

# The i18n module should be moved to core.
from openlibrary import i18n
from openlibrary.mocks.mock_infobase import MockSite


class MockTranslations(dict):
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/tests/core/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
from typing import Final

import pytest
import web

from openlibrary.core.db import get_db
from openlibrary.core.imports import Batch, ImportItem


IMPORT_ITEM_DDL: Final = """
CREATE TABLE import_item (
id serial primary key,
Expand Down
5 changes: 3 additions & 2 deletions openlibrary/tests/core/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from openlibrary.core import models

import pytest

from openlibrary.core import models


class MockSite:
def get(self, key):
Expand Down Expand Up @@ -154,6 +154,7 @@ def test_resolve_redirect_chain(self, monkeypatch):
work4 = {"key": work4_key, "type": type_work}

import web

from openlibrary.mocks import mock_infobase

site = mock_infobase.MockSite()
Expand Down
5 changes: 3 additions & 2 deletions openlibrary/tests/core/test_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from openlibrary.core.processors import readableurls as processors
from infogami.infobase import client, common
import web

from infogami.infobase import client, common
from openlibrary.core.processors import readableurls as processors


class MockSite:
def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/tests/core/test_processors_invalidation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import web
import datetime

import web

from infogami.infobase import client
from openlibrary.core.processors import invalidation
from openlibrary.mocks.mock_infobase import MockSite
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/core/test_unmarshal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
import re
from datetime import datetime

import pytest

Expand Down
9 changes: 5 additions & 4 deletions openlibrary/tests/core/test_vendors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from unittest.mock import patch

import pytest

from openlibrary.core.vendors import (
get_amazon_metadata,
split_amazon_title,
clean_amazon_metadata_for_load,
betterworldbooks_fmt,
AmazonAPI,
betterworldbooks_fmt,
clean_amazon_metadata_for_load,
get_amazon_metadata,
is_dvd,
split_amazon_title,
)


Expand Down
6 changes: 4 additions & 2 deletions openlibrary/tests/core/test_waitinglist.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from openlibrary.core.waitinglist import WaitingLoan
from openlibrary.core import lending
import json

import pytest

from openlibrary.core import lending
from openlibrary.core.waitinglist import WaitingLoan


class TestWaitingLoan:
def test_new(self, monkeypatch):
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/tests/core/test_wikidata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from datetime import datetime, timedelta
from unittest.mock import patch

import pytest

from openlibrary.core import wikidata
from datetime import datetime, timedelta

EXAMPLE_WIKIDATA_DICT = {
'id': "Q42",
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/data/test_dump.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from openlibrary.data.dump import print_dump, pgdecode
from openlibrary.data.dump import pgdecode, print_dump


class TestPrintDump:
Expand Down
5 changes: 3 additions & 2 deletions openlibrary/tests/solr/test_query_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest

from openlibrary.solr.query_utils import (
EmptyTreeError,
luqum_parser,
luqum_remove_child,
luqum_remove_field,
luqum_replace_child,
luqum_traverse,
luqum_replace_field,
luqum_remove_field,
luqum_traverse,
)

REMOVE_TESTS = {
Expand Down
1 change: 0 additions & 1 deletion openlibrary/tests/solr/test_types_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from openlibrary.solr.types_generator import generate


root = os.path.dirname(__file__)


Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/solr/test_update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from openlibrary.core.ratings import WorkRatingsSummary

from openlibrary.core.ratings import WorkRatingsSummary
from openlibrary.solr import update
from openlibrary.solr.data_provider import DataProvider, WorkReadingLogSolrSummary

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/solr/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import MagicMock

import httpx
from httpx import Response, ConnectError
from httpx import ConnectError, Response

from openlibrary.solr.utils import SolrUpdateRequest, solr_update

Expand Down
1 change: 1 addition & 0 deletions openlibrary/tests/solr/updater/test_author.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import httpx
import pytest

from openlibrary.solr.updater.author import AuthorSolrUpdater
from openlibrary.tests.solr.test_update import FakeDataProvider, make_author

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/solr/updater/test_edition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from openlibrary.solr.updater.edition import EditionSolrUpdater

from openlibrary.solr.updater.edition import EditionSolrUpdater
from openlibrary.tests.solr.test_update import FakeDataProvider


Expand Down
1 change: 1 addition & 0 deletions openlibrary/tests/solr/updater/test_work.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from openlibrary.solr.updater.work import (
WorkSolrBuilder,
WorkSolrUpdater,
Expand Down
6 changes: 3 additions & 3 deletions openlibrary/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Generic utilities"""

from enum import Enum
import re
from collections.abc import Callable, Iterable
from enum import Enum
from subprocess import CalledProcessError, run
from typing import TypeVar, Literal
from collections.abc import Iterable, Callable
from typing import Literal, TypeVar

to_drop = set(''';/?:@&=+$,<>#%"{}|\\^[]`\n\r''')

Expand Down
5 changes: 3 additions & 2 deletions openlibrary/utils/bulkimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
going through infobase API.
"""

import datetime
import json
import os
import web
import datetime
from collections import defaultdict

import web


class DocumentLoader:
def __init__(self, **params):
Expand Down
1 change: 0 additions & 1 deletion openlibrary/utils/dateutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from infogami.utils.view import public


MINUTE_SECS = 60
HALF_HOUR_SECS = MINUTE_SECS * 30
HOUR_SECS = MINUTE_SECS * 60
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/utils/ddc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"""

from __future__ import annotations

import re
from string import printable
from collections.abc import Iterable
from string import printable

MULTIPLE_SPACES_RE = re.compile(r'\s+')
DDC_RE = re.compile(
Expand Down
Loading
Loading