Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Jul 16, 2024
1 parent f85c200 commit e87a47d
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 64 deletions.
9 changes: 7 additions & 2 deletions cds_dojson/marc21/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

from __future__ import absolute_import, print_function

from dojson.utils import (IgnoreKey, filter_values, for_each_value, force_list,
ignore_value)
from dojson.utils import (
IgnoreKey,
filter_values,
for_each_value,
force_list,
ignore_value,
)

from ..models.base import model

Expand Down
35 changes: 25 additions & 10 deletions cds_dojson/marc21/fields/books/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,32 @@
from dojson.errors import IgnoreKey
from dojson.utils import filter_values, flatten, for_each_value, force_list

from cds_dojson.marc21.fields.books.errors import MissingRequiredField, \
UnexpectedValue
from cds_dojson.marc21.fields.books.errors import MissingRequiredField, UnexpectedValue
from cds_dojson.marc21.fields.books.utils import extract_volume_number
from cds_dojson.marc21.fields.books.values_mapping import ACQUISITION_METHOD, \
ARXIV_CATEGORIES, COLLECTION, DOCUMENT_TYPE, EXTERNAL_SYSTEM_IDENTIFIERS, \
EXTERNAL_SYSTEM_IDENTIFIERS_TO_IGNORE, MATERIALS, MEDIUM_TYPES, \
SUBJECT_CLASSIFICATION_EXCEPTIONS, mapping
from cds_dojson.marc21.fields.utils import ManualMigrationRequired, \
build_contributor_books, clean_email, clean_pages_range, clean_val, \
filter_list_values, get_week_start, out_strip, related_url, \
replace_in_result
from cds_dojson.marc21.fields.books.values_mapping import (
ACQUISITION_METHOD,
ARXIV_CATEGORIES,
COLLECTION,
DOCUMENT_TYPE,
EXTERNAL_SYSTEM_IDENTIFIERS,
EXTERNAL_SYSTEM_IDENTIFIERS_TO_IGNORE,
MATERIALS,
MEDIUM_TYPES,
SUBJECT_CLASSIFICATION_EXCEPTIONS,
mapping,
)
from cds_dojson.marc21.fields.utils import (
ManualMigrationRequired,
build_contributor_books,
clean_email,
clean_pages_range,
clean_val,
filter_list_values,
get_week_start,
out_strip,
related_url,
replace_in_result,
)
from cds_dojson.marc21.models.books.base import model

from .utils import extract_parts, is_excluded
Expand Down
17 changes: 11 additions & 6 deletions cds_dojson/marc21/fields/books/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
from dojson.errors import IgnoreKey
from dojson.utils import filter_values, for_each_value

from cds_dojson.marc21.fields.books.errors import ManualMigrationRequired, \
MissingRequiredField, UnexpectedValue
from cds_dojson.marc21.fields.books.utils import extract_parts, \
extract_volume_number, is_excluded
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, \
out_strip
from cds_dojson.marc21.fields.books.errors import (
ManualMigrationRequired,
MissingRequiredField,
UnexpectedValue,
)
from cds_dojson.marc21.fields.books.utils import (
extract_parts,
extract_volume_number,
is_excluded,
)
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, out_strip
from cds_dojson.marc21.models.books.book import model

from .base import alternative_titles as alternative_titles_base
Expand Down
3 changes: 1 addition & 2 deletions cds_dojson/marc21/fields/books/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

from cds_dojson.marc21.fields.books.book import title as base_title
from cds_dojson.marc21.fields.books.errors import UnexpectedValue
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, \
out_strip
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, out_strip
from cds_dojson.marc21.models.books.journal import model


Expand Down
18 changes: 12 additions & 6 deletions cds_dojson/marc21/fields/books/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@
from dojson.errors import IgnoreKey
from dojson.utils import for_each_value, force_list

from cds_dojson.marc21.fields.books.errors import MissingRequiredField, \
UnexpectedValue
from cds_dojson.marc21.fields.books.utils import extract_parts, \
extract_volume_info, extract_volume_number
from cds_dojson.marc21.fields.utils import build_contributor_books, \
clean_val, filter_list_values, out_strip
from cds_dojson.marc21.fields.books.errors import MissingRequiredField, UnexpectedValue
from cds_dojson.marc21.fields.books.utils import (
extract_parts,
extract_volume_info,
extract_volume_number,
)
from cds_dojson.marc21.fields.utils import (
build_contributor_books,
clean_val,
filter_list_values,
out_strip,
)
from cds_dojson.marc21.models.books.multipart import model

from .base import alternative_identifiers as alternative_identifiers_base
Expand Down
6 changes: 2 additions & 4 deletions cds_dojson/marc21/fields/books/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
"""Books fields."""
from dojson.utils import for_each_value

from cds_dojson.marc21.fields.books.multipart import \
isbns as multipart_identifiers
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, \
out_strip
from cds_dojson.marc21.fields.books.multipart import isbns as multipart_identifiers
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, out_strip
from cds_dojson.marc21.models.books.serial import model


Expand Down
3 changes: 1 addition & 2 deletions cds_dojson/marc21/fields/books/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

from cds_dojson.marc21.fields.books.errors import UnexpectedValue
from cds_dojson.marc21.fields.books.utils import extract_parts, is_excluded
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, \
out_strip
from cds_dojson.marc21.fields.utils import clean_val, filter_list_values, out_strip
from cds_dojson.marc21.models.books.standard import model


Expand Down
9 changes: 6 additions & 3 deletions cds_dojson/marc21/fields/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
from dojson.utils import force_list
from six import PY2, iteritems

from cds_dojson.marc21.fields.books.errors import ManualMigrationRequired, \
MissingRequiredField, UnexpectedValue
from cds_dojson.marc21.fields.books.errors import (
ManualMigrationRequired,
MissingRequiredField,
UnexpectedValue,
)
from cds_dojson.utils import MementoDict


Expand Down Expand Up @@ -353,6 +356,7 @@ def _extract_json_ids(info, provenence='source'):
regex = re.compile(r'((AUTHOR\|\((CDS|INSPIRE)\))|(\(SzGeCERN\)))(.*)')
ids = []
author_ids = force_list(info.get('0', ''))

for author_id in author_ids:
match = regex.match(author_id)
if match:
Expand All @@ -374,7 +378,6 @@ def _extract_json_ids(info, provenence='source'):
ids.append({'value': info['inspireid'], provenence: 'INSPIRE ID'})
except KeyError:
pass

return ids


Expand Down
10 changes: 6 additions & 4 deletions cds_dojson/marc21/fields/videos/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
from __future__ import absolute_import, print_function

from dojson.errors import IgnoreKey
from dojson.utils import filter_values, for_each_value, force_list, \
ignore_value
from dojson.utils import filter_values, for_each_value, force_list, ignore_value

from ...fields.utils import build_contributor_from_508, \
build_contributor_videos, clean_val
from ...fields.utils import (
build_contributor_from_508,
build_contributor_videos,
clean_val,
)
from ...models.videos.base import model


Expand Down
3 changes: 1 addition & 2 deletions cds_dojson/marc21/fields/videos/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

import arrow
from dojson.errors import IgnoreKey
from dojson.utils import filter_values, for_each_value, force_list, \
ignore_value
from dojson.utils import filter_values, for_each_value, force_list, ignore_value
from six import iteritems

from ...models.videos.video import model
Expand Down
1 change: 1 addition & 0 deletions tests/demo/json_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
host='cds.cern.ch')
def resolve_definitions(path):
"""Resolve the JSON definition schema."""

with open(pkg_resources.resource_filename(
'cds_dojson.schemas', path), 'r') as f:
return json.load(f)
3 changes: 2 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def validate(json):
json,
json['$schema'],
resolver=json_resolver(json['$schema']),
types={'array': (list, tuple)})
# types={'array': (list, tuple)}
)


def load_fixture_file(file_name):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_books.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
import pytest
from dojson.errors import MissingRule

