Example #1
0
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)
Example #2
0
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
Example #3
0
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)
Example #4
0
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
Example #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)
Example #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
Example #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
Example #8
0
File: meta.py Project: 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
Example #9
0
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
Example #10
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)
Example #11
0
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>')
Example #12
0
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>')
Example #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)
Example #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')))
Example #15
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')))
Example #16
0
    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)
Example #17
0
    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)
Example #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')))
Example #19
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')))
Example #20
0
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
Example #21
0
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
Example #22
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
Example #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
Example #24
0
 def asdict(self):
     if self.key in self.store:
         return json.loads(text_type(self.store[self.key], "ascii"))
     else:
         return dict()
Example #25
0
 def asdict(self):
     if self.key in self.store:
         return json.loads(text_type(self.store[self.key], 'ascii'))
     else:
         return dict()
Example #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