Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/add data checks #179

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d55523e
fix: add check for missing/invalid args in project
AngRodrigues Dec 17, 2024
596ddb3
chore: add mention to issue
AngRodrigues Dec 17, 2024
3345bbe
chore: clear warnings
AngRodrigues Jan 7, 2025
b1a94bd
chore: make warnings clear
AngRodrigues Jan 7, 2025
1bb6e47
chore: make warnings clear
AngRodrigues Jan 7, 2025
27ea51d
tests: bypass the necessary dataset requirement
AngRodrigues Jan 7, 2025
c9da10d
fix: skip required file checks if using loop server data
AngRodrigues Jan 7, 2025
713abff
fix: make the config check through project
AngRodrigues Jan 7, 2025
b52d540
tests: add tests for config checks
AngRodrigues Jan 7, 2025
6322872
style: style fixes by ruff and autoformatting by black
AngRodrigues Jan 7, 2025
554ed6a
fiz: actually use libmamba on build
AngRodrigues Jan 7, 2025
f9752b2
revert previous commit
AngRodrigues Jan 7, 2025
9be3ac6
fix: add init commit
AngRodrigues Jan 8, 2025
29466fe
style: style fixes by ruff and autoformatting by black
AngRodrigues Jan 8, 2025
848f31c
tests: add tests for data_checks for each datatype
AngRodrigues Jan 8, 2025
0257a55
Merge branch 'fix/add_data_checks' of https://github.com/Loop3D/map2l…
AngRodrigues Jan 8, 2025
c68ce9a
fix: actually abort the process if validation fails
AngRodrigues Jan 8, 2025
b9663d6
Merge branch 'fix--162' of https://github.com/Loop3D/map2loop into fi…
AngRodrigues Jan 8, 2025
06ff551
fix: add config check step to project
AngRodrigues Jan 8, 2025
6529bf8
fix: add extra checks for config dictionary
AngRodrigues Jan 8, 2025
ce44489
tests: add config test and reorganise
AngRodrigues Jan 8, 2025
0a85eac
fix: add data checks for fold data and update tests accordingly
AngRodrigues Jan 8, 2025
9eb8fed
Merge branch 'master' of https://github.com/Loop3D/map2loop into fix/…
AngRodrigues Jan 13, 2025
273b82d
typos from merging
AngRodrigues Jan 13, 2025
04b43f1
chore: another typo
AngRodrigues Jan 13, 2025
fc2e393
fix: remove kwargs from project
AngRodrigues Jan 13, 2025
e919f94
chore: refactor geometry checks
AngRodrigues Jan 13, 2025
0002262
chore: update tests for geometry refactor
AngRodrigues Jan 13, 2025
b066a22
chore: refactor id checks
AngRodrigues Jan 14, 2025
141c39f
Merge branch 'master' of https://github.com/Loop3D/map2loop into fix/…
AngRodrigues Jan 14, 2025
9001a08
chore: refactor mandatory fields for str and geo
AngRodrigues Jan 14, 2025
652281c
finalise refactor
AngRodrigues Jan 14, 2025
d1f67a9
chore: finalise details
AngRodrigues Jan 14, 2025
1c42d2e
docs: comment typo
lachlangrose Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests: add tests for config checks
AngRodrigues committed Jan 7, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit b52d54014fc493846ff3a068f8dc8b00bb5b0f82
150 changes: 150 additions & 0 deletions tests/project/test_config_arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import pytest
import pathlib
from unittest.mock import patch
from map2loop.project import Project
from map2loop.m2l_enums import Datatype
import map2loop

# ------------------------------------------------------------------------------
# Common fixtures or helper data (bounding box, minimal filenames, etc.)
# ------------------------------------------------------------------------------

@pytest.fixture
def minimal_bounding_box():
return {
"minx": 515687.31005864,
"miny": 7493446.76593407,
"maxx": 562666.860106543,
"maxy": 7521273.57407786,
"base": -3200,
"top": 3000,
}

