def test_compress_result(): """ check full dblock length result vectors are compressed to lists of tuples marking start,stop sample of failed test intervals [ (x0,x1) ... (x0,x1) """ import itertools pg = pygarv.PyGarv(mkh5_f=no_pg_h5) # degenerate dblock len == 0, not typical result = np.zeros(shape=(0, ), dtype=bool) fails = pg._compress_result(result) assert fails == [] # smoke test all combinations of T,F up to len 8 # eyeball check of singletons, runs in any # position appears ok for n in range(9): results = list(itertools.product([0, 1], repeat=n)) for r in results: result = np.array(r) fails = pg._compress_result(result) # print(result) # print(fails) # print() cleanup_h5()
def test_decode_pygarv_stream(): reset_h5() pg = pygarv.PyGarv(pg_h5) for i, dbp in enumerate(pg.dblock_paths): _, dblock = pg.mkh5.get_dblock(dbp) tr_doc = pg.tr_docs[i] pygarv_stream = dblock["pygarv"] result, fails = pg._decode_pygarv_stream(pygarv_stream, tr_doc) if any(result > 0): pass # print(tr_doc) cleanup_h5()
def test_update_mkh5(): # start w/ fresh h5 data reset_h5() # work on tmp in case there is trouble ... tmp_f = f"{pg_h5}_tmp" r = subprocess.run(["cp", no_pg_h5, tmp_f]) # init pg = pygarv.PyGarv(mkh5_f=tmp_f) pg._update_tr_docs_from_yaml_f(yarf_f) # load yarf tests pg._update_mkh5() # actually mod the h5 file # rename the garv marked file r = subprocess.run(["mv", tmp_f, pg_h5]) # PyGarv instance w/ loadable, runnable, save-able tests return pg
def test_update_tr_docs(): """build pygarv.tr_docs from an h5 file with tests given as .yarf YAML""" # start fresh reset_h5() pg = pygarv.PyGarv(mkh5_f=no_pg_h5) pg.yarf_io = pygarv.PyYarf() yarf_docs = pg.yarf_io.read_from_yaml(TEST_DIR("data/calstest.yarf")) # dry run individual tests all tests individually for dbp_idx, dbp in enumerate(pg.mkh5.data_blocks): yarf_doc = yarf_docs[dbp_idx] for test_idx, test in enumerate(yarf_doc["tests"]): # default test_idx=None is to append the tests and results exception = pg._update_tr_docs(dbp_idx, test_idx, test) if exception is not None: raise exception cleanup_h5()
def test_init_pg(): """ basic calling pattern on un-pygarved h5 """ reset_h5() pg = pygarv.PyGarv(mkh5_f=pg_h5) return pg