Skip to content

Commit

Permalink
Merge pull request #20 from NHFLO/actions
Browse files Browse the repository at this point in the history
Refactor tests to use latest data paths and improve folder retrieval …
  • Loading branch information
bdestombe authored Nov 26, 2024
2 parents 73a2d9f + 51aae4d commit 84b8f91
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions tests/test_forbidden_file_formats.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
"""Test for forbidden file formats."""

from __future__ import annotations

import os
from pathlib import Path

import pytest

from nhflodata.get_paths import get_abs_data_path, get_repository_data

def get_all_folders(root_dir: str = ".") -> list[Path]:
"""
Get all folders in the given directory recursively.

Parameters
----------
root_dir : str, optional
Root directory to start searching from, by default current directory (".")
def get_latest_data_paths() -> list[Path]:
"""
Get paths to all latest data versions in the repository.
Returns
-------
Expand All @@ -23,11 +20,13 @@ def get_all_folders(root_dir: str = ".") -> list[Path]:
Examples
--------
>>> folders = get_all_folders("./data")
>>> folders = get_latest_data_paths()
>>> print(folders[0])
./data/subfolder1
./data/subfolder1/v1.2.3
"""
return [Path(os.path.join(root, dir_name)) for root, dirs, _ in os.walk(root_dir) for dir_name in dirs]
dataset_names = sorted(get_repository_data().keys())
dataset_paths = [get_abs_data_path(name, version="latest", location="mockup") for name in dataset_names]
return [Path(path) for path in dataset_paths]


def find_files_by_extension(folder: Path, extensions: set[str]) -> list[Path]:
Expand Down Expand Up @@ -76,6 +75,8 @@ def find_files_by_extension(folder: Path, extensions: set[str]) -> list[Path]:


pytest.mark.xfail(strict=False)


def test_no_shapefile_or_geopackage():
"""
Test for absence of shapefile and geopackage formats.
Expand All @@ -98,7 +99,7 @@ def test_no_shapefile_or_geopackage():
- Single file format instead of multiple files (like shapefiles)
"""
forbidden_geo_extensions = {".shp", ".shx", ".dbf", ".prj", ".gpkg"}
folders = get_all_folders()
folders = get_latest_data_paths()

forbidden_files = []
for folder in folders:
Expand All @@ -115,6 +116,8 @@ def test_no_shapefile_or_geopackage():


pytest.mark.xfail(strict=False)


def test_no_excel_files():
"""
Test for absence of Excel file formats.
Expand All @@ -138,7 +141,7 @@ def test_no_excel_files():
- More universal compatibility
"""
excel_extensions = {".xls", ".xlsx", ".xlsm"}
folders = get_all_folders()
folders = get_latest_data_paths()

excel_files = []
for folder in folders:
Expand Down

0 comments on commit 84b8f91

Please sign in to comment.