Skip to content

Commit

Permalink
libcovebods: Improve code formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Sep 22, 2024
1 parent 51a9462 commit d6e80ff
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 83 deletions.
5 changes: 2 additions & 3 deletions libcovebods/jsonschemavalidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from jsonschema import FormatChecker
from jsonschema.exceptions import ValidationError
from jsonschema.validators import Draft4Validator
from jsonschema.validators import Draft202012Validator
from jsonschema.validators import Draft4Validator, Draft202012Validator

import libcovebods.data_reader
from libcovebods.schema import SchemaBODS
Expand Down Expand Up @@ -157,7 +156,7 @@ def json(self):
path_ending = self._path[-1]
if isinstance(self._path[-1], int) and len(self._path) >= 2:
# We're dealing with elements in an array of items at this point
path_ending = "{}/[number]".format(self._path[-2])
path_ending = f"{self._path[-2]}/[number]"
elif isinstance(self._path[0], int) and len(self._path) == 1:
path_ending = "[number]"
else:
Expand Down
2 changes: 1 addition & 1 deletion libcovebods/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import libcovebods.data_reader
from libcovebods.config import LibCoveBODSConfig
from libcovebods.schema_dir import schema_registry, get_scheme_file_data
from libcovebods.schema_dir import get_scheme_file_data, schema_registry

try:
from functools import cached_property
Expand Down
5 changes: 3 additions & 2 deletions libcovebods/schema_dir.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
from pathlib import Path
from jscc.schema import is_json_schema, is_codelist, is_missing_property
from jscc.testing.filesystem import walk_json_data, walk_csv_data

from jscc.schema import is_json_schema
from jscc.testing.filesystem import walk_json_data
from referencing import Registry, Resource
from referencing.jsonschema import DRAFT202012

Expand Down
88 changes: 44 additions & 44 deletions libcovebods/tasks/checks.py

Large diffs are not rendered by default.

51 changes: 34 additions & 17 deletions libcovebods/tasks/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def get_statistics(self):
data = {
"count_entity_statements": self.count_entity_statements,
"count_entity_statements_types": self.count_entity_statements_types,
"count_entity_statements_types_with_any_identifier": self.count_entity_statements_types_with_any_identifier,
"count_entity_statements_types_with_any_identifier_with_id_and_scheme": self.count_entity_statements_types_with_any_identifier_with_id_and_scheme,
"count_entity_statements_types_with_any_identifier":
self.count_entity_statements_types_with_any_identifier,
"count_entity_statements_types_with_any_identifier_with_id_and_scheme":
self.count_entity_statements_types_with_any_identifier_with_id_and_scheme,
}
return data

Expand Down Expand Up @@ -125,8 +127,10 @@ def get_statistics(self):
data = {
"count_entity_statements": self.count_entity_statements,
"count_entity_statements_types": self.count_entity_statements_types,
"count_entity_statements_types_with_any_identifier": self.count_entity_statements_types_with_any_identifier,
"count_entity_statements_types_with_any_identifier_with_id_and_scheme": self.count_entity_statements_types_with_any_identifier_with_id_and_scheme,
"count_entity_statements_types_with_any_identifier":
self.count_entity_statements_types_with_any_identifier,
"count_entity_statements_types_with_any_identifier_with_id_and_scheme":
self.count_entity_statements_types_with_any_identifier_with_id_and_scheme,
}
return data

