Skip to content

fix: locally running tests errors #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025
Merged

fix: locally running tests errors #459

merged 3 commits into from
Apr 8, 2025

Conversation

maxi297
Copy link
Contributor

@maxi297 maxi297 commented Apr 4, 2025

Context

I had two tests issues:

  • test_macros.test_format_datetime is using the timezone of your computer. In order to fix that, I'm forcing utc. This shouldn't change the behavior of the connector because we for UTC as a timezone for the docker images
  • For whatever reason when running unit_tests not on the root level, pkgutil raise a value error during schema loading instead of a OSError (see blob below). In order to fix that, I handled both errors the same way. This would change the sources behavior only if we were to fail on ValueError before which I doubt it is a case and find the fallback appropriate anyway. Note that this seems to happen only when not running tests from unit_tests directly but running a more scope set of tests. Trying to change the working directory didn't help unfortunately...
Traceback (most recent call last):
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/connector_builder/test_reader/reader.py", line 389, in _read_stream
    yield from AirbyteEntrypoint(source).read(
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/entrypoint.py", line 244, in read
    for message in self.source.read(self.logger, config, catalog, state):
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/sources/declarative/concurrent_declarative_source.py", line 138, in read
    concurrent_streams, _ = self._group_streams(config=config)
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/sources/declarative/concurrent_declarative_source.py", line 333, in _group_streams
    declarative_stream.get_json_schema(),
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/sources/declarative/declarative_stream.py", line 170, in get_json_schema
    return self._schema_loader.get_json_schema()
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/sources/declarative/schema/default_schema_loader.py", line 39, in get_json_schema
    return self.default_loader.get_json_schema()
  File "/Users/maxime/devel/code/airbyte-python-cdk/airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py", line 58, in get_json_schema
    raw_json_file = pkgutil.get_data(resource, schema_path)
  File "/Users/maxime/.pyenv/versions/3.10.14/lib/python3.10/pkgutil.py", line 621, in get_data
    spec = importlib.util.find_spec(package)
  File "/Users/maxime/.pyenv/versions/3.10.14/lib/python3.10/importlib/util.py", line 103, in find_spec
    return _find_spec(fullname, parent_path)
  File "<frozen importlib._bootstrap>", line 945, in _find_spec
  File "/Users/maxime/devel/code/airbyte-python-cdk/.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 110, in find_spec
    if self._early_rewrite_bailout(name, state):
  File "/Users/maxime/devel/code/airbyte-python-cdk/.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 211, in _early_rewrite_bailout
    path = PurePath(*parts).with_suffix(".py")
  File "/Users/maxime/.pyenv/versions/3.10.14/lib/python3.10/pathlib.py", line 782, in with_suffix
    raise ValueError("%r has an empty name" % (self,))
ValueError: PurePosixPath('.') has an empty name

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved datetime consistency so that all timestamps are now uniformly displayed in UTC.
    • Enhanced error resilience during configuration retrieval by expanding error handling to include additional exception types, resulting in a more robust experience.
  • Tests

    • Added new test cases to ensure proper formatting of datetime objects with and without timezone information.
@Copilot Copilot AI review requested due to automatic review settings April 4, 2025 19:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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

Comments suppressed due to low confidence (2)

airbyte_cdk/sources/declarative/schema/default_schema_loader.py:40

  • Consider adding an inline comment to explain why ValueError is handled here, referencing the specific behavior of pkgutil that leads to this exception.
except (OSError, ValueError):

airbyte_cdk/sources/declarative/interpolation/macros.py:180

  • [nitpick] Include a clarifying comment noting that the timezone is being forced to UTC to match Docker image settings, ensuring consistent test outcomes.
dt_datetime = dt_datetime.replace(tzinfo=pytz.utc)
@github-actions github-actions bot added bug Something isn't working security labels Apr 4, 2025
Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

📝 Walkthrough

Walkthrough

The pull request introduces modifications to two components. In the format_datetime function, a conditional check is added to set the timezone of dt_datetime to UTC using pytz, ensuring consistent UTC output. Additionally, in the DefaultSchemaLoader class, the get_json_schema method is updated to catch both OSError and ValueError exceptions, enhancing error handling during schema loading without changing the subsequent logic.

Changes

File Change Summary
airbyte_cdk/.../interpolation/macros.py In the format_datetime function, added dt_datetime = dt_datetime.replace(tzinfo=pytz.utc) to ensure the datetime is explicitly set to UTC.
airbyte_cdk/.../schema/default_schema_loader.py Modified the get_json_schema method to catch both OSError and ValueError, expanding the scope of exception handling during schema retrieval.

Suggested reviewers

  • darynaishchenko
  • aaronsteers

Would you like to consider any additional reviewers or labels, wdyt?


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8bcc43c and e311c73.

📒 Files selected for processing (1)
  • unit_tests/sources/declarative/interpolation/test_macros.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
unit_tests/sources/declarative/interpolation/test_macros.py (2)

104-115: Well-designed test cases! Looking good.

These test cases effectively address the timezone issue mentioned in the PR objectives. The first case verifies correct UTC conversion for an input with timezone information, while the second ensures that inputs without timezone info are properly handled as UTC. This helps make tests consistent regardless of local machine settings.


132-133: Nice descriptive test IDs!

The test IDs clearly communicate the purpose of each test case - handling datetimes with timezone information and inferring UTC when no timezone is provided. This makes the test intentions very clear for future maintainers.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
Copy link
Contributor

@aaronsteers aaronsteers left a comment

Choose a reason for hiding this comment

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

I think we probably need to check for a set timezone before applying utc. Proposed a solution. (Feel free to dismiss this review after resolved/addressed.)

maxi297 and others added 2 commits April 8, 2025 10:17
Copy link
Contributor

@aldogonzalez8 aldogonzalez8 left a comment

Choose a reason for hiding this comment

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

APPROVED

Copy link
Contributor

@aaronsteers aaronsteers left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@maxi297 maxi297 merged commit 5366b13 into main Apr 8, 2025
26 checks passed
@maxi297 maxi297 deleted the maxi297/fix-tests branch April 8, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working security
3 participants