コード例 #1
0
ファイル: test_meta.py プロジェクト: alimanfoo/zarr
def assert_json_eq(expect, actual):  # pragma: no cover
    if isinstance(expect, binary_type):
        expect = text_type(expect, 'ascii')
    if isinstance(actual, binary_type):
        actual = text_type(actual, 'ascii')
    ej = json.loads(expect)
    aj = json.loads(actual)
    eq(ej, aj)
コード例 #2
0
ファイル: test_meta.py プロジェクト: christophernhill/zarr
def assert_json_equal(expect, actual):
    if isinstance(expect, binary_type):  # pragma: py3 no cover
        expect = text_type(expect, 'ascii')
    if isinstance(actual, binary_type):
        actual = text_type(actual, 'ascii')
    ej = json.loads(expect)
    aj = json.loads(actual)
    assert ej == aj
コード例 #3
0
ファイル: test_meta.py プロジェクト: will133/zarr
def assert_json_eq(expect, actual):  # pragma: no cover
    if isinstance(expect, binary_type):
        expect = text_type(expect, 'ascii')
    if isinstance(actual, binary_type):
        actual = text_type(actual, 'ascii')
    ej = json.loads(expect)
    aj = json.loads(actual)
    eq(ej, aj)
コード例 #4
0
ファイル: test_meta.py プロジェクト: martindurant/zarr
def assert_json_equal(expect, actual):
    if isinstance(expect, binary_type):  # pragma: py3 no cover
        expect = text_type(expect, 'ascii')
    if isinstance(actual, binary_type):
        actual = text_type(actual, 'ascii')
    ej = json.loads(expect)
    aj = json.loads(actual)
    assert ej == aj
コード例 #5
0
def _ensure_text(l):
    if isinstance(l, text_type):
        return l
    elif isinstance(l, binary_type):
        return text_type(l, 'ascii')
    else:
        raise ValueError('expected text, found %r' % l)
コード例 #6
0
 def get_config(self):
     config = dict()
     config['id'] = self.codec_id
     config['cname'] = text_type(self.cname, 'ascii')
     config['clevel'] = self.clevel
     config['shuffle'] = self.shuffle
     return config
コード例 #7
0
 def _get_nosync(self):
     try:
         data = self.store[self.key]
     except KeyError:
         d = dict()
     else:
         d = json.loads(text_type(data, 'ascii'))
     return d
コード例 #8
0
ファイル: meta.py プロジェクト: will133/zarr
def decode_group_metadata(s):
    if isinstance(s, binary_type):
        s = text_type(s, 'ascii')
    meta = json.loads(s)
    zarr_format = meta.get('zarr_format', None)
    if zarr_format != ZARR_FORMAT:
        raise MetadataError('unsupported zarr format: %s' % zarr_format)
    meta = dict(zarr_format=ZARR_FORMAT, )
    return meta
コード例 #9
0
ファイル: meta.py プロジェクト: alimanfoo/zarr
def decode_group_metadata(s):
    if isinstance(s, binary_type):
        s = text_type(s, 'ascii')
    meta = json.loads(s)
    zarr_format = meta.get('zarr_format', None)
    if zarr_format != ZARR_FORMAT:
        raise MetadataError('unsupported zarr format: %s' % zarr_format)
    meta = dict(
        zarr_format=ZARR_FORMAT,
    )
    return meta
コード例 #10
0
ファイル: convenience.py プロジェクト: martindurant/zarr
 def __call__(self, *args, **kwargs):
     if self.log_file is not None:
         kwargs['file'] = self.log_file
         if PY2:  # pragma: py3 no cover
             # expect file opened in text mode, need to adapt message
             args = [text_type(a) for a in args]
         print(*args, **kwargs)
         if hasattr(self.log_file, 'flush'):
             # get immediate feedback
             self.log_file.flush()
     elif self.log_func is not None:
         self.log_func(*args, **kwargs)
コード例 #11
0
ファイル: test_hierarchy.py プロジェクト: pombredanne/zarr
def _check_tree(g, expect_bytes, expect_text):
    eq(expect_bytes, bytes(g.tree()))
    eq(expect_text, text_type(g.tree()))
    expect_repr = expect_text
    if PY2:  # pragma: py3 no cover
        expect_repr = expect_bytes
    eq(expect_repr, repr(g.tree()))
    # test _repr_html_ lightly
    # noinspection PyProtectedMember
    html = g.tree()._repr_html_().strip()
    assert html.startswith('<link')
    assert html.endswith('</script>')
