|
| 1 | +import datetime |
| 2 | +import os |
| 3 | +import random |
| 4 | +import string |
| 5 | + |
| 6 | +import numpy as np |
| 7 | +import pytest |
| 8 | + |
| 9 | +import tiledb |
| 10 | +from tiledb.tests.common import DiskTestCase |
| 11 | + |
| 12 | +tiledb_token = os.getenv("TILEDB_TOKEN") |
| 13 | +tiledb_namespace = os.getenv("TILEDB_NAMESPACE") |
| 14 | +s3_bucket = os.getenv("S3_BUCKET") |
| 15 | + |
| 16 | + |
| 17 | +@pytest.mark.skipif( |
| 18 | + not os.getenv("CI") and tiledb_token is None, |
| 19 | + reason="No token was provided in a non-CI environment. Please set the TILEDB_TOKEN environment variable to run this test.", |
| 20 | +) |
| 21 | +class CloudTest(DiskTestCase): |
| 22 | + def test_save_and_open_array_from_cloud(self): |
| 23 | + config = tiledb.Config({"rest.token": tiledb_token}) |
| 24 | + ctx = tiledb.Ctx(config=config) |
| 25 | + |
| 26 | + # Useful to include the datetime in the array name to handle multiple consecutive runs of the test. |
| 27 | + # Random letters are added to the end to ensure that conflicts are avoided, especially in CI environments where multiple tests may run in parallel. |
| 28 | + array_name = ( |
| 29 | + datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") |
| 30 | + + "-" |
| 31 | + + "".join(random.choice(string.ascii_letters) for _ in range(5)) |
| 32 | + ) |
| 33 | + uri = f"tiledb://{tiledb_namespace}/s3://{s3_bucket}/{array_name}" |
| 34 | + |
| 35 | + with tiledb.from_numpy(uri, np.random.rand(3, 2), ctx=ctx) as T: |
| 36 | + self.assertTrue(tiledb.array_exists(uri, ctx=ctx)) |
| 37 | + self.assertTrue( |
| 38 | + T.schema |
| 39 | + == tiledb.ArraySchema( |
| 40 | + domain=tiledb.Domain( |
| 41 | + tiledb.Dim( |
| 42 | + name="__dim_0", |
| 43 | + domain=(0, 2), |
| 44 | + tile=3, |
| 45 | + dtype="uint64", |
| 46 | + filters=tiledb.FilterList([tiledb.ZstdFilter(level=-1)]), |
| 47 | + ), |
| 48 | + tiledb.Dim( |
| 49 | + name="__dim_1", |
| 50 | + domain=(0, 1), |
| 51 | + tile=2, |
| 52 | + dtype="uint64", |
| 53 | + filters=tiledb.FilterList([tiledb.ZstdFilter(level=-1)]), |
| 54 | + ), |
| 55 | + ), |
| 56 | + attrs=[ |
| 57 | + tiledb.Attr( |
| 58 | + name="", |
| 59 | + dtype="float64", |
| 60 | + var=False, |
| 61 | + nullable=False, |
| 62 | + enum_label=None, |
| 63 | + ), |
| 64 | + ], |
| 65 | + cell_order="row-major", |
| 66 | + tile_order="row-major", |
| 67 | + sparse=False, |
| 68 | + ) |
| 69 | + ) |
| 70 | + |
| 71 | + tiledb.Array.delete_array(uri, ctx=ctx) |
0 commit comments