Skip to content

Commit

Permalink
Fix linting errors + update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmcdonnell committed Aug 16, 2024
1 parent bf9297d commit 75ed1a9
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/code_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
pdm sync --dev -G:all
- run: |
pdm run make lint
pdm run make lint-complexity
# TODO: fix the src/ssm_client/io/ssm_json.py methods first
#pdm run make lint-complexity
# Run unit tests only on Windows/MacOS, we can run the full test suite on Linux
test-unit:
Expand Down
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "ssm_client", "ssm-client Documentation", [author], 1)]
man_pages = [
(master_doc, "ssm_client", "ssm-client Documentation", [author], 1)
]


# -- Options for Texinfo output ----------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/ssm_client/containers/collection_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def __ne__(self, other):
Support "!=" comparison between CollectionContainers
Args:
other (CollectionContainer): Collection to compare for non-equality.
other (CollectionContainer):
Collection to compare for non-equality.
Return:
areCollectionsNotEqual (bool)
Expand Down
3 changes: 2 additions & 1 deletion src/ssm_client/services/collection_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def create(self, title: str) -> CollectionContainer:
Args:
title (str): title for collection
Returns:
collection (CollectionContainer): Created CollectionContainer object
collection (CollectionContainer):
Created CollectionContainer object
"""
json = {"title": title}
response = requests.post(self._endpoint(), json=json)
Expand Down
37 changes: 25 additions & 12 deletions src/ssm_client/services/dataset_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@


class MismatchedCollectionException(Exception):
"""Raised when CollectionContainer title doesn't match same title passed in"""
"""
Raised when CollectionContainer title doesn't match
same title passed in
"""


class UnsupportedDatasetFormatException(Exception):
Expand All @@ -21,27 +24,32 @@ class UnsupportedDatasetFormatException(Exception):

class DatasetService:
def __init__(
self, hostname="http://localhost", collection=None, collection_title=None
self,
hostname="http://localhost",
collection=None,
collection_title=None,
):
"""
Initialize a DatasetService object
Args:
hostname (str): Hostname for the SSM Catalog API server
collection (CollectionContainer): collection the Datasets will belong to
collection_title (str): Title of the collection the Datasets will belong to
collection (CollectionContainer): collection for dataset
collection_title (str): Title of the collection for dataset
Raises:
MistmatchedcollectionException:
Raised when collection and title both passed in and do not match
Raised when collection and title do not match
"""
self.hostname = hostname

