Skip to content

Feat: add support for freezing time in unit tests#2362

Merged
georgesittas merged 10 commits intomainfrom
jo/freeze_time_tests
Mar 29, 2024
Merged

Feat: add support for freezing time in unit tests#2362
georgesittas merged 10 commits intomainfrom
jo/freeze_time_tests

Conversation

@georgesittas
Copy link
Copy Markdown
Collaborator

Addresses the 8th item in #1637

This seemed like a nice QOL feature to have in unit tests. The relevant Slack thread is: https://tobiko-data.slack.com/archives/C044BRE5W4S/p1711540655441619.

@georgesittas georgesittas requested review from a team and eakmanrq March 28, 2024 18:05
@georgesittas georgesittas force-pushed the jo/freeze_time_tests branch from 519a11d to f52bf74 Compare March 28, 2024 18:06
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TIL: nullcontext()

@georgesittas georgesittas force-pushed the jo/freeze_time_tests branch from 9e364c1 to 9d76349 Compare March 29, 2024 00:21
@georgesittas georgesittas requested a review from a team March 29, 2024 01:36

def _execute(self, query: exp.Expression) -> pd.DataFrame:
"""Executes the query with the engine adapter and returns a DataFrame."""
with patch.dict(self._engine_adapter_dialect.generator_class.TRANSFORMS, self._transforms):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does Dialect.get_or_raise(self.engine_adapter.dialect) return a global instance or a new one each time? If it's the latter, can't we just set transformers once and not patch it?

Copy link
Copy Markdown
Collaborator Author

@georgesittas georgesittas Mar 29, 2024

Choose a reason for hiding this comment

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

Unfortunately we can't do this, because TRANSFORMS is a class attribute and since generator classes are singletons we'd end up mutating dialects globally if we didn't patch it.

@georgesittas georgesittas merged commit 22781f5 into main Mar 29, 2024
@georgesittas georgesittas deleted the jo/freeze_time_tests branch March 29, 2024 23: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