Skip to content

Decouple transfer tests from GCS using local CSV fixtures#391

Merged
jirhiker merged 3 commits into
stagingfrom
remove-gcs-dependency-from-transfer-test
Jan 16, 2026
Merged

Decouple transfer tests from GCS using local CSV fixtures#391
jirhiker merged 3 commits into
stagingfrom
remove-gcs-dependency-from-transfer-test

Conversation

@jirhiker

Copy link
Copy Markdown
Member

Why

  • Remove GCS dependency from test_contact_with_multiple_wells by relying on local CSV fixtures.
  • Ensure anonymized fixture data stays internally consistent for owner links and contacts.

How

  • Added a base _read_csv in transferers and wired WellTransferer/ContactTransfer to honor CSV_PATHS, skipping GCS caches when local data is supplied.
  • Trimmed fixture CSVs (Location.csv, WellData.csv) and aligned OwnerLink.csv/OwnersData.csv keys to match anonymized owners.
  • Normalized contact email/phone handling in transfers/contact_transfer.py to safely coerce non-string values.

Notes

  • test_contact_with_multiple_wells passes using only local CSVs; transfer logs still show existing warnings from validation and unknown formations.

Tests

  • source .venv/bin/activate && set -a && source .env && set +a && pytest tests/transfers/test_contact_with_multiple_wells.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the GCS (Google Cloud Storage) dependency from transfer tests by enabling the use of local CSV fixtures instead. The changes allow test_contact_with_multiple_wells to run entirely on local data, improving test isolation and eliminating external dependencies.

Changes:

  • Added _read_csv method to the base Transferer class that respects CSV_PATHS flag for local file loading
  • Updated WellTransferer and ContactTransfer to use _read_csv instead of direct read_csv calls
  • Enhanced _make_email and _make_phone to handle non-string values safely by coercing to strings before stripping

Reviewed changes

Copilot reviewed 4 out of 8 changed files in this pull request and generated 2 comments.

File Description
transfers/transferer.py Added base _read_csv method that checks CSV_PATHS flag and falls back to GCS
transfers/well_transfer.py Updated to use _read_csv and conditionally initialize cached elevations based on CSV_PATHS flag
transfers/contact_transfer.py Updated to use _read_csv and added null/type safety for email and phone processing
tests/transfers/test_contact_with_multiple_wells.py Modified test to use local CSV fixtures via CSV_PATHS flag instead of GCS

Comment thread transfers/contact_transfer.py Outdated
Comment on lines +222 to +225
if self.flags.get("CSV_PATHS"):
self._cached_elevations = {}
else:
self._cached_elevations = get_cached_elevations()

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

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

The conditional initialization of _cached_elevations lacks an explanatory comment. It's not immediately clear why CSV_PATHS disables cached elevations. Consider adding a comment explaining that local CSV mode bypasses the GCS elevation cache to avoid external dependencies during testing.

Copilot uses AI. Check for mistakes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9de4f1ac88

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread transfers/well_transfer.py Outdated
Comment on lines +1596 to +1597

input_df = read_csv(self.source_table, self.source_dtypes)
input_df = self._read_csv(self.source_table, self.source_dtypes)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Pass dtype as keyword in _read_csv call

When CSV_PATHS is used, _read_csv routes through pd.read_csv, so the positional self.source_dtypes here is interpreted as the sep argument instead of dtype. For chunk transferers that set source_dtypes to a dict (e.g., LinkIdsWellDataTransferer), this will raise a delimiter error or parse the CSV incorrectly, which breaks any local-fixture run with CSV_PATHS. Pass dtype=self.source_dtypes (or update _read_csv to accept a dtype parameter explicitly) to keep local CSVs readable.

Useful? React with 👍 / 👎.

Comment on lines 220 to +224
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self._cached_elevations = get_cached_elevations()
if self.flags.get("CSV_PATHS"):
self._cached_elevations = {}
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid overwriting cached elevations when CSV_PATHS is set

With CSV_PATHS enabled, _cached_elevations is now initialized as an empty dict, but WellTransferer._after_hook still unconditionally calls dump_cached_elevations to GCS. This means a local/fixture run will overwrite the shared cached_elevations.json with only the subset encountered in the fixture (or fail if GCS credentials are unavailable), which defeats the goal of decoupling tests from GCS and can corrupt the cache used by other runs. Consider skipping the dump or merging with the existing cache when CSV_PATHS is set.

Useful? React with 👍 / 👎.

@kblake kblake left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 16, 2026 04:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 8 changed files in this pull request and generated 2 comments.

Comment on lines +222 to +225
if self.flags.get("CSV_PATHS"):
self._cached_elevations = {}
else:
self._cached_elevations = get_cached_elevations()

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

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

The conditional initialization of _cached_elevations creates two different behaviors based on the CSV_PATHS flag. When using local CSVs, the empty dictionary bypasses elevation caching entirely. Consider adding a comment explaining why elevation caching is disabled for local CSV paths, or ensure that the elevation logic properly handles the empty cache case without attempting GCS operations.

Copilot uses AI. Check for mistakes.
"first",
row.OwnerKey,
email=row.Email.strip(),
email=str(row.Email).strip() if row.Email is not None else None,

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

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

The inline type coercion and null check could be simplified by extracting this logic into a helper function, especially since similar patterns appear in _make_email and _make_phone. This would improve consistency and reduce duplication across the codebase.

Copilot uses AI. Check for mistakes.
@jirhiker jirhiker merged commit 2f97980 into staging Jan 16, 2026
6 checks passed
@TylerAdamMartinez TylerAdamMartinez deleted the remove-gcs-dependency-from-transfer-test branch February 26, 2026 18:26
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