-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add current_version_number to dataset status CLI output #965
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
Closed
+117
−3
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
|
|
||
| class TestDatasetStatus(unittest.TestCase): | ||
| def setUp(self): | ||
| self.api = self._create_api() | ||
|
|
||
| def _create_api(self): | ||
| with patch("kaggle.api.kaggle_api_extended.KaggleApi._read_config_file"): | ||
| from kaggle.api.kaggle_api_extended import KaggleApi | ||
|
|
||
| api = KaggleApi.__new__(KaggleApi) | ||
| api.already_printed_version_warning = True | ||
| api.config_values = {} | ||
| return api | ||
|
|
||
| def _mock_kaggle_client(self, status_name, current_version_number): | ||
| mock_kaggle = MagicMock() | ||
|
|
||
| # Mock get_dataset_status response | ||
| mock_status_response = MagicMock() | ||
| mock_status_response.status.name = status_name | ||
| mock_kaggle.datasets.dataset_api_client.get_dataset_status.return_value = mock_status_response | ||
|
|
||
| # Mock get_dataset response | ||
| mock_dataset_response = MagicMock() | ||
| mock_dataset_response.current_version_number = current_version_number | ||
| mock_kaggle.datasets.dataset_api_client.get_dataset.return_value = mock_dataset_response | ||
|
|
||
| return mock_kaggle | ||
|
|
||
| @patch("kaggle.api.kaggle_api_extended.KaggleApi.build_kaggle_client") | ||
| def test_dataset_status_returns_status_and_version(self, mock_build): | ||
| mock_kaggle = self._mock_kaggle_client("READY", 3) | ||
| mock_build.return_value.__enter__ = MagicMock(return_value=mock_kaggle) | ||
| mock_build.return_value.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| status, version = self.api.dataset_status("owner/dataset-name") | ||
|
|
||
| self.assertEqual(status, "ready") | ||
| self.assertEqual(version, 3) | ||
|
|
||
| @patch("kaggle.api.kaggle_api_extended.KaggleApi.build_kaggle_client") | ||
| def test_dataset_status_cli_formats_with_version(self, mock_build): | ||
| mock_kaggle = self._mock_kaggle_client("READY", 5) | ||
| mock_build.return_value.__enter__ = MagicMock(return_value=mock_kaggle) | ||
| mock_build.return_value.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| result = self.api.dataset_status_cli("owner/dataset-name") | ||
|
|
||
| self.assertEqual(result, "ready (version 5)") | ||
|
|
||
| @patch("kaggle.api.kaggle_api_extended.KaggleApi.build_kaggle_client") | ||
| def test_dataset_status_cli_pending(self, mock_build): | ||
| mock_kaggle = self._mock_kaggle_client("PENDING", 2) | ||
| mock_build.return_value.__enter__ = MagicMock(return_value=mock_kaggle) | ||
| mock_build.return_value.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| result = self.api.dataset_status_cli("owner/dataset-name") | ||
|
|
||
| self.assertEqual(result, "pending (version 2)") | ||
|
|
||
| @patch("kaggle.api.kaggle_api_extended.KaggleApi.build_kaggle_client") | ||
| def test_dataset_status_cli_version_none(self, mock_build): | ||
| mock_kaggle = self._mock_kaggle_client("READY", None) | ||
| mock_build.return_value.__enter__ = MagicMock(return_value=mock_kaggle) | ||
| mock_build.return_value.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| result = self.api.dataset_status_cli("owner/dataset-name") | ||
|
|
||
| self.assertEqual(result, "ready") | ||
|
|
||
| @patch("kaggle.api.kaggle_api_extended.KaggleApi.build_kaggle_client") | ||
| def test_dataset_status_cli_version_1(self, mock_build): | ||
| mock_kaggle = self._mock_kaggle_client("READY", 1) | ||
| mock_build.return_value.__enter__ = MagicMock(return_value=mock_kaggle) | ||
| mock_build.return_value.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| result = self.api.dataset_status_cli("owner/dataset-name") | ||
|
|
||
| self.assertEqual(result, "ready (version 1)") | ||
|
|
||
| @patch("kaggle.api.kaggle_api_extended.KaggleApi.build_kaggle_client") | ||
| def test_dataset_status_cli_uses_dataset_opt(self, mock_build): | ||
| mock_kaggle = self._mock_kaggle_client("READY", 3) | ||
| mock_build.return_value.__enter__ = MagicMock(return_value=mock_kaggle) | ||
| mock_build.return_value.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| result = self.api.dataset_status_cli(None, dataset_opt="owner/dataset-name") | ||
|
|
||
| self.assertEqual(result, "ready (version 3)") | ||
|
|
||
| def test_dataset_status_raises_on_none(self): | ||
| with self.assertRaises(ValueError): | ||
| self.api.dataset_status(None) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or 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
Oops, something went wrong.
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.
@rosbo This breaks backward-compatibility, doesn't it? Not for the CLI usage, but for notebooks that import the package. When I checked, there were tens of thousands of such notebooks, but I don't know how often they are used. And I don't know if any of them call
dataset_status().In general, breaking back-compat is not advised.
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.
I had marvin try to one-shot these, but lack enough context on the working of this code to know if it was a good solution. Based on my initial review it didn't look good.
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.
Agree with Steve. To avoid breaking script that parses this output, we could add a
--formatflag likegcloud: https://screenshot.googleplex.com/ganNtm4RhbYHWkSBy default, we would keep the text output with only the status.
But user could specify
--format=jsonand they would get the status AND the current version number in a json output.Optionally, we could support field selection like gcloud in the format flag:
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 — reverted.
dataset_status()now keeps its originalstrreturn type so notebooks/scripts importing the package are unaffected. The version-number behavior moved behind a new--formatflag at the CLI layer per @rosbo's suggestion.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.
Implemented the gcloud-style
--formatflag:--format=json: emits{"status": ..., "current_version_number": ...}.--format='json(current_version_number)'and--format='json(status,current_version_number)'for gcloud-style field selection.dataset_status()is back to returning juststr. The extraget_dataset()call to fetch the version number only runs when--formatrequests JSON, so we don't pay for it on the default path either. Tests intests/test_dataset_status.pycover the default path, JSON, field selection, and error cases.