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

[easy] Test for Codebook.to_json / open_json #1645

Merged
merged 1 commit into from
Nov 13, 2019
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
5 changes: 3 additions & 2 deletions starfish/core/codebook/codebook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import uuid
from pathlib import Path
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, TypeVar, Union

import numpy as np
Expand Down Expand Up @@ -388,13 +389,13 @@ def open_json(

return cls.from_code_array(codebook_doc[DocumentKeys.MAPPINGS_KEY], n_round, n_channel)

def to_json(self, filename: str) -> None:
def to_json(self, filename: Union[str, Path]) -> None:
"""
Save a codebook to json using SpaceTx Format.

Parameters
----------
filename : str
filename : Union[str, Path]
The name of the file in which to save the codebook.

"""
Expand Down
14 changes: 14 additions & 0 deletions starfish/core/codebook/test/test_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

from .factories import simple_codebook_array
from ..codebook import Codebook


def test_to_json(tmp_path):
code_array = simple_codebook_array()
codebook = Codebook.from_code_array(code_array)
codebook_path = tmp_path / "codebook.json"
codebook.to_json(codebook_path)

loaded_codebook = Codebook.open_json(os.fspath(codebook_path))
assert codebook.equals(loaded_codebook)