Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions src/blosc2/c2array.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ def info(path, urlbase, params=None, headers=None, model=None, auth_token=None):
return json if model is None else model(**json)


def subscribe(root, urlbase, auth_token):
url = _sub_url(urlbase, f"api/subscribe/{root}")
return _xpost(url, auth_token=auth_token)


def fetch_data(path, urlbase, params, auth_token=None, as_blosc2=False):
url = _sub_url(urlbase, f"api/fetch/{path}")
response = _xget(url, params=params, auth_token=auth_token)
Expand Down Expand Up @@ -237,15 +232,8 @@ def __init__(self, path: str, /, urlbase: str | None = None, auth_token: str | N
# Try to 'open' the remote path
try:
self.meta = info(self.path, self.urlbase, auth_token=self.auth_token)
except requests.HTTPError:
# Subscribe to root and try again. It is less latency to subscribe directly
# than to check for the subscription.
root, _ = self.path.split("/", 1)
subscribe(root, self.urlbase, self.auth_token)
try:
self.meta = info(self.path, self.urlbase, auth_token=self.auth_token)
except requests.HTTPError as err:
raise FileNotFoundError(f"Remote path not found: {path}.\nError was: {err}") from err
except requests.HTTPError as err:
raise FileNotFoundError(f"Remote path not found: {path}.\nError was: {err}") from err
cparams = self.meta["schunk"]["cparams"]
# Remove "filters, meta" from cparams; this is an artifact from the server
cparams.pop("filters, meta", None)
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def pytest_configure(config):


@pytest.fixture(scope="session")
def c2sub_context():
def cat2_context():
# You may use the URL and credentials for an already existing user
# in a different Caterva2 subscriber.
urlbase = os.environ.get("BLOSC_C2URLBASE", "https://demo.caterva2.net/")
urlbase = os.environ.get("BLOSC_C2URLBASE", "https://cat2.cloud/testing/")
c2params = {"urlbase": urlbase, "username": None, "password": None}
with blosc2.c2context(**c2params):
yield c2params
Expand Down
16 changes: 8 additions & 8 deletions tests/ndarray/test_c2array_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
pytestmark = pytest.mark.network

NITEMS_SMALL = 1_000
ROOT = "b2tests"
ROOT = "@public"
DIR = "expr/"


Expand Down Expand Up @@ -51,7 +51,7 @@ def get_arrays(shape, chunks_blocks):
(False, False),
],
)
def test_simple(chunks_blocks, c2sub_context):
def test_simple(chunks_blocks, cat2_context):
shape = (60, 60)
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)

Expand All @@ -67,7 +67,7 @@ def test_simple(chunks_blocks, c2sub_context):
np.testing.assert_allclose(res[:], nres)


def test_simple_getitem(c2sub_context):
def test_simple_getitem(cat2_context):
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
Expand All @@ -91,7 +91,7 @@ def test_simple_getitem(c2sub_context):
(False, False),
],
)
def test_ixxx(chunks_blocks, c2sub_context):
def test_ixxx(chunks_blocks, cat2_context):
shape = (60, 60)
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
expr = a1**3 + a2**2 + a3**3 - a4 + 3
Expand All @@ -103,7 +103,7 @@ def test_ixxx(chunks_blocks, c2sub_context):
np.testing.assert_allclose(res[:], nres)


def test_complex(c2sub_context):
def test_complex(cat2_context):
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_complex(c2sub_context):
(False, False),
],
)
def test_mix_operands(chunks_blocks, c2sub_context):
def test_mix_operands(chunks_blocks, cat2_context):
shape = (60, 60)
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
b1 = blosc2.asarray(na1, chunks=a1.chunks, blocks=a1.blocks)
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_mix_operands(chunks_blocks, c2sub_context):


# Tests related with save method
def test_save(c2sub_context):
def test_save(cat2_context):
shape = (60, 60)
tol = 1e-17
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, (False, True))
Expand Down Expand Up @@ -212,7 +212,7 @@ def broadcast_shape(request):


@pytest.fixture
def broadcast_fixture(broadcast_shape, c2sub_context):
def broadcast_fixture(broadcast_shape, cat2_context):
shape1, shape2 = broadcast_shape
dtype = np.float64
na1 = np.linspace(0, 1, np.prod(shape1), dtype=dtype).reshape(shape1)
Expand Down
8 changes: 4 additions & 4 deletions tests/ndarray/test_c2array_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
pytestmark = pytest.mark.network

NITEMS_SMALL = 1_000
ROOT = "b2tests"
ROOT = "@public"
DIR = "expr/"


Expand Down Expand Up @@ -45,7 +45,7 @@ def get_arrays(shape, chunks_blocks):


@pytest.mark.parametrize("reduce_op", ["sum", pytest.param("all", marks=pytest.mark.heavy)])
def test_reduce_bool(reduce_op, c2sub_context):
def test_reduce_bool(reduce_op, cat2_context):
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_reduce_bool(reduce_op, c2sub_context):
@pytest.mark.parametrize("axis", [1])
@pytest.mark.parametrize("keepdims", [True, False])
@pytest.mark.parametrize("dtype_out", [np.int16])
def test_reduce_params(chunks_blocks, axis, keepdims, dtype_out, reduce_op, c2sub_context):
def test_reduce_params(chunks_blocks, axis, keepdims, dtype_out, reduce_op, cat2_context):
shape = (60, 60)
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
if axis is not None and np.isscalar(axis) and len(a1.shape) >= axis:
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_reduce_params(chunks_blocks, axis, keepdims, dtype_out, reduce_op, c2su
],
)
@pytest.mark.parametrize("axis", [0])
def test_reduce_expr_arr(chunks_blocks, axis, reduce_op, c2sub_context):
def test_reduce_expr_arr(chunks_blocks, axis, reduce_op, cat2_context):
shape = (60, 60)
a1, a2, a3, a4, na1, na2, na3, na4 = get_arrays(shape, chunks_blocks)
if axis is not None and len(a1.shape) >= axis:
Expand Down
6 changes: 3 additions & 3 deletions tests/ndarray/test_c2array_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import blosc2