@pytest.fixture
def geology_file():
return str(
pathlib.Path(map2loop.__file__).parent
/ pathlib.Path('_datasets/geodata_files/hamersley/geology.geojson')
)

@pytest.fixture
def structure_file():
return str(
pathlib.Path(map2loop.__file__).parent
/ pathlib.Path('_datasets/geodata_files/hamersley/structure.geojson')
)

@pytest.fixture
def dtm_file():
return str(
pathlib.Path(map2loop.__file__).parent
/ pathlib.Path('_datasets/geodata_files/hamersley/dtm_rp.tif')
)

@pytest.fixture
def valid_config_dictionary():
"""
A valid config dictionary that meets the 'structure' and 'geology' requirements
"""
return {
"structure": {
"dipdir_column": "azimuth2",
"dip_column": "dip"
},
"geology": {
"unitname_column": "unitname",
"alt_unitname_column": "code",
}
}



# 1) config_filename and config_dictionary both present should raise ValueError
def test_config_filename_and_dictionary_raises_error(
minimal_bounding_box, geology_file, dtm_file, structure_file, valid_config_dictionary
):

with pytest.raises(ValueError, match="Both 'config_filename' and 'config_dictionary' were provided"):
Project(
bounding_box=minimal_bounding_box,
working_projection="EPSG:28350",
geology_filename=geology_file,
dtm_filename=dtm_file,
structure_filename=structure_file,
config_filename="dummy_config.json",
config_dictionary=valid_config_dictionary,
)

# 2) No config_filename or config_dictionary should raise ValueError
def test_no_config_provided_raises_error(
minimal_bounding_box, geology_file, dtm_file, structure_file
):

with pytest.raises(ValueError, match="A config file is required to run map2loop"):
Project(
bounding_box=minimal_bounding_box,
working_projection="EPSG:28350",
geology_filename=geology_file,
dtm_filename=dtm_file,
structure_filename=structure_file,
)

# 3) Passing an unexpected argument should raise TypeError
def test_unexpected_argument_raises_error(
minimal_bounding_box, geology_file, dtm_file, structure_file, valid_config_dictionary
):

with pytest.raises(TypeError, match="unexpected keyword argument 'config_file'"):
Project(
bounding_box=minimal_bounding_box,
working_projection="EPSG:28350",
geology_filename=geology_file,
dtm_filename=dtm_file,
structure_filename=structure_file,
config_dictionary=valid_config_dictionary,
config_file="wrong_kwarg.json",
)

# 4) Dictionary missing a required key should raise ValueError

def test_dictionary_missing_required_key_raises_error(
minimal_bounding_box, geology_file, dtm_file, structure_file
):

invalid_dictionary = {
"structure": {"dipdir_column": "azimuth2", "dip_column": "dip"},
"geology": {"unitname_column": "unitname"} # alt_unitname_column missing
}

with pytest.raises(ValueError, match="Missing required key 'alt_unitname_column' for 'geology'"):
Project(
bounding_box=minimal_bounding_box,
working_projection="EPSG:28350",
geology_filename=geology_file,
dtm_filename=dtm_file,
structure_filename=structure_file,
config_dictionary=invalid_dictionary,
)

# 5) All good => The Project should be created without errors
def test_good_config_runs_successfully(
minimal_bounding_box, geology_file, dtm_file, structure_file, valid_config_dictionary
):
project = None
try:
project = Project(
bounding_box=minimal_bounding_box,
working_projection="EPSG:28350",
geology_filename=geology_file,
dtm_filename=dtm_file,
structure_filename=structure_file,
config_dictionary=valid_config_dictionary,
)
except Exception as e:
pytest.fail(f"Project initialization raised an unexpected exception: {e}")

assert project is not None, "Project was not created."
assert project.map_data.config.structure_config["dipdir_column"] == "azimuth2"
assert project.map_data.config.structure_config["dip_column"] == "dip"
assert project.map_data.config.geology_config["unitname_column"] == "unitname"
assert project.map_data.config.geology_config["alt_unitname_column"] == "code"