Expand Down Expand Up @@ -281,18 +285,25 @@ def check_ownership_or_control_statement_first_pass(self, statement):
def get_statistics(self):
data = {
"count_ownership_or_control_statement": self.count_ownership_or_control_statement,
"count_ownership_or_control_statement_interested_party_with_person": self.count_ownership_or_control_statement_interested_party_with_person,
"count_ownership_or_control_statement_interested_party_with_entity": self.count_ownership_or_control_statement_interested_party_with_entity,
"count_ownership_or_control_statement_interested_party_with_unspecified": self.count_ownership_or_control_statement_interested_party_with_unspecified,
"count_ownership_or_control_statement_interest_statement_types": self.count_ownership_or_control_statement_interest_statement_types,
"count_ownership_or_control_statement_interested_party_with_person":
self.count_ownership_or_control_statement_interested_party_with_person,
"count_ownership_or_control_statement_interested_party_with_entity":
self.count_ownership_or_control_statement_interested_party_with_entity,
"count_ownership_or_control_statement_interested_party_with_unspecified":
self.count_ownership_or_control_statement_interested_party_with_unspecified,
"count_ownership_or_control_statement_interest_statement_types":
self.count_ownership_or_control_statement_interest_statement_types,
"count_ownership_or_control_statement_by_year": self.count_ownership_or_control_statement_by_year,
"count_ownership_or_control_statement_subject_by_year": {
year: len(year_set)
for year, year_set in self.subject_statement_ids_by_year.items()
},
"count_ownership_or_control_statement_interested_party_with_entity_by_year": self.count_ownership_or_control_statement_interested_party_with_entity_by_year,
"count_ownership_or_control_statement_interested_party_with_person_by_year": self.count_ownership_or_control_statement_interested_party_with_person_by_year,
"count_ownership_or_control_statement_interested_party_with_unspecified_by_year": self.count_ownership_or_control_statement_interested_party_with_unspecified_by_year,
"count_ownership_or_control_statement_interested_party_with_entity_by_year":
self.count_ownership_or_control_statement_interested_party_with_entity_by_year,
"count_ownership_or_control_statement_interested_party_with_person_by_year":
self.count_ownership_or_control_statement_interested_party_with_person_by_year,
"count_ownership_or_control_statement_interested_party_with_unspecified_by_year":
self.count_ownership_or_control_statement_interested_party_with_unspecified_by_year,
}
return data

Expand Down Expand Up @@ -353,14 +364,18 @@ def check_ownership_or_control_statement_first_pass(self, statement):
def get_statistics(self):
data = {
"count_ownership_or_control_statement": self.count_ownership_or_control_statement,
"count_ownership_or_control_statement_interested_party": self.count_ownership_or_control_statement_interested_party,
"count_ownership_or_control_statement_interest_statement_types": self.count_ownership_or_control_statement_interest_statement_types,
"count_ownership_or_control_statement_by_year": self.count_ownership_or_control_statement_by_year,
"count_ownership_or_control_statement_interested_party":
self.count_ownership_or_control_statement_interested_party,
"count_ownership_or_control_statement_interest_statement_types":
self.count_ownership_or_control_statement_interest_statement_types,
"count_ownership_or_control_statement_by_year":
self.count_ownership_or_control_statement_by_year,
"count_ownership_or_control_statement_subject_by_year": {
year: len(year_set)
for year, year_set in self.subject_statement_ids_by_year.items()
},
"count_ownership_or_control_statement_interested_party_by_year": self.count_ownership_or_control_statement_interested_party_by_year,
"count_ownership_or_control_statement_interested_party_by_year":
self.count_ownership_or_control_statement_interested_party_by_year,
}
return data

Expand Down Expand Up @@ -447,7 +462,8 @@ def get_statistics(self):
"count_addresses": self.count_addresses,
"count_addresses_with_postcode": self.count_addresses_with_postcode,
"count_addresses_with_country": self.count_addresses_with_country,
"count_addresses_with_postcode_duplicated_in_address": self.count_addresses_with_postcode_duplicated_in_address,
"count_addresses_with_postcode_duplicated_in_address":
self.count_addresses_with_postcode_duplicated_in_address,
}
return data

Expand Down Expand Up @@ -485,7 +501,8 @@ def check_ownership_or_control_statement_first_pass(self, statement):

def get_statistics(self):
return {
"count_ownership_or_control_statement_interest_direct_or_indirect": self.count_ownership_or_control_statement_interest_direct_or_indirect,
"count_ownership_or_control_statement_interest_direct_or_indirect":
self.count_ownership_or_control_statement_interest_direct_or_indirect,
}


Expand Down
3 changes: 1 addition & 2 deletions libcovebods/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import json
import re

from dateutil import parser
Expand Down Expand Up @@ -58,7 +57,7 @@ def numeric_value(value):
try:
float(value)
return True
except:
except ValueError:
return False

def sort_by_date(list_with_date, index):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ lint.select = [
"C4", # flake8-comprehensions
"UP", # pyupgrade
]
line-length = 140
7 changes: 4 additions & 3 deletions tests/test_additional_checks_0_4_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from tests.api import bods_json_output


def test_retrievedat_not_future_date_invalid_1():

