-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from paulsengroup/feat/better-errors
Improve error message generated when invalid params are passed to hictkpy.File()
- Loading branch information
Showing
2 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (C) 2024 Roberto Rossini <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import pathlib | ||
|
||
import pytest | ||
|
||
import hictkpy | ||
|
||
testdir = pathlib.Path(__file__).resolve().parent | ||
|
||
pytestmark = pytest.mark.parametrize( | ||
"file,resolution", | ||
[ | ||
(testdir / "data" / "cooler_test_file.mcool", 100_000), | ||
(testdir / "data" / "hic_test_file.hic", 100_000), | ||
], | ||
) | ||
|
||
|
||
class TestClass: | ||
def test_resolution_mismatch(self, file, resolution): | ||
f = hictkpy.MultiResFile(file) | ||
|
||
if not f[resolution].is_cooler(): | ||
pytest.skip(f'File "{file}" is not in .mcool format') | ||
|
||
assert 1_000_000 in f.resolutions() | ||
with pytest.raises(RuntimeError, match="resolution mismatch"): | ||
hictkpy.File(f"{file}::/resolutions/{resolution}", 1_000_000) | ||
|
||
def test_missing_resolution_param(self, file, resolution): | ||
f = hictkpy.MultiResFile(file) | ||
|
||
if f[resolution].is_cooler(): | ||
ext = ".mcool" | ||
else: | ||
ext = ".hic" | ||
|
||
with pytest.raises(RuntimeError, match=f"resolution is required and cannot be None when opening {ext} files"): | ||
hictkpy.File(file) |