Skip to content

Commit

Permalink
added test for Graphicle subscripting #174
Browse files Browse the repository at this point in the history
  • Loading branch information
jacanchaplais committed Mar 1, 2024
1 parent f001db1 commit f7d0b4e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
"""
import cmath
import dataclasses as dc
import gzip
import json
import math
import random
import string
import typing as ty
from pathlib import Path

import numpy as np
import pytest

import graphicle as gcl

ZERO_TOL = 1.0e-10 # absolute tolerance for detecting zero-values
SCRIPT_DIR = Path(__file__).parent


def random_alphanum(length: int) -> str:
Expand Down Expand Up @@ -173,3 +178,17 @@ def test_maskgroup_serialize_inverse() -> None:
)
invertible &= maskgroup.equal_to(gcl.MaskGroup(maskgroup.serialize()))
assert invertible, "Serializing MaskGroups is not invertible."


def load_graphicle_from_json(file_obj: ty.TextIO) -> gcl.Graphicle:
graph_dict = json.load(file_obj)
return gcl.Graphicle(
adj=graph_dict.pop("adj"),
particles=gcl.ParticleSet.from_numpy(**graph_dict),
)


def test_composite_subscript() -> None:
with gzip.open(SCRIPT_DIR / "sample.json.gz", mode="rt") as file_obj:
graph = load_graphicle_from_json(file_obj)
_ = graph[graph.final]

0 comments on commit f7d0b4e

Please sign in to comment.