-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add support for overriding context.engine
by magic argument
#60
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ def mock_credentials(monkeypatch): | |
|
||
|
||
@pytest.fixture | ||
def bigframes_engine(monkeypatch): | ||
def set_bigframes_engine_in_context(monkeypatch): | ||
monkeypatch.setattr(bigquery_magics.context, "engine", "bigframes") | ||
|
||
|
||
|
@@ -1896,8 +1896,20 @@ def test_bigquery_magic_with_location(): | |
assert client_options_used.location == "us-east1" | ||
|
||
|
||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials", "bigframes_engine") | ||
def test_big_query_magic_bigframes(): | ||
@pytest.mark.usefixtures("ipython_interactive") | ||
def test_bigquery_magic_with_invalid_engine_raises_error(): | ||
ip = IPython.get_ipython() | ||
ip.extension_manager.load_extension("bigquery_magics") | ||
engine = "whatever" | ||
|
||
with pytest.raises(ValueError, match=f"Invalid engine: {engine}"): | ||
ip.run_cell_magic("bigquery", f"--engine {engine}", "SELECT 17 AS num") | ||
|
||
|
||
@pytest.mark.usefixtures( | ||
"ipython_interactive", "mock_credentials", "set_bigframes_engine_in_context" | ||
) | ||
def test_big_query_magic_bigframes_set_in_context(): | ||
if bpd is None: | ||
pytest.skip("BigFrames not installed") | ||
|
||
|
@@ -1920,7 +1932,33 @@ def test_big_query_magic_bigframes(): | |
assert bpd.options.bigquery.project == bigquery_magics.context.project | ||
|
||
|
||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials", "bigframes_engine") | ||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials") | ||
def test_big_query_magic_bigframes_set_in_args(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: big_query -> bigquery There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Updated the name here and for other methods too. |
||
if bpd is None: | ||
pytest.skip("BigFrames not installed") | ||
|
||
ip = IPython.get_ipython() | ||
ip.extension_manager.load_extension("bigquery_magics") | ||
sql = "SELECT 0 AS something" | ||
expected_configuration = { | ||
"query": {"queryParameters": [], "useLegacySql": False}, | ||
"dryRun": False, | ||
} | ||
bf_patch = mock.patch("bigframes.pandas.read_gbq_query", autospec=True) | ||
|
||
with bf_patch as bf_mock: | ||
ip.run_cell_magic("bigquery", "--engine bigframes", sql) | ||
|
||
bf_mock.assert_called_once_with( | ||
sql, max_results=None, configuration=expected_configuration | ||
) | ||
assert bpd.options.bigquery.credentials is bigquery_magics.context.credentials | ||
assert bpd.options.bigquery.project == bigquery_magics.context.project | ||
|
||
|
||
@pytest.mark.usefixtures( | ||
"ipython_interactive", "mock_credentials", "set_bigframes_engine_in_context" | ||
) | ||
def test_big_query_magic_bigframes__bigframes_is_not_installed__should_raise_error(): | ||
if bpd is not None: | ||
pytest.skip("BigFrames is installed") | ||
|
@@ -1933,7 +1971,9 @@ def test_big_query_magic_bigframes__bigframes_is_not_installed__should_raise_err | |
ip.run_cell_magic("bigquery", "", sql) | ||
|
||
|
||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials", "bigframes_engine") | ||
@pytest.mark.usefixtures( | ||
"ipython_interactive", "mock_credentials", "set_bigframes_engine_in_context" | ||
) | ||
def test_big_query_magic_bigframes_with_params(): | ||
if bpd is None: | ||
pytest.skip("BigFrames not installed") | ||
|
@@ -1965,7 +2005,9 @@ def test_big_query_magic_bigframes_with_params(): | |
) | ||
|
||
|
||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials", "bigframes_engine") | ||
@pytest.mark.usefixtures( | ||
"ipython_interactive", "mock_credentials", "set_bigframes_engine_in_context" | ||
) | ||
def test_big_query_magic_bigframes_with_max_results(): | ||
if bpd is None: | ||
pytest.skip("BigFrames not installed") | ||
|
@@ -1987,7 +2029,9 @@ def test_big_query_magic_bigframes_with_max_results(): | |
) | ||
|
||
|
||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials", "bigframes_engine") | ||
@pytest.mark.usefixtures( | ||
"ipython_interactive", "mock_credentials", "set_bigframes_engine_in_context" | ||
) | ||
def test_big_query_magic_bigframes_with_destination_var(ipython_ns_cleanup): | ||
if bpd is None: | ||
pytest.skip("BigFrames not installed") | ||
|
@@ -2007,7 +2051,9 @@ def test_big_query_magic_bigframes_with_destination_var(ipython_ns_cleanup): | |
assert df is bf_mock.return_value | ||
|
||
|
||
@pytest.mark.usefixtures("ipython_interactive", "mock_credentials", "bigframes_engine") | ||
@pytest.mark.usefixtures( | ||
"ipython_interactive", "mock_credentials", "set_bigframes_engine_in_context" | ||
) | ||
def test_big_query_magic_bigframes_with_dry_run__should_fail(): | ||
if bpd is None: | ||
pytest.skip("BigFrames not installed") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name feels off to me. Like it would be a boolean but it's not. How about
engine_or_default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I named it simply"engine"