from cds_dojson.marc21.fields.books.errors import ManualMigrationRequired, \
MissingRequiredField, UnexpectedValue
from cds_dojson.marc21.fields.books.errors import (
ManualMigrationRequired,
MissingRequiredField,
UnexpectedValue,
)
from cds_dojson.marc21.fields.books.values_mapping import MATERIALS, mapping
from cds_dojson.marc21.models.books.base import get_migration_dict
from cds_dojson.marc21.models.books.book import model
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
def test_cli(src, compiled):
"""Test cds-dojson CLI."""
runner = CliRunner()

result = runner.invoke(compile_schema, [
pkg_resources.resource_filename('cds_dojson.schemas', src)
])
Expand Down
18 changes: 14 additions & 4 deletions tests/test_fields_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@
import pytest
from dojson.errors import IgnoreKey

from cds_dojson.marc21.fields.utils import ManualMigrationRequired, \
MissingRequiredField, UnexpectedValue, clean_email, clean_pages_range, \
clean_str, clean_val, filter_list_values, get_week_start, out_strip, \
related_url, replace_in_result
from cds_dojson.marc21.fields.utils import (
ManualMigrationRequired,
MissingRequiredField,
UnexpectedValue,
clean_email,
clean_pages_range,
clean_str,
clean_val,
filter_list_values,
get_week_start,
out_strip,
related_url,
replace_in_result,
)


def test_clean_pages():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import pytest
from dojson.contrib import marc21 as default

from cds_dojson.marc21.models.books import book, journal, multipart, serial, \
standard
from cds_dojson.marc21.models.books import book, journal, multipart, serial, standard
from cds_dojson.marc21.models.videos import project, video
from cds_dojson.matcher import matcher

Expand Down
3 changes: 1 addition & 2 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import pytest
from dojson.errors import MissingRule

from cds_dojson.marc21.fields.books.errors import MissingRequiredField, \
UnexpectedValue
from cds_dojson.marc21.fields.books.errors import MissingRequiredField, UnexpectedValue
from cds_dojson.marc21.models.books.base import get_migration_dict
from cds_dojson.marc21.models.books.multipart import model as multipart_model
from cds_dojson.marc21.models.books.serial import model as serial_model
Expand Down
16 changes: 12 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@

import json
import os

import pytest
from dojson.utils import filter_values

from cds_dojson.marc21.fields.books.errors import MissingRequiredField
from cds_dojson.marc21.fields.books.utils import extract_volume_info, \
extract_volume_number
from cds_dojson.utils import MementoDict, convert_date_to_iso_8601, \
for_each_squash, not_accessed_keys, yaml2json
from cds_dojson.marc21.fields.books.utils import (
extract_volume_info,
extract_volume_number,
)
from cds_dojson.utils import (
MementoDict,
convert_date_to_iso_8601,
for_each_squash,
not_accessed_keys,
yaml2json,
)


def test_for_each_squash():
Expand Down
4 changes: 1 addition & 3 deletions tests/test_videos_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Video rules tests."""
import mock

from helpers import load_fixture_file, validate
from helpers import load_fixture_file, mock_contributor_fetch, validate

from cds_dojson.marc21.fields.videos.utils import language_to_isocode
from cds_dojson.marc21.models.videos.project import model
from cds_dojson.marc21.utils import create_record
from helpers import load_fixture_file, mock_contributor_fetch, validate


def test_required_fields(app):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_videos_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Video rules tests."""
import mock

from helpers import load_fixture_file, validate
from helpers import load_fixture_file, mock_contributor_fetch, validate

from cds_dojson.marc21.fields.videos.utils import language_to_isocode
from cds_dojson.marc21.models.videos.video import model
from cds_dojson.marc21.utils import create_record
from helpers import load_fixture_file, mock_contributor_fetch, validate


def test_required_fields(app):
Expand Down Expand Up @@ -600,7 +598,7 @@ def check_transformation(marcxml_body, json_body):
},
{
'role': 'Producer',
'ids': [{'source': 'CDS', 'value': '1231231'}],
'ids': [{'source': 'CDS', 'value': "CDS"}],
'name': 'Jessica, Jones'
},
]
Expand Down

0 comments on commit e87a47d

Please sign in to comment.