Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Nov 18, 2024
1 parent 52a06cf commit 9d3c304
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions tests/matrixstore/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from unittest.mock import ANY, Mock

import numpy as np
import pandas as pd
import pytest
from fastapi import UploadFile
from starlette.datastructures import Headers
Expand Down Expand Up @@ -53,11 +52,11 @@ def test_create__nominal_case(self, matrix_service: MatrixService) -> None:
# A "real" hash value is calculated
assert matrix_id, "ID can't be empty"

# The matrix is saved in the content repository as a HDF file
# The matrix is saved in the content repository as a TSV file
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
content_path = bucket_dir.joinpath(f"{matrix_id}.hdf")
array = pd.read_hdf(content_path).__array__()
assert (array == np.array(data)).all()
content_path = bucket_dir.joinpath(f"{matrix_id}.tsv")
array = np.loadtxt(content_path)
assert array.all() == np.array(data).all()

# A matrix object is stored in the database
with db():
Expand All @@ -77,11 +76,11 @@ def test_create__from_numpy_array(self, matrix_service: MatrixService) -> None:
# A "real" hash value is calculated
assert matrix_id, "ID can't be empty"

# The matrix is saved in the content repository as an HDF file
# The matrix is saved in the content repository as a TSV file
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
content_path = bucket_dir.joinpath(f"{matrix_id}.hdf")
array = pd.read_hdf(content_path).__array__()
assert (array == data).all()
content_path = bucket_dir.joinpath(f"{matrix_id}.tsv")
array = np.loadtxt(content_path)
assert array.all() == data.all()

# A matrix object is stored in the database
with db():
Expand All @@ -103,8 +102,8 @@ def test_create__side_effect(self, matrix_service: MatrixService) -> None:

# the associated matrix file must not be deleted
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
hdf_files = list(bucket_dir.glob("*.hdf"))
assert hdf_files
tsv_files = list(bucket_dir.glob("*.tsv"))
assert tsv_files

# Nothing is stored in the database
with db():
Expand Down Expand Up @@ -160,8 +159,8 @@ def test_delete__nominal_case(self, matrix_service: MatrixService) -> None:

# The matrix in no more available in the content repository
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
hdf_files = list(bucket_dir.glob("*.hdf"))
assert not hdf_files
tsv_files = list(bucket_dir.glob("*.tsv"))
assert not tsv_files

# The matrix object is deleted from the database
with db():
Expand All @@ -176,8 +175,8 @@ def test_delete__missing(self, matrix_service: MatrixService) -> None:

# then, the matrix in no more available in the content repository
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
hdf_files = list(bucket_dir.glob("*.hdf"))
assert not hdf_files
tsv_files = list(bucket_dir.glob("*.tsv"))
assert not tsv_files

# The matrix object is deleted from the database
with db():
Expand Down Expand Up @@ -232,14 +231,11 @@ def test_create_by_importation__nominal_case(
# A "real" hash value is calculated
assert info.id, "ID can't be empty"

# The matrix is saved in the content repository as an HDF file
# The matrix is saved in the content repository as a TSV file
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
content_path = bucket_dir.joinpath(f"{info.id}.hdf")
if content_path.stat().st_size == 0:
actual = np.empty(shape=1)
else:
actual = pd.read_hdf(content_path).__array__()
assert (actual == matrix).all()
content_path = bucket_dir.joinpath(f"{info.id}.tsv")
actual = np.loadtxt(content_path)
assert actual.all() == matrix.all()

# A matrix object is stored in the database
with db():
Expand Down Expand Up @@ -302,14 +298,11 @@ def test_create_by_importation__zip_file(self, matrix_service: MatrixService, co
# A "real" hash value is calculated
assert info.id, "ID can't be empty"

# The matrix is saved in the content repository as an HDF file
# The matrix is saved in the content repository as a TSV file
bucket_dir = matrix_service.matrix_content_repository.bucket_dir
content_path = bucket_dir.joinpath(f"{info.id}.hdf")
if content_path.stat().st_size == 0:
actual = np.empty(shape=1)
else:
actual = pd.read_hdf(content_path).__array__()
assert (actual == matrix).all()
content_path = bucket_dir.joinpath(f"{info.id}.tsv")
actual = np.loadtxt(content_path)
assert actual.all() == matrix.all()

# A matrix object is stored in the database
with db():
Expand Down

0 comments on commit 9d3c304

Please sign in to comment.