ROOT = "b2tests"
ROOT = "@public"
DIR = "expr/"

pytestmark = pytest.mark.network
Expand All @@ -34,7 +34,7 @@ def udf1p(inputs_tuple, output, offset):
),
],
)
def test_1p(chunks, blocks, chunked_eval, c2sub_context):
def test_1p(chunks, blocks, chunked_eval, cat2_context):
dtype = np.float64
shape = (60, 60)
urlpath = f"ds-0-10-linspace-{dtype.__name__}-(True, False)-a1-{shape}d.b2nd"
Expand Down Expand Up @@ -71,7 +71,7 @@ def udf2p(inputs_tuple, output, offset):
pytest.param((53, 20), (10, 13), (slice(3, 8), slice(9, 12)), None, False),
],
)
def test_getitem(chunks, blocks, slices, urlpath, contiguous, chunked_eval, c2sub_context):
def test_getitem(chunks, blocks, slices, urlpath, contiguous, chunked_eval, cat2_context):
dtype = np.float64
shape = (60, 60)
blosc2.remove_urlpath(urlpath)
Expand Down
8 changes: 4 additions & 4 deletions tests/ndarray/test_proxy_c2array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pytestmark = pytest.mark.network

NITEMS_SMALL = 1_000
ROOT = "b2tests"
ROOT = "@public"
DIR = "expr/"


Expand Down Expand Up @@ -44,7 +44,7 @@ def get_array(shape, chunks_blocks):
("proxy", (slice(37, 53), slice(19, 233))),
],
)
def test_simple(chunks_blocks, c2sub_context, urlpath, slices):
def test_simple(chunks_blocks, cat2_context, urlpath, slices):
shape = (60, 60)
a = get_array(shape, chunks_blocks)
b = blosc2.Proxy(a, urlpath=urlpath, mode="w")
Expand All @@ -62,7 +62,7 @@ def test_simple(chunks_blocks, c2sub_context, urlpath, slices):
blosc2.remove_urlpath(urlpath)


def test_small(c2sub_context):
def test_small(cat2_context):
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
a = get_array(shape, chunks_blocks)
Expand All @@ -77,7 +77,7 @@ def test_small(c2sub_context):
np.testing.assert_allclose(cache[...], a[...])


def test_open(c2sub_context):
def test_open(cat2_context):
urlpath = "proxy.b2nd"
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
Expand Down
4 changes: 2 additions & 2 deletions tests/ndarray/test_proxy_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

pytestmark = pytest.mark.network

ROOT = "b2tests"
ROOT = "@public"
DIR = "expr/"


Expand Down Expand Up @@ -60,7 +60,7 @@ def get_arrays(shape, chunks_blocks):
(False, False),
],
)
def test_expr_proxy_operands(chunks_blocks, c2sub_context):
def test_expr_proxy_operands(chunks_blocks, cat2_context):
shape = (60, 60)
a1, a2, a3, a4, na1, na2, na3, na4, cleanup_paths = get_arrays(shape, chunks_blocks)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_open_c2array.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
pytestmark = pytest.mark.network

NITEMS_SMALL = 1_000
ROOT = "b2tests"
ROOT = "@public"
DIR = "expr/"


def test_open_c2array(c2sub_context):
def test_open_c2array(cat2_context):
dtype = np.float64
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
Expand Down Expand Up @@ -50,16 +50,16 @@ def test_open_c2array(c2sub_context):
_ = blosc2.open(urlpath, mode="r", offset=0, cparams={})


def test_open_c2array_args(c2sub_context): # instance args prevail
def test_open_c2array_args(cat2_context): # instance args prevail
dtype = np.float64
shape = (NITEMS_SMALL,)
chunks_blocks = "default"
path = f"ds-0-10-linspace-{dtype.__name__}-{chunks_blocks}-a1-{shape}d.b2nd"
path = pathlib.Path(f"{ROOT}/{DIR + path}").as_posix()

with blosc2.c2context(urlbase="https://wrong.example.com/", auth_token="wrong-token"):
urlbase = c2sub_context["urlbase"]
auth_token = blosc2.c2array.login(**c2sub_context) if c2sub_context["username"] else None
urlbase = cat2_context["urlbase"]
auth_token = blosc2.c2array.login(**cat2_context) if cat2_context["username"] else None
a1 = blosc2.C2Array(path, urlbase=urlbase, auth_token=auth_token)
urlpath = blosc2.URLPath(path, urlbase=urlbase, auth_token=auth_token)
a_open = blosc2.open(urlpath, mode="r", offset=0)
Expand All @@ -71,7 +71,7 @@ def c2sub_user():
def rand32():
return random.randint(0, 0x7FFFFFFF)

urlbase = "https://demo-auth.caterva2.net/"
urlbase = "https://cat2.cloud/testing/"
username = f"user+{rand32():x}@example.com"
password = hex(rand32())

Expand Down
Loading