Skip to content

Commit

Permalink
update logic and tests now that from_dict works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAkhmetov committed Jul 19, 2024
1 parent 7481d17 commit 2e7a455
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
29 changes: 15 additions & 14 deletions src/portal_visualization/builders/epic_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,42 @@
class EPICConfBuilder(ABC):
def __init__(self, base_conf: ConfCells, epic_uuid) -> None:

if base_conf.conf is None:
conf, cells = base_conf

if conf is None:
raise ValueError("ConfCells object must have a conf attribute")

self._is_plural = isinstance(base_conf.conf, list)
self._is_plural = isinstance(conf, list)

if self._is_plural:
self._base_conf = [
VitessceConfig.from_dict(conf) for conf in base_conf.conf
VitessceConfig.from_dict(conf) for conf in conf
]
else:
self._base_conf: VitessceConfig = VitessceConfig.from_dict(base_conf.conf)

# TODO: from_dict does not copy over requestInit options for dataset files,
# the function needs to be extended upstream to handle this.

self._epic_uuid = epic_uuid
pass

def get_conf_cells(self):
self.apply()
if (self._is_plural):
return get_conf_cells([conf.to_dict() for conf in self._base_conf])
return get_conf_cells(self._base_conf)

def apply(self):
if self._is_plural:
for conf in self._base_conf:
self._apply(conf)
else:
self._apply(self._base_conf)

@abstractmethod
def apply(self): # pragma: no cover
def _apply(self, conf): # pragma: no cover
pass


class SegmentationMaskBuilder(EPICConfBuilder):
def apply(self):
if self._is_plural:
for conf in self._base_conf:
self._apply(conf)
return
# Only expecting one dataset at this point
# dataset = datasets[0]

def _apply(self, conf):
datasets = conf.get_datasets()
Expand Down
17 changes: 8 additions & 9 deletions test/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,19 @@ def test_entity_to_vitessce_conf(entity_path, mocker):
epic_builder = get_epic_builder(entity["uuid"])
assert epic_builder is not None

if (conf is None):
if conf is None:
with pytest.raises(ValueError):
epic_builder(ConfCells(conf, cells), entity["uuid"]).get_conf_cells()
return

built_epic_conf, _ = epic_builder(ConfCells(conf, cells), entity["uuid"]).get_conf_cells()
# Since the `from_dict` function fails to copy over the `requestInit`,
# the following assertion will fail. Once this is implemented upstream,
# the following assertion can be uncommented:
# assert json.dumps(built_epic_conf, indent=2, sort_keys=True) == json.dumps(
# conf, indent=2, sort_keys=True
# )
# For now we just check that the builder is not None
built_epic_conf, _ = epic_builder(
ConfCells(conf, cells), entity["uuid"]
).get_conf_cells()

assert built_epic_conf is not None
assert json.dumps(built_epic_conf, indent=2, sort_keys=True) == json.dumps(
conf, indent=2, sort_keys=True
)


@pytest.mark.parametrize("entity_path", bad_entity_paths, ids=lambda path: path.name)
Expand Down

0 comments on commit 2e7a455

Please sign in to comment.