Skip to content

Commit

Permalink
257 replace mocks (#291)
Browse files Browse the repository at this point in the history
* Removed lots of mocks from tests where not needed.

* Replaced lots of call to os module with pathlib (#271)


Co-authored-by: Marc White <[email protected]>

---------

Co-authored-by: Marc White <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 2f5ba48 commit 44ad1bf
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 414 deletions.
8 changes: 5 additions & 3 deletions src/access_nri_intake/catalog/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Manager for adding/updating intake sources in an intake-dataframe-catalog like the ACCESS-NRI catalog"""

import os
from pathlib import Path

import intake
from intake_dataframe_catalog.core import DfFileCatalog, DfFileCatalogError
Expand Down Expand Up @@ -32,7 +33,7 @@ class CatalogManager:
Add/update intake sources in an intake-dataframe-catalog like the ACCESS-NRI catalog
"""

def __init__(self, path: str):
def __init__(self, path: Path | str):
"""
Initialise a CatalogManager instance to add/update intake sources in a
intake-dataframe-catalog like the ACCESS-NRI catalog
Expand All @@ -42,10 +43,11 @@ def __init__(self, path: str):
path: str
The path to the intake-dataframe-catalog
"""
path = Path(path)

self.path = path
self.path = str(path)

self.mode = "a" if os.path.exists(path) else "w"
self.mode = "a" if path.exists() else "w"

try:
self.dfcat = DfFileCatalog(
Expand Down
19 changes: 15 additions & 4 deletions src/access_nri_intake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,20 @@ def metadata_validate(argv: Sequence[str] | None = None):
raise FileNotFoundError(f"No such file(s): {f}")


def metadata_template(loc=None):
def metadata_template(loc: str | Path | None = None) -> None:
"""
Create an empty template for a metadata.yaml file using the experiment schema
Create an empty template for a metadata.yaml file using the experiment schema.
Writes the template to the current working directory by default.
Parameters:
-----
loc (str, Path, optional): The directory in which to save the template.
Defaults to the current working directory.
Returns:
-----
None
"""

if loc is None:
Expand All @@ -424,9 +435,9 @@ def metadata_template(loc=None):
description = f"<{descr['description']}>"

if _can_be_array(descr):
description = [description]
description = [description] # type: ignore

template[name] = description

with open(os.path.join(loc, "metadata.yaml"), "w") as outfile:
with open((Path(loc) / "metadata.yaml"), "w") as outfile:
yaml.dump(template, outfile, default_flow_style=False, sort_keys=False)
Loading

0 comments on commit 44ad1bf

Please sign in to comment.