Skip to content

Commit b434d32

Browse files
committed
isort tests/mocks/utils
1 parent 6b3db69 commit b434d32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+105
-71
lines changed

openlibrary/conftest.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
from infogami.infobase.tests.pytest_wildcard import Wildcard
88
from infogami.utils import template
99
from infogami.utils.view import render_template as infobase_render_template
10-
from openlibrary.i18n import gettext
1110
from openlibrary.core import helpers
12-
11+
from openlibrary.i18n import gettext
12+
from openlibrary.mocks.mock_ia import mock_ia # noqa: F401 side effects may be needed
1313
from openlibrary.mocks.mock_infobase import (
1414
mock_site, # noqa: F401 side effects may be needed
1515
)
16-
from openlibrary.mocks.mock_ia import mock_ia # noqa: F401 side effects may be needed
1716
from openlibrary.mocks.mock_memcache import (
1817
mock_memcache, # noqa: F401 side effects may be needed
1918
)

openlibrary/mocks/mock_ia.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33

44
import pytest
5+
56
from openlibrary.core import ia
67

78

openlibrary/mocks/mock_infobase.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import itertools
66
import json
77
import re
8+
from datetime import datetime
9+
810
import pytest
911
import web
1012

11-
from datetime import datetime
12-
13-
from infogami.infobase import client, common, account, config as infobase_config
1413
from infogami import config
14+
from infogami.infobase import account, client, common
15+
from infogami.infobase import config as infobase_config
1516
from openlibrary.plugins.upstream.models import Changeset
1617
from openlibrary.plugins.upstream.utils import safeget
1718

