Skip to content

Conversation

@ZohebShaikh
Copy link
Contributor

Checklist

  • Add a Changelog entry
  • Add the ticket number which this PR closes to the comment section

("adapter_sql_one_partition"),
("adapter_duckdb_one_partition"),
("adapter_psql_one_partition"),
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could instead shrink all the very similar SQLAdapter fixtures into one fixture that fetches the right database scheme and number of partitions?

async def _postgresql_uri() -> AsyncGenerator[str, None]:
    uri = os.getenv("TILED_TEST_POSTGRESQL_URI")
    if uri is None:
        pytest.skip("TILED_TEST_POSTGRESQL_URI is not set")
    async with temp_postgres(uri) as uri_with_database_name:
        yield uri_with_database_name

async def _database_uri(scheme: str, tmp_path: Path) -> Generator[str, None, None]:
    if schema == "postgresql":
       url = await postgresql_uri()
       yield url
    else:
       yield f"{scheme}:///{tmp_path}/test.db"

@asyncio.fixture
async def adapter(tmp_path: Path, request: pytest.FixtureRequest) -> Generator[SQLAdapter, None, None]:
    database_params: tuple[str, int] = request.params
    uri = await database_uri(database_params[0], tmp_path)
    data_source = data_source_from_init_storage(uri, database_params[1])
    yield SQLAdapter(
        data_source.assets[0].data_uri,
        data_source.structure,
        data_source.parameters["table_name"],
        data_source.parameters["dataset_id"],
    )


@pytest.mark.parametrize(
    "adapter",
    [
        ("sqlite", 1),
        ("duckdb", 1),
        ("postgresql", 1),
    ],
   indirect=True
)
def test_write_read_one_batch_one_part(adapter: SQLAdapter) -> None:

And adapter_psql_many_partitions becomes ("postgresql", 3) etc.?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I just don't like the pattern of fetching the fixture inside the test, this way the skip is done before the first line of the test)

# By giving that a name ("_") we enable requests to asking for the
# last N by requesting the sorting ("_", -1).
sorting = [SortingItem(key="_", direction=1)]
sorting = [SortingItem(key="_", direction=SortingDirection.ASCENDING)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually work? Or as discussed, is the type hint wrong and the method works with what it was previously receiving?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants