Skip to content

Commit

Permalink
[easy] Test for Codebook.to_json / open_json (#1645)
Browse files Browse the repository at this point in the history
This verifies that the two operations are symmetric.

Test plan: this is the test.
  • Loading branch information
Tony Tung authored Nov 13, 2019
1 parent 9e03fc7 commit 3072f3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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)

0 comments on commit 3072f3c

Please sign in to comment.