Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Nov 11, 2024
1 parent eb802e7 commit fafb9ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
15 changes: 15 additions & 0 deletions test/test_file_creation_cool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ def setup_method():
logging.basicConfig(level="INFO", force=True)
logging.getLogger().setLevel("INFO")

def test_accessors(self, file, resolution, tmpdir):
bins = hictkpy.File(file, resolution).bins()

path = tmpdir / "test.cool"
w = hictkpy.cooler.FileWriter(path, bins)

assert str(w).startswith("CoolFileWriter(")
assert w.path() == path
if resolution is None:
assert w.resolution() == 0
else:
assert w.resolution() == resolution
assert w.chromosomes() == bins.chromosomes()
assert len(w.bins().to_df().compare(bins.to_df())) == 0

def test_file_creation_thin_pixel(self, file, resolution, tmpdir):
f = hictkpy.File(file, resolution)
if f.bins().type() != "fixed":
Expand Down
20 changes: 17 additions & 3 deletions test/test_file_creation_hic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ def setup_method():
logging.basicConfig(level="INFO", force=True)
logging.getLogger().setLevel("INFO")

def test_accessors(self, file, resolution, tmpdir):
bins = hictkpy.File(file, resolution).bins()
if bins.type() != "fixed":
pytest.skip(f'BinTable of file "{file}" does not have fixed bins.')

path = tmpdir / "test.hic"
w = hictkpy.hic.FileWriter(path, bins)

assert str(w).startswith("HiCFileWriter(")
assert w.path() == path
assert w.resolutions() == [resolution]
assert w.chromosomes() == bins.chromosomes()
assert len(w.bins(resolution).to_df().compare(bins.to_df())) == 0

def test_file_creation_thin_pixel(self, file, resolution, tmpdir):
f = hictkpy.File(file, resolution)
if f.bins().type() != "fixed":
Expand All @@ -39,7 +53,7 @@ def test_file_creation_thin_pixel(self, file, resolution, tmpdir):
df = f.fetch(join=False).to_df()
expected_sum = df["count"].sum()

path = tmpdir / "test1.hic"
path = tmpdir / "test.hic"
w = hictkpy.hic.FileWriter(path, f.chromosomes(), f.resolution())

chunk_size = 1000
Expand Down Expand Up @@ -67,7 +81,7 @@ def test_file_creation(self, file, resolution, tmpdir):
df = f.fetch(join=True).to_df()
expected_sum = df["count"].sum()

path = tmpdir / "test2.hic"
path = tmpdir / "test.hic"
w = hictkpy.hic.FileWriter(path, f.chromosomes(), f.resolution())

chunk_size = 1000
Expand All @@ -93,7 +107,7 @@ def test_file_creation_bin_table(self, file, resolution, tmpdir):
df = f.fetch(join=True).to_df()
expected_sum = df["count"].sum()

path = tmpdir / "test2.hic"
path = tmpdir / "test.hic"
if f.bins().type() != "fixed":
with pytest.raises(Exception):
hictkpy.hic.FileWriter(path, f.bins())
Expand Down

0 comments on commit fafb9ef

Please sign in to comment.