Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions src/npg_irods/xenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ def publish_result_dirs(
try:
publish_result_dir(p, remote_root)

num_published += 1

if print_success:
num_published += 1
print(p, file=writer)
except Exception as e:
log.error(f"Failed to publish '{p}': {e}")

number_failed += 1

if print_fail:
number_failed += 1
print(p, file=writer)

return num_dirs, num_published, number_failed
Expand Down
29 changes: 26 additions & 3 deletions tests/xenium/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,42 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from pathlib import Path
from pathlib import Path, PurePath
from unittest.mock import MagicMock, patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you mocking this rather than just publishing a directory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit testing publish_result_dirs rather than integration testing the publish_result_dirs > publish_result_dir > partisan > baton > irods stack to achieve a smaller/narrower test


from partisan.irods import AC, AVU, Collection, Permission
from pytest import mark as m

from npg_irods.common import PlatformNamespace
from npg_irods.xenium import publish_result_dir
from npg_irods.xenium import publish_result_dirs, publish_result_dir


class TestPublish:

@m.context("When publishing a directory fails")
@m.it("Reports failure")
@patch("npg_irods.xenium.publish_result_dir", autospec=True)
def test_publish_result_dirs(self, mock_publish_result_dir: MagicMock):
# Arrange
reader = ["a", "b"]
writer = None
remote_root = PurePath("remote_root")

mock_publish_result_dir.side_effect = [None, Exception]

# Act
num_dirs, num_published, num_failed = publish_result_dirs(
reader, writer, remote_root
)

# Assert
assert num_dirs == 2
assert num_published == 1
assert num_failed == 1

@m.context("When a local Xenium results directory is provided")
@m.it("Publishes it to iRODS with correct collection metadata")
def test_publish_results_directory(self, empty_collection_path):
def test_publish_result_dir(self, empty_collection_path):
local_path = Path(
"tests/data/xenium/synthetic/"
"output-XETG00000__0000000__synthetic_region_001__20000101__000000"
Expand Down