cove_temp_folder = tempfile.mkdtemp(
Expand Down Expand Up @@ -1336,7 +1337,7 @@ def test_statement_series_valid_2():
assert results["additional_fields_count"] == 0
assert results["additional_checks_count"] == 0

def test_statement_series_invalid_1():
def test_statement_relationship_component_records_are_record_ids_invalid_1():

cove_temp_folder = tempfile.mkdtemp(
prefix="lib-cove-bods-tests-", dir=tempfile.gettempdir()
Expand All @@ -1358,7 +1359,7 @@ def test_statement_series_invalid_1():
assert results["additional_fields_count"] == 0
assert results["additional_checks_count"] == 1

def test_statement_series_invalid_2():
def test_statement_relationship_component_records_are_record_ids_invalid_2():

cove_temp_folder = tempfile.mkdtemp(
prefix="lib-cove-bods-tests-", dir=tempfile.gettempdir()
Expand All @@ -1380,7 +1381,7 @@ def test_statement_series_invalid_2():
assert results["additional_fields_count"] == 0
assert results["additional_checks_count"] == 1

def test_statement_series_valid_1():
def test_statement_relationship_component_records_are_record_ids_valid_1():

cove_temp_folder = tempfile.mkdtemp(
prefix="lib-cove-bods-tests-", dir=tempfile.gettempdir()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_api_0_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,8 @@ def test_badfile_all_validation_errors():
"badfile_all_validation_errors.json",
)
# This file is generated with
# libcovebods jsv tests/fixtures/0.1/badfile_all_validation_errors.json > tests/fixtures/0.1/badfile_all_validation_errors.expected.json
# libcovebods jsv tests/fixtures/0.1/badfile_all_validation_errors.json >
# tests/fixtures/0.1/badfile_all_validation_errors.expected.json
expected_json_filename = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"fixtures",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lib_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_this_YYYY(self):
def test_this_YYYY_MM(self):
today = dateutil.utils.today(UTC)
assert (
is_interest_current({"endDate": "{}-{}".format(today.year, today.month)})
is_interest_current({"endDate": f"{today.year}-{today.month}"})
is True
)

Expand Down
9 changes: 5 additions & 4 deletions tests/test_schema_validation_0_4.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import csv
import os
import pathlib
import pytest
import tempfile

import pytest

from tests.api import bods_json_output


@pytest.fixture
def expected_errors():
expected = []
Expand All @@ -29,7 +30,8 @@ def extract_elements(element_path):
out.append(0)
else:
out.append(elem)
if len(out) == 1 and out[0] == '$': out = []
if (len(out) == 1 and out[0] == '$'):
out = []
return out

def test_all_schema_validation_invalid(expected_errors):
Expand Down Expand Up @@ -62,7 +64,6 @@ def test_all_schema_validation_invalid(expected_errors):
else:
print(expected)
print(results['validation_errors'][0])
assert False


def test_all_schema_validation_valid(valid_statements):
Expand Down
1 change: 1 addition & 0 deletions tests/test_stat_count_declaration_subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from tests.api import bods_json_output


def test_schema_0_4_count():

cove_temp_folder = tempfile.mkdtemp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_schema_0_3_basic_1():
assert results["schema_version"] == "0.3"

# We want to test the dict has the correct keys!
# So these tests are deliberately written so they will error if the specified key is not in that dict
# So these tests are deliberately written so they will error if the specified key
# is not in that dict
assert (
1
== results["statistics"][
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ def test_schema_0_1():

assert results["schema_version"] == "0.1"

# Schema v0.1 and Schema v0.2 have different enum options, make sure that is reflected in data
# Schema v0.1 and Schema v0.2 have different enum options, make sure that
# is reflected in data
keys = results["statistics"][
"count_ownership_or_control_statement_interest_statement_types"
].keys()
assert 12 == len(keys)

# We want to test the dict has the correct keys!
# So these tests are deliberately written so they will error if the specified key is not in that dict
# So these tests are deliberately written so they will error if the specified
# key is not in that dict
assert (
1
== results["statistics"][
Expand Down Expand Up @@ -112,14 +114,16 @@ def test_schema_0_2():

assert results["schema_version"] == "0.2"

# Schema v0.1 and Schema v0.2 have different enum options, make sure that is reflected in data
# Schema v0.1 and Schema v0.2 have different enum options, make sure that
# is reflected in data
keys = results["statistics"][
"count_ownership_or_control_statement_interest_statement_types"
].keys()
assert 14 == len(keys)

# We want to test the dict has the correct keys!
# So these tests are deliberately written so they will error if the specified key is not in that dict
# So these tests are deliberately written so they will error if the specified key
# is not in that dict
assert (
1
== results["statistics"][
Expand Down Expand Up @@ -204,3 +208,4 @@ def test_schema_0_2():
"count_ownership_or_control_statement_interest_statement_types"
]["conditional-rights-granted-by-contract"]
) # noqa

0 comments on commit d6e80ff

Please sign in to comment.