if collection and collection_title:
if collection.title != collection_title:
msg = (
"collection: {collection_title} and title: {title} NOT equal!\n"
"Trying using one method, either the collection OR the title"
"collection: {collection_title} and title: {title}"
"NOT equal!\n"
"Trying using one method, "
"either the collection OR the title"
)
msg = msg.format(
collection_title=collection.title, title=collection_title
Expand Down Expand Up @@ -84,7 +92,8 @@ def create(self, dataset):
dataset (dict): JSON-LD Dataset to create for collection
Raises:
requests.HTTPError: Raised when we cannot find the collection or Dataset
requests.HTTPError: Raised when we cannot find
the collection or Dataset
Returns:
dataset (DatasetContainer): Created DatasetContainer object
Expand Down Expand Up @@ -113,7 +122,8 @@ def get_by_uuid(self, uuid, format: str = _FORMAT_JSONLD):
Default: "jsonld" Choices: ["json", "jsonld"]
Raises:
requests.HTTPError: Raised when we cannot find the collection or dataset
requests.HTTPError: Raised when we cannot find
the collection or dataset
Returns:
dataset (DatasetContainer): DatasetContainer object with given UUID
Expand Down Expand Up @@ -148,7 +158,8 @@ def replace_dataset_for_uuid(self, uuid, dataset):
dataset (dict): JSON-LD for Dataset to replace
Raises:
requests.HTTPError: Raised when we cannot find the collection or dataset
requests.HTTPError: Raised when we cannot find
the collection or dataset
Returns:
new_dataset (DatasetContainer): Updated DatasetContainer object
Expand All @@ -166,7 +177,8 @@ def update_dataset_for_uuid(self, uuid, dataset):
dataset (dict): JSON-LD with partial dataset to update
Raises:
requests.HTTPError: Raised when we cannot find the collection or dataset
requests.HTTPError: Raised when we cannot find
the collection or dataset
Returns:
new_dataset (DatasetContainer): Updated DatasetContainer object
Expand All @@ -183,7 +195,8 @@ def delete_by_uuid(self, uuid):
uuid (str): 64-character UUID for dataset
Raises:
requests.HTTPError: Raised when we cannot find the collection or dataset
requests.HTTPError: Raised when we cannot find
the collection or dataset
"""
response = requests.delete(self._endpoint(uuid))
response.raise_for_status()
3 changes: 2 additions & 1 deletion src/ssm_client/ssm_rester.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def initialize_dataset_for_collection(self, collection):
Initialize the Dataset service for collection
Args:
collection (CollectionContainer): collection to setup a DatasetService for
collection (CollectionContainer): collection to setup
DatasetService for
"""

self.dataset = DatasetService(
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

def pytest_addoption(parser):
parser.addoption(
"--base-url", default="http://localhost", help="Base url for Calatog API"
"--base-url",
default="http://localhost",
help="Base url for Calatog API",
)


Expand Down
23 changes: 17 additions & 6 deletions tests/e2e/test_ssm_rester.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_collection_read(ssm_rester):
title = "foo"

created_collection = ssm_rester.collection.create(title)
read_collection = ssm_rester.collection.get_by_title(created_collection.title)
read_collection = ssm_rester.collection.get_by_title(
created_collection.title
)

assert created_collection == read_collection

Expand All @@ -34,7 +36,9 @@ def test_collection_delete(ssm_rester):
title = "foo"

created_collection = ssm_rester.collection.create(title)
read_collection = ssm_rester.collection.get_by_title(created_collection.title)
read_collection = ssm_rester.collection.get_by_title(
created_collection.title
)

assert created_collection == read_collection

Expand Down Expand Up @@ -72,7 +76,9 @@ def test_metazeunerite_dataset_ssm_json_create(
collection = ssm_rester.collection.create("foo-collection-ssm-json")
ssm_rester.initialize_dataset_for_collection(collection)
dataset = ssm_rester.dataset.create(metazeunerite_jsonld)
dataset_ssm_json = ssm_rester.dataset.get_by_uuid(dataset.uuid, format="json")
dataset_ssm_json = ssm_rester.dataset.get_by_uuid(
dataset.uuid, format="json"
)
print(dataset.dataset.keys())
assert dataset.dataset.get("@graph")[0].get(
"title"
Expand All @@ -82,14 +88,18 @@ def test_metazeunerite_dataset_ssm_json_create(
) == metazeunerite_ssm_json.get("description")


def test_metazeunerite_dataset_ssm_json_update(ssm_rester, metazeunerite_jsonld):
def test_metazeunerite_dataset_ssm_json_update(
ssm_rester, metazeunerite_jsonld
):
# Create collection and upload metazeunerite scidata JSON-LD
collection = ssm_rester.collection.create("foo-collection-ssm-json")
ssm_rester.initialize_dataset_for_collection(collection)
dataset = ssm_rester.dataset.create(metazeunerite_jsonld)

# Pull down the metazeuneriate data from catalog in SSM JSON format
dataset_ssm_json = ssm_rester.dataset.get_by_uuid(dataset.uuid, format="json")
dataset_ssm_json = ssm_rester.dataset.get_by_uuid(
dataset.uuid, format="json"
)

# Modify the 51st data entry for y-axis
dataseries = dataset_ssm_json.dataset.get("scidata").get("dataseries")
Expand All @@ -107,7 +117,8 @@ def test_metazeunerite_dataset_ssm_json_update(ssm_rester, metazeunerite_jsonld)
with open(ssm_json_filename, "w") as f:
json.dump(dataset_ssm_json.dataset, f)

# Upload the modified metazeunerite SSM JSON file to converter for SciData JSON-LD format output
# Upload the modified metazeunerite SSM JSON file to converter
# for SciData JSON-LD format output
with open(ssm_json_filename, "r") as f:
file_args = {"upload_file": (ssm_json_filename, f)}
response = requests.post(
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/containers/test_collection_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_construction_default():
def test_construction_just_title():
"""Test creating default collection"""
kwargs = {
"title": "5D0DC5589FA2C1F5DE2AB19B47F3923E65B261FABD8ED0F9A9B57CBBE3799988"
} # noqa: E501
"title": "5D0DC5589FA2C1F5DE2AB19B47F3923E65B261FABD8ED0F9A9B57CBBE3799988" # noqa: E501
}
collection = CollectionContainer(**kwargs)
assert collection.title == kwargs["title"]
assert collection.uri is None
Expand All @@ -27,8 +27,8 @@ def test_construction_just_title():
def test_construction_just_uri():
"""Test creating default collection"""
kwargs = {
"uri": "http://fuseki:3030/5D0DC5589FA2C1F5DE2AB19B47F3923E65B261FABD8ED0F9A9B57CBBE3799988"
} # noqa: E501
"uri": "http://fuseki:3030/5D0DC5589FA2C1F5DE2AB19B47F3923E65B261FABD8ED0F9A9B57CBBE3799988" # noqa: E501
}
collection = CollectionContainer(**kwargs)
assert collection.title is None
assert collection.uri == kwargs["uri"]
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/containers/test_dataset_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def test_construction_default():
def test_construction_just_uuid():
"""Test creating default dataset"""
kwargs = {
"uuid": "5D0DC5589FA2C1F5DE2AB19B47F3923E65B261FABD8ED0F9A9B57CBBE3799988"
} # noqa: E501
"uuid": "5D0DC5589FA2C1F5DE2AB19B47F3923E65B261FABD8ED0F9A9B57CBBE3799988" # noqa: E501
}
dataset = DatasetContainer(**kwargs)
assert dataset.uuid == kwargs["uuid"]
assert dataset.dataset == dict()
Expand All @@ -49,13 +49,18 @@ def test_dataset_str(dataset):
"""Testing string output of DatasetContainer"""
dataset_container = DatasetContainer()
target = "DatasetContainer(\nuuid={uuid},\ndataset={dataset}\n)"
assert target.format(uuid=None, dataset=dict()) == dataset_container.__str__()
assert (
target.format(uuid=None, dataset=dict()) == dataset_container.__str__()
)

uuid = "foo"
dataset_container = DatasetContainer(uuid=uuid, dataset=dataset)
pretty_dataset = json.dumps(dataset_container.dataset, sort_keys=True, indent=4)
pretty_dataset = json.dumps(
dataset_container.dataset, sort_keys=True, indent=4
)
assert (
target.format(uuid=uuid, dataset=pretty_dataset) == dataset_container.__str__()
target.format(uuid=uuid, dataset=pretty_dataset)
== dataset_container.__str__()
)


Expand Down
17 changes: 13 additions & 4 deletions tests/unit/io/test_jcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def _remove_elements_from_list(
# Tests


@pytest.mark.skip("Broken test due to SciDataLib not handling jcamp 'children'")
@pytest.mark.skip(
"Broken test due to SciDataLib not handling jcamp 'children'"
)
def test_read_hnmr(hnmr_ethanol_jcamp):
scidata_dict = jcamp.read_jcamp(hnmr_ethanol_jcamp.resolve())
assert scidata_dict == 0
Expand Down Expand Up @@ -87,7 +89,9 @@ def test_read_infrared(infrared_ethanol_jcamp):


def test_read_infrared_compressed(infrared_ethanol_compressed_jcamp):
scidata_dict = jcamp.read_jcamp(infrared_ethanol_compressed_jcamp.resolve())
scidata_dict = jcamp.read_jcamp(
infrared_ethanol_compressed_jcamp.resolve()
)

graph = scidata_dict.get("@graph")
assert graph["title"] == "$$ Begin of the data block"
Expand Down Expand Up @@ -115,7 +119,9 @@ def test_read_infrared_compressed(infrared_ethanol_compressed_jcamp):
assert len(parameter_0.get("dataarray")) == 1970


@pytest.mark.skip("Broken test due to SciDataLib not handling jcamp 'children'")
@pytest.mark.skip(
"Broken test due to SciDataLib not handling jcamp 'children'"
)
def test_read_infrared_compound(infrared_compound_jcamp):
scidata_dict = jcamp.read_jcamp(infrared_compound_jcamp.resolve())
assert scidata_dict == 0
Expand Down Expand Up @@ -221,7 +227,10 @@ def test_read_uvvis(uvvis_toluene_jcamp):

graph = scidata_dict.get("@graph")
assert graph["title"] == "Toluene"
assert graph["publisher"] == "INSTITUTE OF ENERGY PROBLEMS OF CHEMICAL PHYSICS, RAS"
assert (
graph["publisher"]
== "INSTITUTE OF ENERGY PROBLEMS OF CHEMICAL PHYSICS, RAS"
)
description = graph.get("description")
assert "JCAMP-DX" in description

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/io/test_scidata_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ def test_read(scidata_nmr_jsonld, outfile):
assert "version" in output
assert "generatedAt" in output
assert output.get("version") == 2
assert output.get("@id") == "https://stuchalk.github.io/scidata/examples/nmr/" # noqa: E501
assert (
output.get("@id") == "https://stuchalk.github.io/scidata/examples/nmr/"
) # noqa: E501
4 changes: 3 additions & 1 deletion tests/unit/services/test_dataset_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def test_construction(collection):
assert dataset.hostname == "http://localhost"
assert dataset.collection_title == collection.title

dataset = DatasetService(collection=collection, collection_title=collection.title)
dataset = DatasetService(
collection=collection, collection_title=collection.title
)
assert dataset.hostname == "http://localhost"
assert dataset.collection_title == collection.title

Expand Down

0 comments on commit 75ed1a9

Please sign in to comment.