コード例 #12
0
ファイル: test_hierarchy.py プロジェクト: CSNoyes/zarr
def _check_tree(g, expect_bytes, expect_text):
    eq(expect_bytes, bytes(g.tree()))
    eq(expect_text, text_type(g.tree()))
    expect_repr = expect_text
    if PY2:  # pragma: py3 no cover
        expect_repr = expect_bytes
    eq(expect_repr, repr(g.tree()))
    # test _repr_html_ lightly
    # noinspection PyProtectedMember
    html = g.tree()._repr_html_().strip()
    assert html.startswith('<link')
    assert html.endswith('</script>')
コード例 #13
0
 def __call__(self, *args, **kwargs):
     if self.log_file is not None:
         kwargs['file'] = self.log_file
         if PY2:  # pragma: py3 no cover
             # expect file opened in text mode, need to adapt message
             args = [text_type(a) for a in args]
         print(*args, **kwargs)
         if hasattr(self.log_file, 'flush'):
             # get immediate feedback
             self.log_file.flush()
     elif self.log_func is not None:
         self.log_func(*args, **kwargs)
コード例 #14
0
    def test_init_group(self):
        store = self.create_store()
        init_group(store)

        # check metadata
        assert group_meta_key in store
        meta = decode_group_metadata(store[group_meta_key])
        eq(ZARR_FORMAT, meta['zarr_format'])

        # check attributes
        assert attrs_key in store
        eq(dict(), json.loads(text_type(store[attrs_key], 'ascii')))
コード例 #15
0
ファイル: test_storage.py プロジェクト: alimanfoo/zarr
    def test_init_group(self):
        store = self.create_store()
        init_group(store)

        # check metadata
        assert group_meta_key in store
        meta = decode_group_metadata(store[group_meta_key])
        eq(ZARR_FORMAT, meta['zarr_format'])

        # check attributes
        assert attrs_key in store
        eq(dict(), json.loads(text_type(store[attrs_key], 'ascii')))
コード例 #16
0
ファイル: test_attrs.py プロジェクト: hengthu/zarr
    def test_storage(self):

        store = dict()
        a = Attributes(store=store, key='attrs')
        assert 'foo' not in a
        assert 'bar' not in a
        eq(dict(), a.asdict())

        a['foo'] = 'bar'
        a['baz'] = 42
        assert 'attrs' in store
        assert isinstance(store['attrs'], binary_type)
        d = json.loads(text_type(store['attrs'], 'ascii'))
        eq(dict(foo='bar', baz=42), d)
コード例 #17
0
ファイル: test_attrs.py プロジェクト: alimanfoo/zarr
    def test_storage(self):

        store = dict()
        a = Attributes(store=store, key='attrs')
        assert 'foo' not in a
        assert 'bar' not in a
        eq(dict(), a.asdict())

        a['foo'] = 'bar'
        a['baz'] = 42
        assert 'attrs' in store
        assert isinstance(store['attrs'], binary_type)
        d = json.loads(text_type(store['attrs'], 'ascii'))
        eq(dict(foo='bar', baz=42), d)
コード例 #18
0
    def test_init_array(self):
        store = self.create_store()
        init_array(store, shape=1000, chunks=100)

        # check metadata
        assert array_meta_key in store
        meta = decode_array_metadata(store[array_meta_key])
        eq(ZARR_FORMAT, meta['zarr_format'])
        eq((1000, ), meta['shape'])
        eq((100, ), meta['chunks'])
        eq(np.dtype(None), meta['dtype'])
        eq(default_compressor.get_config(), meta['compressor'])
        assert_is_none(meta['fill_value'])

        # check attributes
        assert attrs_key in store
        eq(dict(), json.loads(text_type(store[attrs_key], 'ascii')))
コード例 #19
0
ファイル: test_storage.py プロジェクト: alimanfoo/zarr
    def test_init_array(self):
        store = self.create_store()
        init_array(store, shape=1000, chunks=100)

        # check metadata
        assert array_meta_key in store
        meta = decode_array_metadata(store[array_meta_key])
        eq(ZARR_FORMAT, meta['zarr_format'])
        eq((1000,), meta['shape'])
        eq((100,), meta['chunks'])
        eq(np.dtype(None), meta['dtype'])
        eq(default_compressor.get_config(), meta['compressor'])
        assert_is_none(meta['fill_value'])

        # check attributes
        assert attrs_key in store
        eq(dict(), json.loads(text_type(store[attrs_key], 'ascii')))