18-
1919
key_patterns = {
2020
'work': '/works/OL%dW',
2121
'edition': '/books/OL%dM',

openlibrary/mocks/mock_ol.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import pytest
21
import re
2+
3+
import pytest
34
import web
5+
46
from infogami import config
57
from infogami.utils import delegate
68

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

12-
from openlibrary.mocks.mock_infobase import mock_site, MockConnection
14+
from openlibrary.mocks.mock_infobase import MockConnection, mock_site
1315
from openlibrary.plugins import ol_infobase
1416

1517

openlibrary/mocks/tests/test_mock_infobase.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
23
import web
34

45

openlibrary/mocks/tests/test_mock_memcache.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from .. import mock_memcache
21
import memcache
32

3+
from .. import mock_memcache
4+
45

56
class Test_mock_memcache:
67
def test_set(self):

openlibrary/tests/accounts/test_models.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from openlibrary.accounts import model, InternetArchiveAccount, OpenLibraryAccount
2-
from requests.models import Response
31
from unittest import mock
42

3+
from requests.models import Response
4+
5+
from openlibrary.accounts import InternetArchiveAccount, OpenLibraryAccount, model
6+
57

68
def get_username(account):
79
return account and account.value

openlibrary/tests/catalog/test_get_ia.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import pytest
21
from pathlib import Path
2+
3+
import pytest
4+
35
from openlibrary.catalog import get_ia
4-
from openlibrary.core import ia
6+
from openlibrary.catalog.marc.marc_binary import BadLength, BadMARC, MarcBinary
57
from openlibrary.catalog.marc.marc_xml import MarcXml
6-
from openlibrary.catalog.marc.marc_binary import MarcBinary, BadLength, BadMARC
7-
8+
from openlibrary.core import ia
89

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

openlibrary/tests/catalog/test_utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from datetime import datetime, timedelta
2+
13
import pytest
24

3-
from datetime import datetime, timedelta
45
from openlibrary.catalog.utils import (
56
author_dates_match,
67
flip_name,

openlibrary/tests/core/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
import pytest
34

45

openlibrary/tests/core/lists/test_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from openlibrary.mocks.mock_infobase import MockSite
21
import openlibrary.core.lists.model as list_model
2+
from openlibrary.mocks.mock_infobase import MockSite
33

44

55
class TestList:

openlibrary/tests/core/test_connections.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This will be moved to core soon.
2-
from openlibrary.plugins.openlibrary import connection as connections
32
import json
43

4+
from openlibrary.plugins.openlibrary import connection as connections
5+
56

67
class MockConnection:
78
def __init__(self):

openlibrary/tests/core/test_db.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import web
2-
from openlibrary.core.db import get_db
2+
3+
from openlibrary.core.booknotes import Booknotes
34
from openlibrary.core.bookshelves import Bookshelves
45
from openlibrary.core.bookshelves_events import BookshelvesEvents
5-
from openlibrary.core.booknotes import Booknotes
6+
from openlibrary.core.db import get_db
67
from openlibrary.core.edits import CommunityEditsQueue
78
from openlibrary.core.observations import Observations
89
from openlibrary.core.ratings import Ratings

openlibrary/tests/core/test_fulltext.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from json.decoder import JSONDecodeError
22
from unittest.mock import Mock, patch
3+
34
import requests
5+
46
from infogami import config
57
from openlibrary.core import fulltext
68

openlibrary/tests/core/test_helpers.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import web
2+
23
from openlibrary.core import helpers as h
34
from openlibrary.mocks.mock_infobase import MockSite
45

openlibrary/tests/core/test_i18n.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import web
2-
from openlibrary.mocks.mock_infobase import MockSite
32

43
# The i18n module should be moved to core.
54
from openlibrary import i18n
5+
from openlibrary.mocks.mock_infobase import MockSite
66

77

88
class MockTranslations(dict):

openlibrary/tests/core/test_imports.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import pytest
21
from typing import Final
2+
3+
import pytest
34
import web
45

56
from openlibrary.core.db import get_db
67
from openlibrary.core.imports import Batch, ImportItem
78

8-
99
IMPORT_ITEM_DDL: Final = """
1010
CREATE TABLE import_item (
1111
id serial primary key,

openlibrary/tests/core/test_models.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from openlibrary.core import models
2-
31
import pytest
42

3+
from openlibrary.core import models
4+
55

66
class MockSite:
77
def get(self, key):
@@ -154,6 +154,7 @@ def test_resolve_redirect_chain(self, monkeypatch):
154154
work4 = {"key": work4_key, "type": type_work}
155155

156156
import web
157+
157158
from openlibrary.mocks import mock_infobase
158159

159160
site = mock_infobase.MockSite()

openlibrary/tests/core/test_processors.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from openlibrary.core.processors import readableurls as processors
2-
from infogami.infobase import client, common
31
import web
42

3+
from infogami.infobase import client, common
4+
from openlibrary.core.processors import readableurls as processors
5+
56

67
class MockSite:
78
def __init__(self):

openlibrary/tests/core/test_processors_invalidation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import web
21
import datetime
32

3+
import web
4+
45
from infogami.infobase import client
56
from openlibrary.core.processors import invalidation
67
from openlibrary.mocks.mock_infobase import MockSite

openlibrary/tests/core/test_unmarshal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from datetime import datetime
21
import re
2+
from datetime import datetime
33

44
import pytest
55

openlibrary/tests/core/test_vendors.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from unittest.mock import patch
33

44
import pytest
5+
56
from openlibrary.core.vendors import (
6-
get_amazon_metadata,
7-
split_amazon_title,
8-
clean_amazon_metadata_for_load,
9-
betterworldbooks_fmt,
107
AmazonAPI,
8+
betterworldbooks_fmt,
9+
clean_amazon_metadata_for_load,
10+
get_amazon_metadata,
1111
is_dvd,
12+
split_amazon_title,
1213
)
1314

1415

openlibrary/tests/core/test_waitinglist.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from openlibrary.core.waitinglist import WaitingLoan
2-
from openlibrary.core import lending
31
import json
2+
43
import pytest
54

5+
from openlibrary.core import lending
6+
from openlibrary.core.waitinglist import WaitingLoan
7+
68

79
class TestWaitingLoan:
810
def test_new(self, monkeypatch):

openlibrary/tests/core/test_wikidata.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import pytest
1+
from datetime import datetime, timedelta
22
from unittest.mock import patch
3+
4+
import pytest
5+
36
from openlibrary.core import wikidata
4-
from datetime import datetime, timedelta
57

68
EXAMPLE_WIKIDATA_DICT = {
79
'id': "Q42",

openlibrary/tests/data/test_dump.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
from openlibrary.data.dump import print_dump, pgdecode
3+
from openlibrary.data.dump import pgdecode, print_dump
44

55

66
class TestPrintDump:

openlibrary/tests/solr/test_query_utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import pytest
2+
23
from openlibrary.solr.query_utils import (
34
EmptyTreeError,
45
luqum_parser,
56
luqum_remove_child,
7+
luqum_remove_field,
68
luqum_replace_child,
7-
luqum_traverse,
89
luqum_replace_field,
9-
luqum_remove_field,
10+
luqum_traverse,
1011
)
1112

1213
REMOVE_TESTS = {

openlibrary/tests/solr/test_types_generator.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from openlibrary.solr.types_generator import generate
44

5-
65
root = os.path.dirname(__file__)
76

87

openlibrary/tests/solr/test_update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
2-
from openlibrary.core.ratings import WorkRatingsSummary
32

3+
from openlibrary.core.ratings import WorkRatingsSummary
44
from openlibrary.solr import update
55
from openlibrary.solr.data_provider import DataProvider, WorkReadingLogSolrSummary
66

openlibrary/tests/solr/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from unittest.mock import MagicMock
33

44
import httpx
5-
from httpx import Response, ConnectError
5+
from httpx import ConnectError, Response
66

77
from openlibrary.solr.utils import SolrUpdateRequest, solr_update
88

openlibrary/tests/solr/updater/test_author.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import httpx
22
import pytest
3+
34
from openlibrary.solr.updater.author import AuthorSolrUpdater
45
from openlibrary.tests.solr.test_update import FakeDataProvider, make_author
56

openlibrary/tests/solr/updater/test_edition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
2-
from openlibrary.solr.updater.edition import EditionSolrUpdater
32

3+
from openlibrary.solr.updater.edition import EditionSolrUpdater
44
from openlibrary.tests.solr.test_update import FakeDataProvider
55

66

openlibrary/tests/solr/updater/test_work.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
from openlibrary.solr.updater.work import (
34
WorkSolrBuilder,
45
WorkSolrUpdater,

openlibrary/utils/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Generic utilities"""
22

3-
from enum import Enum
43
import re
4+
from collections.abc import Callable, Iterable
5+
from enum import Enum
56
from subprocess import CalledProcessError, run
6-
from typing import TypeVar, Literal
7-
from collections.abc import Iterable, Callable
7+
from typing import Literal, TypeVar
88

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

openlibrary/utils/bulkimport.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
going through infobase API.
33
"""
44

5+
import datetime
56
import json
67
import os
7-
import web
8-
import datetime
98
from collections import defaultdict
109

10+
import web
11+
1112

1213
class DocumentLoader:
1314
def __init__(self, **params):

openlibrary/utils/dateutil.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from infogami.utils.view import public
1111

12-
1312
MINUTE_SECS = 60
1413
HALF_HOUR_SECS = MINUTE_SECS * 30
1514
HOUR_SECS = MINUTE_SECS * 60

openlibrary/utils/ddc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"""
99

1010
from __future__ import annotations
11+
1112
import re
12-
from string import printable
1313
from collections.abc import Iterable
14+
from string import printable
1415

1516
MULTIPLE_SPACES_RE = re.compile(r'\s+')
1617
DDC_RE = re.compile(

0 commit comments

Comments
 (0)