diff --git a/pyproject.toml b/pyproject.toml index 141ec33..369fe88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,8 +37,8 @@ dependencies = [ "ckanapi>=4.8", "defopt>=7.0.0", "email_validator", - "hdx-python-country>=4.0.0", - "hdx-python-utilities>=4.0.0", + "hdx-python-country>=4.0.1", + "hdx-python-utilities>=4.0.2", "libhxl>=5.2.2", "makefun", "quantulum3", diff --git a/requirements.txt b/requirements.txt index a36af05..48785d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,9 +34,9 @@ et-xmlfile==2.0.0 # via openpyxl frictionless==5.18.1 # via hdx-python-utilities -hdx-python-country==4.0.0 +hdx-python-country==4.0.1 # via hdx-python-api (pyproject.toml) -hdx-python-utilities==4.0.0 +hdx-python-utilities==4.0.2 # via # hdx-python-api (pyproject.toml) # hdx-python-country diff --git a/src/hdx/api/configuration.py b/src/hdx/api/configuration.py index 324d4f0..f96dd2a 100755 --- a/src/hdx/api/configuration.py +++ b/src/hdx/api/configuration.py @@ -4,7 +4,8 @@ import os from base64 import b64decode from collections import UserDict -from os.path import expanduser, isfile, join +from os.path import expanduser +from pathlib import Path from typing import Any, Optional import ckanapi @@ -38,14 +39,14 @@ class Configuration(UserDict): hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR - hdx_config_json (str): Path to JSON HDX configuration OR - hdx_config_yaml (str): Path to YAML HDX configuration + hdx_config_json (Path | str): Path to JSON HDX configuration OR + hdx_config_yaml (Path | str): Path to YAML HDX configuration project_config_dict (dict): Project configuration dictionary OR - project_config_json (str): Path to JSON Project configuration OR - project_config_yaml (str): Path to YAML Project configuration + project_config_json (Path | str): Path to JSON Project configuration OR + project_config_yaml (Path | str): Path to YAML Project configuration hdx_base_config_dict (dict): HDX base configuration dictionary OR - hdx_base_config_json (str): Path to JSON HDX base configuration OR - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. """ _configuration = None @@ -53,7 +54,7 @@ class Configuration(UserDict): default_hdx_base_config_yaml = script_dir_plus_file( "hdx_base_configuration.yaml", ConfigurationError ) - default_hdx_config_yaml = join(home_folder, ".hdx_configuration.yaml") + default_hdx_config_yaml = Path(home_folder, ".hdx_configuration.yaml") prefix = f"HDXPythonLibrary/{__version__}" @@ -111,10 +112,10 @@ def __init__(self, **kwargs: Any) -> None: raise ConfigurationError("More than one HDX configuration given!") else: if not hdx_config_yaml: - hdx_config_yaml = Configuration.default_hdx_config_yaml - if not isfile(hdx_config_yaml): - hdx_config_yaml = hdx_config_yaml.replace(".yaml", ".yml") - if isfile(hdx_config_yaml): + hdx_config_yaml = Path(Configuration.default_hdx_config_yaml) + if not hdx_config_yaml.is_file(): + hdx_config_yaml = hdx_config_yaml.with_suffix(".yml") + if hdx_config_yaml.is_file(): logger.info( f"No HDX configuration parameter. Using default configuration file: {hdx_config_yaml}." ) @@ -364,7 +365,7 @@ def create_session_user_agent( cls, session: requests.Session = None, user_agent: str | None = None, - user_agent_config_yaml: str | None = None, + user_agent_config_yaml: Path | str | None = None, user_agent_lookup: str | None = None, use_env: bool = False, **kwargs: Any, @@ -509,14 +510,14 @@ def setup( hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR - hdx_config_json (str): Path to JSON HDX configuration OR - hdx_config_yaml (str): Path to YAML HDX configuration + hdx_config_json (Path | str): Path to JSON HDX configuration OR + hdx_config_yaml (Path | str): Path to YAML HDX configuration project_config_dict (dict): Project configuration dictionary OR - project_config_json (str): Path to JSON Project configuration OR - project_config_yaml (str): Path to YAML Project configuration + project_config_json (Path | str): Path to JSON Project configuration OR + project_config_yaml (Path | str): Path to YAML Project configuration hdx_base_config_dict (dict): HDX base configuration dictionary OR - hdx_base_config_json (str): Path to JSON HDX base configuration OR - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. Returns: None @@ -549,14 +550,14 @@ def _create( hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR - hdx_config_json (str): Path to JSON HDX configuration OR - hdx_config_yaml (str): Path to YAML HDX configuration + hdx_config_json (Path | str): Path to JSON HDX configuration OR + hdx_config_yaml (Path | str): Path to YAML HDX configuration project_config_dict (dict): Project configuration dictionary OR - project_config_json (str): Path to JSON Project configuration OR - project_config_yaml (str): Path to YAML Project configuration + project_config_json (Path | str): Path to JSON Project configuration OR + project_config_yaml (Path | str): Path to YAML Project configuration hdx_base_config_dict (dict): HDX base configuration dictionary OR - hdx_base_config_json (str): Path to JSON HDX base configuration OR - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. Returns: HDX site url @@ -588,14 +589,14 @@ def create( hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR - hdx_config_json (str): Path to JSON HDX configuration OR - hdx_config_yaml (str): Path to YAML HDX configuration + hdx_config_json (Path | str): Path to JSON HDX configuration OR + hdx_config_yaml (Path | str): Path to YAML HDX configuration project_config_dict (dict): Project configuration dictionary OR - project_config_json (str): Path to JSON Project configuration OR - project_config_yaml (str): Path to YAML Project configuration + project_config_json (Path | str): Path to JSON Project configuration OR + project_config_yaml (Path | str): Path to YAML Project configuration hdx_base_config_dict (dict): HDX base configuration dictionary OR - hdx_base_config_json (str): Path to JSON HDX base configuration OR - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. Returns: HDX site url diff --git a/src/hdx/api/utilities/hdx_state.py b/src/hdx/api/utilities/hdx_state.py index 68d8d7c..aa20cb5 100644 --- a/src/hdx/api/utilities/hdx_state.py +++ b/src/hdx/api/utilities/hdx_state.py @@ -2,7 +2,7 @@ import logging from collections.abc import Callable -from os.path import join +from pathlib import Path from typing import Any from hdx.utilities.loader import load_text @@ -32,7 +32,7 @@ class HDXState(State): def __init__( self, dataset_name_or_id: str, - path: str, + path: Path | str, read_fn: Callable[[str], Any] = lambda x: x, write_fn: Callable[[Any], str] = lambda x: x, configuration: Configuration | None = None, @@ -65,7 +65,7 @@ def write(self) -> None: """ logger.info(f"State written to {self._dataset_name_or_id} = {self.state}") filename = self._resource["name"] - file_to_upload = join(self.path, filename) + file_to_upload = self.path / filename save_text(self.write_fn(self.state), file_to_upload) self._resource.set_file_to_upload(file_to_upload) self._resource.update_in_hdx() diff --git a/src/hdx/data/dataset.py b/src/hdx/data/dataset.py index 103180a..f1ed03b 100755 --- a/src/hdx/data/dataset.py +++ b/src/hdx/data/dataset.py @@ -7,7 +7,8 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from copy import deepcopy from datetime import datetime -from os.path import isfile, join +from os.path import isfile +from pathlib import Path from typing import ( TYPE_CHECKING, Any, @@ -198,7 +199,7 @@ def get_dataset_dict(self) -> dict: package["resources"] = self._convert_hdxobjects(self._resources) return package - def save_to_json(self, path: str, follow_urls: bool = False): + def save_to_json(self, path: Path | str, follow_urls: bool = False): """Save dataset to JSON. If follow_urls is True, resource urls that point to datasets, HXL proxy urls etc. are followed to retrieve final urls. @@ -219,7 +220,7 @@ def save_to_json(self, path: str, follow_urls: bool = False): save_json(dataset_dict, path) @staticmethod - def load_from_json(path: str) -> Optional["Dataset"]: + def load_from_json(path: Path | str) -> Optional["Dataset"]: """Load dataset from JSON Args: @@ -457,7 +458,7 @@ def move_resource( return resource def update_from_yaml( - self, path: str = join("config", "hdx_dataset_static.yaml") + self, path: Path | str = Path("config", "hdx_dataset_static.yaml") ) -> None: """Update dataset metadata with static metadata from YAML file @@ -471,7 +472,7 @@ def update_from_yaml( self.separate_resources() def update_from_json( - self, path: str = join("config", "hdx_dataset_static.json") + self, path: Path | str = Path("config", "hdx_dataset_static.json") ) -> None: """Update dataset metadata with static metadata from JSON file @@ -2330,7 +2331,7 @@ def _create_preview_resourceview(self) -> None: def _generate_resource_view( self, resource: Union["Resource", dict, str, int] = 0, - path: str | None = None, + path: Path | str | None = None, bites_disabled: Sequence[bool] | None = None, indicators: Sequence[dict] | None = None, findreplace: dict | None = None, @@ -2374,9 +2375,9 @@ def _generate_resource_view( resourceview = resource_view.ResourceView(resourceview_data) if path is None: if indicators is None: - path = join("config", "hdx_resource_view_static.yaml") + path = Path("config", "hdx_resource_view_static.yaml") if not isfile(path): - path = path.replace(".yaml", ".yml") + path = path.with_suffix(".yml") else: path = script_dir_plus_file( "indicator_resource_view_template.yaml", @@ -2488,7 +2489,7 @@ def replace_indicator(qc_config, index): def generate_quickcharts( self, resource: Union["Resource", dict, str, int] = 0, - path: str | None = None, + path: Path | str | None = None, bites_disabled: Sequence[bool] | None = None, indicators: Sequence[dict] | None = None, findreplace: dict | None = None, @@ -2607,7 +2608,7 @@ def remove_dates_from_title( def generate_resource( self, - folder: str, + folder: Path | str, filename: str, rows: Iterable[Sequence | Mapping], resourcedata: dict, @@ -2703,7 +2704,7 @@ def process_row(row: Sequence | Mapping) -> Sequence | Mapping | None: dates[1] = enddate return row - filepath = join(folder, filename) + filepath = Path(folder) / filename rows = save_iterable( filepath, rows, @@ -2739,7 +2740,7 @@ def process_row(row: Sequence | Mapping) -> Sequence | Mapping | None: def generate_resource_from_rows( self, - folder: str, + folder: Path | str, filename: str, rows: Iterable[Sequence | Mapping], resourcedata: dict, @@ -2776,7 +2777,7 @@ def generate_resource_from_iterable( headers: Sequence[str], iterable: Iterable[Sequence | dict], hxltags: dict[str, str], - folder: str, + folder: Path | str, filename: str, resourcedata: dict, datecol: int | str | None = None, @@ -2988,7 +2989,7 @@ def generate_resource_from_iterator( headers: Sequence[str], iterator: Iterator[Sequence | dict], hxltags: dict[str, str], - folder: str, + folder: Path | str, filename: str, resourcedata: dict, datecol: int | str | None = None, @@ -3019,7 +3020,7 @@ def download_generate_resource( self, downloader: BaseDownload, url: str, - folder: str, + folder: Path | str, filename: str, resourcedata: dict, header_insertions: Sequence[tuple[int, str]] | None = None, @@ -3122,7 +3123,7 @@ def download_and_generate_resource( downloader: BaseDownload, url: str, hxltags: dict[str, str], - folder: str, + folder: Path | str, filename: str, resourcedata: dict, header_insertions: Sequence[tuple[int, str]] | None = None, diff --git a/src/hdx/data/hdxobject.py b/src/hdx/data/hdxobject.py index 8128207..0925dba 100755 --- a/src/hdx/data/hdxobject.py +++ b/src/hdx/data/hdxobject.py @@ -8,6 +8,7 @@ from collections import UserDict from collections.abc import Sequence from os.path import isfile +from pathlib import Path from typing import Any, Optional, Union from ckanapi.errors import NotFound @@ -62,7 +63,7 @@ def get_old_data_dict(self) -> dict: """ return self._old_data - def update_from_yaml(self, path: str) -> None: + def update_from_yaml(self, path: Path | str) -> None: """Update metadata with static metadata from YAML file Args: @@ -72,10 +73,10 @@ def update_from_yaml(self, path: str) -> None: None """ if not isfile(path): - path = path.replace(".yaml", ".yml") - self.data = load_yaml_into_existing_dict(self.data, path) + path = Path(path).with_suffix(".yml") + load_yaml_into_existing_dict(self.data, path) - def update_from_json(self, path: str) -> None: + def update_from_json(self, path: Path | str) -> None: """Update metadata with static metadata from JSON file Args: @@ -84,7 +85,7 @@ def update_from_json(self, path: str) -> None: Returns: None """ - self.data = load_json_into_existing_dict(self.data, path) + load_json_into_existing_dict(self.data, path) def _read_from_hdx( self, diff --git a/src/hdx/data/organization.py b/src/hdx/data/organization.py index 3609d6e..3cd4790 100755 --- a/src/hdx/data/organization.py +++ b/src/hdx/data/organization.py @@ -2,7 +2,7 @@ import logging from collections.abc import Sequence -from os.path import join +from pathlib import Path from typing import TYPE_CHECKING, Any, Optional, Union import hdx.data.dataset @@ -50,7 +50,7 @@ def actions() -> dict[str, str]: } def update_from_yaml( - self, path: str = join("config", "hdx_organization_static.yaml") + self, path: Path | str = Path("config", "hdx_organization_static.yaml") ) -> None: """Update organization metadata with static metadata from YAML file @@ -63,7 +63,7 @@ def update_from_yaml( super().update_from_yaml(path) def update_from_json( - self, path: str = join("config", "hdx_organization_static.json") + self, path: Path | str = Path("config", "hdx_organization_static.json") ) -> None: """Update organization metadata with static metadata from JSON file diff --git a/src/hdx/data/resource.py b/src/hdx/data/resource.py index a579092..6229143 100755 --- a/src/hdx/data/resource.py +++ b/src/hdx/data/resource.py @@ -4,7 +4,6 @@ import warnings from collections.abc import Sequence from datetime import datetime -from os.path import join from pathlib import Path from typing import Any, Optional @@ -67,7 +66,7 @@ def actions() -> dict[str, str]: } def update_from_yaml( - self, path: str = join("config", "hdx_resource_static.yaml") + self, path: Path | str = Path("config", "hdx_resource_static.yaml") ) -> None: """Update resource metadata with static metadata from YAML file @@ -80,7 +79,7 @@ def update_from_yaml( super().update_from_yaml(path) def update_from_json( - self, path: str = join("config", "hdx_resource_static.json") + self, path: Path | str = Path("config", "hdx_resource_static.json") ) -> None: """Update resource metadata with static metadata from JSON file @@ -300,7 +299,7 @@ def get_file_to_upload(self) -> str | None: return self._file_to_upload def set_file_to_upload( - self, file_to_upload: str, guess_format_from_suffix: bool = False + self, file_to_upload: Path | str, guess_format_from_suffix: bool = False ) -> str: """Delete any existing url and set the file uploaded to the local path provided @@ -647,8 +646,8 @@ def search_in_hdx( return resources def download( - self, folder: str | None = None, retriever: Retrieve | None = None - ) -> tuple[str, str]: + self, folder: Path | str | None = None, retriever: Retrieve | None = None + ) -> tuple[str, Path]: """Download resource store to provided folder or temporary folder if no folder supplied diff --git a/src/hdx/data/resource_view.py b/src/hdx/data/resource_view.py index 414812c..e9b62ba 100755 --- a/src/hdx/data/resource_view.py +++ b/src/hdx/data/resource_view.py @@ -2,7 +2,7 @@ import logging from collections.abc import Sequence -from os.path import join +from pathlib import Path from typing import Any, Optional, Union from hdx.utilities.uuid import is_valid_uuid @@ -47,7 +47,7 @@ def actions() -> dict[str, str]: } def update_from_yaml( - self, path: str = join("config", "hdx_resource_view_static.yaml") + self, path: Path | str = Path("config", "hdx_resource_view_static.yaml") ) -> None: """Update resource view metadata with static metadata from YAML file @@ -60,7 +60,7 @@ def update_from_yaml( super().update_from_yaml(path) def update_from_json( - self, path: str = join("config", "hdx_resource_view_static.json") + self, path: Path | str = Path("config", "hdx_resource_view_static.json") ) -> None: """Update resource view metadata with static metadata from JSON file diff --git a/src/hdx/data/showcase.py b/src/hdx/data/showcase.py index fc0c6c4..e0f7c93 100755 --- a/src/hdx/data/showcase.py +++ b/src/hdx/data/showcase.py @@ -3,7 +3,7 @@ import logging import sys from collections.abc import Sequence -from os.path import join +from pathlib import Path from typing import Any, Optional, Union from hdx.utilities.dictandlist import merge_two_dictionaries @@ -57,7 +57,7 @@ def actions() -> dict[str, str]: } def update_from_yaml( - self, path: str = join("config", "hdx_showcase_static.yaml") + self, path: Path | str = Path("config", "hdx_showcase_static.yaml") ) -> None: """Update showcase metadata with static metadata from YAML file @@ -70,7 +70,7 @@ def update_from_yaml( super().update_from_yaml(path) def update_from_json( - self, path: str = join("config", "hdx_showcase_static.json") + self, path: Path | str = Path("config", "hdx_showcase_static.json") ) -> None: """Update showcase metadata with static metadata from JSON file diff --git a/src/hdx/data/user.py b/src/hdx/data/user.py index 9596c98..3d5c3e7 100755 --- a/src/hdx/data/user.py +++ b/src/hdx/data/user.py @@ -2,7 +2,7 @@ import logging from collections.abc import Sequence -from os.path import join +from pathlib import Path from typing import Any, Optional import hdx.data.organization @@ -48,7 +48,7 @@ def actions() -> dict[str, str]: } def update_from_yaml( - self, path: str = join("config", "hdx_user_static.yaml") + self, path: Path | str = Path("config", "hdx_user_static.yaml") ) -> None: """Update user metadata with static metadata from YAML file @@ -61,7 +61,7 @@ def update_from_yaml( super().update_from_yaml(path) def update_from_json( - self, path: str = join("config", "hdx_user_static.json") + self, path: Path | str = Path("config", "hdx_user_static.json") ) -> None: """Update user metadata with static metadata from JSON file diff --git a/src/hdx/data/vocabulary.py b/src/hdx/data/vocabulary.py index c1f6cd8..d42bedf 100755 --- a/src/hdx/data/vocabulary.py +++ b/src/hdx/data/vocabulary.py @@ -3,7 +3,7 @@ import logging from collections import OrderedDict from collections.abc import Sequence -from os.path import join +from pathlib import Path from typing import Any, Optional from hdx.utilities.downloader import Download @@ -63,7 +63,7 @@ def actions() -> dict[str, str]: } def update_from_yaml( - self, path: str = join("config", "hdx_vocabulary_static.yaml") + self, path: Path | str = Path("config", "hdx_vocabulary_static.yaml") ) -> None: """Update vocabulary metadata with static metadata from YAML file @@ -76,7 +76,7 @@ def update_from_yaml( super().update_from_yaml(path) def update_from_json( - self, path: str = join("config", "hdx_vocabulary_static.json") + self, path: Path | str = Path("config", "hdx_vocabulary_static.json") ) -> None: """Update vocabulary metadata with static metadata from JSON file diff --git a/src/hdx/facades/infer_arguments.py b/src/hdx/facades/infer_arguments.py index 5b808b2..5bdc47a 100755 --- a/src/hdx/facades/infer_arguments.py +++ b/src/hdx/facades/infer_arguments.py @@ -2,8 +2,9 @@ import logging import sys -from collections.abc import Callable # noqa: F401 +from collections.abc import Callable from inspect import getdoc +from pathlib import Path from typing import Any import defopt @@ -66,15 +67,16 @@ def facade(projectmainfn: Callable[[Any], None], **kwargs: Any): if count < no_main_parameters: count += 1 else: - if param_type == "str": - param_type = "str | None" - default = None - elif param_type == "bool": - default = False - else: - raise ValueError( - "Configuration.create has new parameter with unknown type!" - ) + match param_type: + case "str" | "Path" | "Path | str": + param_type = "str | None" + default = None + case "bool": + default = False + case _: + raise ValueError( + f"Configuration.create has new parameter {param_name} with unknown type {param_type}!" + ) param_names.append(f"{param_name}: {param_type} = {default}") main_doc.append(f"\n {param_name}: {param_info.doc}") main_doc = "".join(main_doc) @@ -87,7 +89,10 @@ def facade(projectmainfn: Callable[[Any], None], **kwargs: Any): name = f"--{key.replace('_', '-')}" if name not in argv: argv.append(name) - argv.append(kwargs[key]) + value = kwargs[key] + if isinstance(value, Path): + value = str(value) + argv.append(value) @with_signature(main_sig) def gen_func(*args, **kwargs): diff --git a/tests/hdx/api/test_ckan.py b/tests/hdx/api/test_ckan.py index 92a449d..6a0e79e 100644 --- a/tests/hdx/api/test_ckan.py +++ b/tests/hdx/api/test_ckan.py @@ -5,10 +5,10 @@ import json import logging -import os import random from os import getenv -from os.path import join +from os.path import expanduser +from pathlib import Path from time import sleep import gspread @@ -43,8 +43,8 @@ def configuration(self): Vocabulary._tags_dict = None @pytest.fixture(scope="function") - def datasetmetadata(self): - return join("tests", "fixtures", "CKAN", "hdx_dataset_static.yaml") + def datasetmetadata(self, fixturesfolder): + return fixturesfolder / "CKAN" / "hdx_dataset_static.yaml" @pytest.fixture(scope="class") def params(self): @@ -59,9 +59,9 @@ def params(self): def gclient(self): gsheet_auth = getenv("GSHEET_AUTH") if not gsheet_auth: - auth_file_path = os.path.join(os.path.expanduser("~"), ".gsheet_auth.json") - if os.path.exists(auth_file_path): - with open(auth_file_path, encoding="utf-8") as auth_file: + auth_file_path = Path(expanduser("~"), ".gsheet_auth.json") + if auth_file_path.exists(): + with auth_file_path.open(encoding="utf-8") as auth_file: gsheet_auth = auth_file.read() else: raise ValueError("No gsheet authorisation supplied!") diff --git a/tests/hdx/api/test_configuration.py b/tests/hdx/api/test_configuration.py index 7a7d692..ddde871 100755 --- a/tests/hdx/api/test_configuration.py +++ b/tests/hdx/api/test_configuration.py @@ -1,7 +1,5 @@ """Configuration Tests""" -from os.path import join - import pytest from hdx.utilities.loader import LoadError from hdx.utilities.useragent import UserAgentError @@ -14,39 +12,39 @@ class TestConfiguration: @pytest.fixture(scope="class") def hdx_base_config_yaml(self, configfolder): - return join(configfolder, "hdx_base_config.yaml") + return configfolder / "hdx_base_config.yaml" @pytest.fixture(scope="class") def hdx_base_config_json(self, configfolder): - return join(configfolder, "hdx_base_config.json") + return configfolder / "hdx_base_config.json" @pytest.fixture(scope="class") def hdx_missing_site_config_json(self, configfolder): - return join(configfolder, "hdx_missing_site_config.json") + return configfolder / "hdx_missing_site_config.json" @pytest.fixture(scope="class") def project_config_json(self, configfolder): - return join(configfolder, "project_configuration.json") + return configfolder / "project_configuration.json" @pytest.fixture(scope="class") def user_agent_config_yaml(self, configfolder): - return join(configfolder, "user_agent_config.yaml") + return configfolder / "user_agent_config.yaml" @pytest.fixture(scope="class") def user_agent_config2_yaml(self, configfolder): - return join(configfolder, "user_agent_config2.yaml") + return configfolder / "user_agent_config2.yaml" @pytest.fixture(scope="class") def user_agent_config3_yaml(self, configfolder): - return join(configfolder, "user_agent_config3.yaml") + return configfolder / "user_agent_config3.yaml" @pytest.fixture(scope="class") def empty_yaml(self, configfolder): - return join(configfolder, "empty.yaml") + return configfolder / "empty.yaml" @pytest.fixture(scope="class") def user_agent_config_wrong_yaml(self, configfolder): - return join(configfolder, "user_agent_config_wrong.yaml") + return configfolder / "user_agent_config_wrong.yaml" def test_init( self, diff --git a/tests/hdx/api/utilities/test_hdx_state.py b/tests/hdx/api/utilities/test_hdx_state.py index cb80876..41d9cd6 100644 --- a/tests/hdx/api/utilities/test_hdx_state.py +++ b/tests/hdx/api/utilities/test_hdx_state.py @@ -4,7 +4,8 @@ from copy import deepcopy from datetime import datetime, timezone from os import makedirs -from os.path import exists, join +from os.path import exists +from pathlib import Path from shutil import copyfile, rmtree from tempfile import gettempdir @@ -21,11 +22,11 @@ class TestState: @pytest.fixture(scope="class") def tempfolder(self): - return join(gettempdir(), "test_state") + return Path(gettempdir(), "test_state") @pytest.fixture(scope="class") def statefolder(self, fixturesfolder): - return join(fixturesfolder, "state") + return fixturesfolder / "state" @pytest.fixture(scope="class") def statefile(self): @@ -58,7 +59,7 @@ def post(url, data, headers, files, allow_redirects, auth=None): myresultdict = deepcopy(dataset_resultdict) resource = myresultdict["resources"][0] resource["name"] = statefile - resource["url"] = join(tempfolder, statefile) + resource["url"] = str(tempfolder / statefile) result = json.dumps(myresultdict) return MockResponse( 200, @@ -82,7 +83,7 @@ def post(url, data, headers, files, allow_redirects, auth=None): myresultdict = deepcopy(dataset_resultdict) resource = myresultdict["resources"][0] resource["name"] = multidatestatefile - resource["url"] = join(tempfolder, multidatestatefile) + resource["url"] = str(tempfolder / multidatestatefile) result = json.dumps(myresultdict) return MockResponse( 200, @@ -96,8 +97,8 @@ def test_state( ): if not exists(tempfolder): makedirs(tempfolder) - statepath = join(tempfolder, statefile) - copyfile(join(statefolder, statefile), statepath) + statepath = tempfolder / statefile + copyfile(statefolder / statefile, statepath) with HDXState( "test_dataset", tempfolder, parse_date, iso_string_from_datetime ) as state: @@ -125,8 +126,8 @@ def test_multi_date_state( ): if not exists(tempfolder): makedirs(tempfolder) - statepath = join(tempfolder, multidatestatefile) - copyfile(join(statefolder, multidatestatefile), statepath) + statepath = tempfolder / multidatestatefile + copyfile(statefolder / multidatestatefile, statepath) with HDXState( "test_dataset", tempfolder, diff --git a/tests/hdx/conftest.py b/tests/hdx/conftest.py index cd24acd..b5355ec 100755 --- a/tests/hdx/conftest.py +++ b/tests/hdx/conftest.py @@ -2,7 +2,7 @@ import re import smtplib -from os.path import join +from pathlib import Path import pytest @@ -12,40 +12,38 @@ @pytest.fixture(scope="session") def fixturesfolder(): - return join("tests", "fixtures") + return Path("tests") / "fixtures" @pytest.fixture(scope="session") def configfolder(fixturesfolder): - return join(fixturesfolder, "config") + return fixturesfolder / "config" @pytest.fixture(scope="session") def hdx_config_yaml(configfolder): - return join(configfolder, "hdx_config.yaml") + return configfolder / "hdx_config.yaml" @pytest.fixture(scope="session") def hdx_config_json(configfolder): - return join(configfolder, "hdx_config.json") + return configfolder / "hdx_config.json" @pytest.fixture(scope="session") -def project_config_yaml(): - return join("tests", "fixtures", "config", "project_configuration.yaml") +def project_config_yaml(configfolder): + return configfolder / "project_configuration.yaml" @pytest.fixture(scope="session") def test_data(fixturesfolder): - return join(fixturesfolder, "test_data.csv") + return fixturesfolder / "test_data.csv" @pytest.fixture(scope="session") def test_xlsx(fixturesfolder): - return join( - fixturesfolder, - "size_hash", - "ACLED-All-Africa-File_20170101-to-20170708.xlsx", + return ( + fixturesfolder / "size_hash" / "ACLED-All-Africa-File_20170101-to-20170708.xlsx" ) diff --git a/tests/hdx/data/test_dataset_core.py b/tests/hdx/data/test_dataset_core.py index ee9be5a..7385aaa 100755 --- a/tests/hdx/data/test_dataset_core.py +++ b/tests/hdx/data/test_dataset_core.py @@ -6,7 +6,7 @@ import re import shutil import tempfile -from os.path import join +from pathlib import Path import pytest from hdx.utilities.dictandlist import merge_two_dictionaries @@ -36,7 +36,7 @@ ) from .test_vocabulary import vocabulary_mockshow -searchdict = load_yaml(join("tests", "fixtures", "dataset_search_results.yaml")) +searchdict = load_yaml(Path("tests") / "fixtures" / "dataset_search_results.yaml") dataset_list = [ "acled-conflict-data-for-libya", "acled-conflict-data-for-liberia", @@ -185,12 +185,12 @@ def mockhxlupdate(url, datadict): class TestDatasetCore: @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_dataset_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_dataset_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_dataset_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_dataset_static.json" @pytest.fixture(scope="function") def read(self): @@ -746,7 +746,7 @@ def test_update_in_hdx(self, configuration, post_update, date_pattern, test_xlsx assert len(dataset._resources) == 3 dataset = Dataset.read_from_hdx("TEST4") with temp_dir("test_update_in_hdx") as tempdir: - path = join(tempdir, "test_update_in_hdx.xlsx") + path = tempdir / "test_update_in_hdx.xlsx" shutil.copyfile(test_xlsx, path) resource.set_file_to_upload(path) dataset.add_update_resource(resource) diff --git a/tests/hdx/data/test_dataset_noncore.py b/tests/hdx/data/test_dataset_noncore.py index 94824d7..a06c506 100755 --- a/tests/hdx/data/test_dataset_noncore.py +++ b/tests/hdx/data/test_dataset_noncore.py @@ -3,7 +3,6 @@ import copy import json from datetime import datetime, timezone -from os.path import join import pytest from hdx.location.country import Country @@ -44,8 +43,8 @@ class TestDatasetNoncore: association = None @pytest.fixture(scope="class") - def static_resource_view_yaml(self): - return join("tests", "fixtures", "config", "hdx_resource_view_static.yaml") + def static_resource_view_yaml(self, configfolder): + return configfolder / "hdx_resource_view_static.yaml" @pytest.fixture(scope="function") def vocabulary_read(self): @@ -988,7 +987,7 @@ def test_load_save_to_json(self, configuration, vocabulary_read): "url": "https://docs.google.com/spreadsheets/d/1NjSI2LaS3SqbgYc0HdD8oIb7lofGtiHgoKKATCpwVdY/edit#gid=1088874596", } dataset.add_update_resource(resourcedata) - path = join(temp_folder, "dataset.json") + path = temp_folder / "dataset.json" dataset.save_to_json(path, follow_urls=True) dataset = Dataset.load_from_json(path) assert dataset["name"] == name diff --git a/tests/hdx/data/test_dataset_resource_generation.py b/tests/hdx/data/test_dataset_resource_generation.py index f5c4d99..023bb98 100644 --- a/tests/hdx/data/test_dataset_resource_generation.py +++ b/tests/hdx/data/test_dataset_resource_generation.py @@ -1,7 +1,6 @@ """Dataset Tests (noncore methods)""" from datetime import datetime, timezone -from os.path import join import pytest from hdx.utilities.compare import assert_files_same @@ -38,7 +37,7 @@ class TestDatasetResourceGeneration: "ISO3": "#country+code", } - def test_download_generate_resource(self, configuration): + def test_download_generate_resource(self, configuration, fixturesfolder): with temp_dir("test") as folder: filename = "conflict_data_alg.csv" resourcedata = { @@ -233,8 +232,8 @@ def process_row(headers, row): }, ] assert_files_same( - join("tests", "fixtures", "gen_resource", filename), - join(folder, filename), + fixturesfolder / "gen_resource" / filename, + folder / filename, ) columns_to_include = [ @@ -524,7 +523,7 @@ def process_year(row): ) assert success is False - def test_download_and_generate_resource(self, configuration): + def test_download_and_generate_resource(self, configuration, fixturesfolder): with temp_dir("test") as folder: filename = "conflict_data_alg.csv" resourcedata = { @@ -838,13 +837,13 @@ def process_row(headers, row): }, ] assert_files_same( - join("tests", "fixtures", "download_gen_resource", filename), - join(folder, filename), + fixturesfolder / "download_gen_resource" / filename, + folder / filename, ) qc_filename = f"qc_{filename}" assert_files_same( - join("tests", "fixtures", "gen_resource", qc_filename), - join(folder, qc_filename), + fixturesfolder / "gen_resource" / qc_filename, + folder / qc_filename, ) success, results = dataset.download_and_generate_resource( @@ -1115,13 +1114,8 @@ def process_year(row): == "[2001-01-01T00:00:00 TO 2001-12-31T23:59:59]" ) assert_files_same( - join( - "tests", - "fixtures", - "gen_resource", - f"min_{qc_filename}", - ), - join(folder, qc_filename), + fixturesfolder / "gen_resource" / f"min_{qc_filename}", + folder / qc_filename, ) with pytest.raises(HDXError): diff --git a/tests/hdx/data/test_organization.py b/tests/hdx/data/test_organization.py index 800d79a..aeec81d 100755 --- a/tests/hdx/data/test_organization.py +++ b/tests/hdx/data/test_organization.py @@ -2,7 +2,7 @@ import copy import json -from os.path import join +from pathlib import Path import pytest from hdx.utilities.dictandlist import merge_two_dictionaries @@ -16,7 +16,7 @@ from .. import MockResponse, organization_data, user_data from .test_user import user_mockshow -resultdict = load_yaml(join("tests", "fixtures", "organization_show_results.yaml")) +resultdict = load_yaml(Path("tests") / "fixtures" / "organization_show_results.yaml") organization_list = [ "acaps", @@ -30,7 +30,7 @@ "afdb", "afghanistan-protection-cluster", ] -searchdict = load_yaml(join("tests", "fixtures", "dataset_search_results.yaml")) +searchdict = load_yaml(Path("tests") / "fixtures" / "dataset_search_results.yaml") organization_autocomplete = [ { @@ -99,12 +99,12 @@ def mockgetdatasets(url, datadict): class TestOrganization: @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_organization_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_organization_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_organization_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_organization_static.json" @pytest.fixture(scope="function") def read(self): diff --git a/tests/hdx/data/test_resource.py b/tests/hdx/data/test_resource.py index 8d998dc..bfb97a4 100755 --- a/tests/hdx/data/test_resource.py +++ b/tests/hdx/data/test_resource.py @@ -5,7 +5,7 @@ import os from datetime import datetime, timezone from os import remove -from os.path import basename, join +from os.path import basename import pytest from hdx.utilities.dateparse import parse_date @@ -341,20 +341,20 @@ class TestResource: datastore = None @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_resource_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_resource_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_resource_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_resource_static.json" @pytest.fixture(scope="class") - def topline_yaml(self): - return join("tests", "fixtures", "config", "hdx_datasource_topline.yaml") + def topline_yaml(self, configfolder): + return configfolder / "hdx_datasource_topline.yaml" @pytest.fixture(scope="class") - def topline_json(self): - return join("tests", "fixtures", "config", "hdx_datasource_topline.json") + def topline_json(self, configfolder): + return configfolder / "hdx_datasource_topline.json" @pytest.fixture(scope="function") def read(self): diff --git a/tests/hdx/data/test_resource_view.py b/tests/hdx/data/test_resource_view.py index e7426a0..14840e8 100755 --- a/tests/hdx/data/test_resource_view.py +++ b/tests/hdx/data/test_resource_view.py @@ -2,7 +2,6 @@ import copy import json -from os.path import join import pytest from hdx.utilities.dictandlist import merge_two_dictionaries @@ -130,12 +129,12 @@ class TestResourceView: } @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_resource_view_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_resource_view_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_resource_view_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_resource_view_static.json" @pytest.fixture(scope="function") def read(self): diff --git a/tests/hdx/data/test_showcase.py b/tests/hdx/data/test_showcase.py index a5e439c..e10000c 100755 --- a/tests/hdx/data/test_showcase.py +++ b/tests/hdx/data/test_showcase.py @@ -2,7 +2,7 @@ import copy import json -from os.path import join +from pathlib import Path import pytest from hdx.utilities.dictandlist import merge_two_dictionaries @@ -58,8 +58,10 @@ "name": "showcase-1", } -datasetsdict = load_yaml(join("tests", "fixtures", "dataset_search_results.yaml")) -allsearchdict = load_yaml(join("tests", "fixtures", "showcase_all_search_results.yaml")) +datasetsdict = load_yaml(Path("tests") / "fixtures" / "dataset_search_results.yaml") +allsearchdict = load_yaml( + Path("tests") / "fixtures" / "showcase_all_search_results.yaml" +) def mockshow(url, datadict): @@ -173,12 +175,12 @@ class TestShowcase: association = None @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_showcase_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_showcase_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_showcase_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_showcase_static.json" @pytest.fixture(scope="function") def read(self): diff --git a/tests/hdx/data/test_update_dataset_resources.py b/tests/hdx/data/test_update_dataset_resources.py index 1e3c3a7..4fa1939 100644 --- a/tests/hdx/data/test_update_dataset_resources.py +++ b/tests/hdx/data/test_update_dataset_resources.py @@ -1,4 +1,5 @@ from os.path import join +from pathlib import Path import pytest from hdx.location.country import Country @@ -51,20 +52,20 @@ def configuration(self): } @pytest.fixture(scope="class") - def fixture_path(self): - return join("tests", "fixtures", "update_dataset_resources") + def fixture_path(self, fixturesfolder): + return fixturesfolder / "update_dataset_resources" @pytest.fixture(scope="class") def new_dataset_json(self, fixture_path): - return join(fixture_path, "unesco_update_dataset.json") + return fixture_path / "unesco_update_dataset.json" @pytest.fixture(scope="class") def dataset_json(self, fixture_path): - return join(fixture_path, "unesco_dataset.json") + return fixture_path / "unesco_dataset.json" @pytest.fixture(scope="class") def expected_resources_to_update_json(self, fixture_path): - return join(fixture_path, "expected_resources_to_update.json") + return fixture_path / "expected_resources_to_update.json" @pytest.fixture(scope="function") def dataset(self, dataset_json): @@ -79,7 +80,7 @@ def new_dataset(self, fixture_path, new_dataset_json): for resourceobj in resourceobjs: resource = Resource(resourceobj) filename = self.file_mapping[resourceobj["name"]] - resource.set_file_to_upload(join(fixture_path, filename)) + resource.set_file_to_upload(fixture_path / filename) dataset.add_update_resource(resource) return dataset @@ -111,15 +112,15 @@ def test_dataset_update_resources( assert resources_to_update == expected_resources_to_update assert resources_to_delete == [8, 2, 1, 0] assert filestore_resources == { - 3: join(fixture_path, "sdg_data_zwe.csv"), - 4: join(fixture_path, "sdg_indicatorlist_zwe.csv"), - 5: join(fixture_path, "sdg_metadata_zwe.csv"), - 6: join(fixture_path, "dem_data_zwe.csv"), - 7: join(fixture_path, "dem_indicatorlist_zwe.csv"), - 9: join(fixture_path, "opri_data_zwe.csv"), - 10: join(fixture_path, "opri_indicatorlist_zwe.csv"), - 11: join(fixture_path, "opri_metadata_zwe.csv"), - 12: join(fixture_path, "qc_sdg_data_zwe.csv"), + 3: fixture_path / "sdg_data_zwe.csv", + 4: fixture_path / "sdg_indicatorlist_zwe.csv", + 5: fixture_path / "sdg_metadata_zwe.csv", + 6: fixture_path / "dem_data_zwe.csv", + 7: fixture_path / "dem_indicatorlist_zwe.csv", + 9: fixture_path / "opri_data_zwe.csv", + 10: fixture_path / "opri_indicatorlist_zwe.csv", + 11: fixture_path / "opri_metadata_zwe.csv", + 12: fixture_path / "qc_sdg_data_zwe.csv", } assert new_resource_order == [ ("SDG 4 Global and Thematic data", "csv"), @@ -160,21 +161,15 @@ def test_dataset_update_resources( test=True, ) assert results["files_to_upload"] == { - "update__resources__0__upload": join(fixture_path, "sdg_data_zwe.csv"), - "update__resources__1__upload": join( - fixture_path, "sdg_indicatorlist_zwe.csv" - ), - "update__resources__2__upload": join(fixture_path, "sdg_metadata_zwe.csv"), - "update__resources__3__upload": join(fixture_path, "dem_data_zwe.csv"), - "update__resources__4__upload": join( - fixture_path, "dem_indicatorlist_zwe.csv" - ), - "update__resources__5__upload": join(fixture_path, "opri_data_zwe.csv"), - "update__resources__6__upload": join( - fixture_path, "opri_indicatorlist_zwe.csv" - ), - "update__resources__7__upload": join(fixture_path, "opri_metadata_zwe.csv"), - "update__resources__8__upload": join(fixture_path, "qc_sdg_data_zwe.csv"), + "update__resources__0__upload": fixture_path / "sdg_data_zwe.csv", + "update__resources__1__upload": fixture_path / "sdg_indicatorlist_zwe.csv", + "update__resources__2__upload": fixture_path / "sdg_metadata_zwe.csv", + "update__resources__3__upload": fixture_path / "dem_data_zwe.csv", + "update__resources__4__upload": fixture_path / "dem_indicatorlist_zwe.csv", + "update__resources__5__upload": fixture_path / "opri_data_zwe.csv", + "update__resources__6__upload": fixture_path / "opri_indicatorlist_zwe.csv", + "update__resources__7__upload": fixture_path / "opri_metadata_zwe.csv", + "update__resources__8__upload": fixture_path / "qc_sdg_data_zwe.csv", } resources = results["update"]["resources"] cutdown_resources = [] @@ -336,8 +331,11 @@ def test_dataset_update_resources_position( ] assert resources_to_delete == [] assert filestore_resources == { - 0: "tests/fixtures/test_data.csv", - 1: "tests/fixtures/size_hash/ACLED-All-Africa-File_20170101-to-20170708.xlsx", + 0: Path("tests") / "fixtures" / "test_data.csv", + 1: Path("tests") + / "fixtures" + / "size_hash" + / "ACLED-All-Africa-File_20170101-to-20170708.xlsx", } assert new_resource_order == [("test1", "csv"), ("test2", "xlsx")] assert statuses == {"test1": 2, "test2": 2} diff --git a/tests/hdx/data/test_update_logic.py b/tests/hdx/data/test_update_logic.py index e69fac3..cbc1637 100644 --- a/tests/hdx/data/test_update_logic.py +++ b/tests/hdx/data/test_update_logic.py @@ -43,8 +43,8 @@ def configuration(self): } @pytest.fixture(scope="class") - def fixture_path(self): - return join("tests", "fixtures", "update_logic") + def fixture_path(self, fixturesfolder): + return fixturesfolder / "update_logic" @pytest.fixture(scope="class") def temp_dir(self): @@ -52,11 +52,11 @@ def temp_dir(self): @pytest.fixture(scope="class") def new_resources_yaml(self, fixture_path): - return join(fixture_path, "update_logic_resources_new.yaml") + return fixture_path / "update_logic_resources_new.yaml" @pytest.fixture(scope="class") def resources_yaml(self, fixture_path): - return join(fixture_path, "update_logic_resources.yaml") + return fixture_path / "update_logic_resources.yaml" @pytest.fixture(scope="class") def dataset_data(self): diff --git a/tests/hdx/data/test_user.py b/tests/hdx/data/test_user.py index f0db619..64a09d0 100755 --- a/tests/hdx/data/test_user.py +++ b/tests/hdx/data/test_user.py @@ -2,7 +2,7 @@ import copy import json -from os.path import join +from pathlib import Path import pytest from hdx.utilities.dictandlist import merge_two_dictionaries @@ -31,7 +31,7 @@ "id": "9f3e9973-7dbe-4c65-8820-f48578e3ffea", "number_created_packages": 0, } -orgdict = load_yaml(join("tests", "fixtures", "organization_show_results.yaml")) +orgdict = load_yaml(Path("tests") / "fixtures" / "organization_show_results.yaml") orgdict2 = copy.deepcopy(orgdict) del orgdict2["users"] del orgdict2["packages"] @@ -135,12 +135,12 @@ class TestUser: email_config_dict.update(smtp_initargs) @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_user_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_user_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_user_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_user_static.json" @pytest.fixture(scope="function") def read(self): diff --git a/tests/hdx/data/test_vocabulary.py b/tests/hdx/data/test_vocabulary.py index 9d8487f..c46dd21 100755 --- a/tests/hdx/data/test_vocabulary.py +++ b/tests/hdx/data/test_vocabulary.py @@ -2,7 +2,6 @@ import copy import json -from os.path import join import pytest from hdx.utilities.dictandlist import merge_two_dictionaries @@ -1134,12 +1133,12 @@ class TestVocabulary: } @pytest.fixture(scope="class") - def static_yaml(self): - return join("tests", "fixtures", "config", "hdx_vocabulary_static.yaml") + def static_yaml(self, configfolder): + return configfolder / "hdx_vocabulary_static.yaml" @pytest.fixture(scope="class") - def static_json(self): - return join("tests", "fixtures", "config", "hdx_vocabulary_static.json") + def static_json(self, configfolder): + return configfolder / "hdx_vocabulary_static.json" @pytest.fixture(scope="function") def read(self):