コード例 #20
0
ファイル: meta_v1.py プロジェクト: martindurant/zarr
def decode_metadata(b):
    s = text_type(b, 'ascii')
    meta = json.loads(s)
    zarr_format = meta.get('zarr_format', None)
    if zarr_format != 1:
        raise MetadataError('unsupported zarr format: %s' % zarr_format)
    try:
        meta = dict(
            zarr_format=meta['zarr_format'],
            shape=tuple(meta['shape']),
            chunks=tuple(meta['chunks']),
            dtype=decode_dtype(meta['dtype']),
            compression=meta['compression'],
            compression_opts=meta['compression_opts'],
            fill_value=meta['fill_value'],
            order=meta['order'],
        )
    except Exception as e:
        raise MetadataError('error decoding metadata: %s' % e)
    else:
        return meta
コード例 #21
0
ファイル: meta_v1.py プロジェクト: will133/zarr
def decode_metadata(b):
    s = text_type(b, 'ascii')
    meta = json.loads(s)
    zarr_format = meta.get('zarr_format', None)
    if zarr_format != 1:
        raise MetadataError('unsupported zarr format: %s' % zarr_format)
    try:
        meta = dict(
            zarr_format=meta['zarr_format'],
            shape=tuple(meta['shape']),
            chunks=tuple(meta['chunks']),
            dtype=decode_dtype(meta['dtype']),
            compression=meta['compression'],
            compression_opts=meta['compression_opts'],
            fill_value=meta['fill_value'],
            order=meta['order'],
        )
    except Exception as e:
        raise MetadataError('error decoding metadata: %s' % e)
    else:
        return meta
コード例 #22
0
ファイル: meta.py プロジェクト: alimanfoo/zarr
def decode_array_metadata(s):
    if isinstance(s, binary_type):
        s = text_type(s, 'ascii')
    meta = json.loads(s)
    zarr_format = meta.get('zarr_format', None)
    if zarr_format != ZARR_FORMAT:
        raise MetadataError('unsupported zarr format: %s' % zarr_format)
    try:
        dtype = decode_dtype(meta['dtype'])
        fill_value = decode_fill_value(meta['fill_value'], dtype)
        meta = dict(
            zarr_format=meta['zarr_format'],
            shape=tuple(meta['shape']),
            chunks=tuple(meta['chunks']),
            dtype=dtype,
            compressor=meta['compressor'],
            fill_value=fill_value,
            order=meta['order'],
            filters=meta['filters'],
        )
    except Exception as e:
        raise MetadataError('error decoding metadata: %s' % e)
    else:
        return meta
コード例 #23
0
def decode_array_metadata(s):
    if isinstance(s, binary_type):
        s = text_type(s, 'ascii')
    meta = json.loads(s)
    zarr_format = meta.get('zarr_format', None)
    if zarr_format != ZARR_FORMAT:
        raise MetadataError('unsupported zarr format: %s' % zarr_format)
    try:
        dtype = decode_dtype(meta['dtype'])
        fill_value = decode_fill_value(meta['fill_value'], dtype)
        meta = dict(
            zarr_format=meta['zarr_format'],
            shape=tuple(meta['shape']),
            chunks=tuple(meta['chunks']),
            dtype=dtype,
            compressor=meta['compressor'],
            fill_value=fill_value,
            order=meta['order'],
            filters=meta['filters'],
        )
    except Exception as e:
        raise MetadataError('error decoding metadata: %s' % e)
    else:
        return meta
コード例 #24
0
ファイル: attrs.py プロジェクト: alimanfoo/zarr
 def asdict(self):
     if self.key in self.store:
         return json.loads(text_type(self.store[self.key], "ascii"))
     else:
         return dict()
コード例 #25
0
 def asdict(self):
     if self.key in self.store:
         return json.loads(text_type(self.store[self.key], 'ascii'))
     else:
         return dict()
コード例 #26
0
 def __repr__(self):
     r = '%s(cname=%r, clevel=%r, shuffle=%r)' % \
         (type(self).__name__, text_type(self.cname, 'ascii'),
          self.clevel, self.shuffle)
     return r