-
Notifications
You must be signed in to change notification settings - Fork 4
アノテーションクラスの領域数上限をSDKから指定できるようにする #288
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
88eba82
アノテーションクラス作成で領域数上限を指定できるようにした
soymd bd6216d
アノテーションクラス更新で領域数上限を変更できるようにした
soymd bcb88fd
領域数上限の有効範囲をREADMEに明記した
soymd b098470
アノテーションクラス作成でmax_area_count未指定時はリクエストに含めないようにした
soymd d1efbf8
センチネルの判定をisinstanceから同一性比較に変えた
soymd 1aa65b6
テストのclient fixtureとリクエスト記録ヘルパーをconftestへ移した
soymd 961462d
センチネルの型注釈を調整して公開シグネチャから内部クラスを隠した
soymd f6a5497
未指定マーカーをシングルトンにしてコピーやシリアライズを跨いでも同一性が保たれるようにした
soymd a990f6b
未指定マーカーを使う理由を呼び出し箇所とマーカー定義にコメントで書いた
soymd 8b77875
アノテーションクラスの領域数上限 未指定マーカーの意図を日本語で具体的に書き直した
soymd fb6b53d
アノテーションクラスの領域数上限 未指定マーカーの説明を英語に戻した
soymd 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
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,119 @@ | ||
| """Tests for the annotation class API client methods. | ||
|
|
||
| These verify that create_annotation and update_annotation build the correct | ||
| endpoint and payload, with a focus on max_area_count. The HTTP layer | ||
| (client.api.*_request) is stubbed so no real request is made. | ||
| """ | ||
|
|
||
| import copy | ||
| import pickle | ||
|
|
||
| import pytest | ||
|
|
||
| import fastlabel | ||
|
|
||
| # --- create_annotation ----------------------------------------------------- | ||
|
|
||
|
|
||
| def test_create_annotation_omits_max_area_count_by_default(client, capture_request): | ||
| calls = capture_request(client, "post_request", return_value="anno-id") | ||
|
|
||
| client.create_annotation( | ||
| project="my-project", type="segmentation", value="cat", title="Cat" | ||
| ) | ||
|
|
||
| # The field is left out entirely so the API applies its own default of 1 | ||
| assert calls[0]["endpoint"] == "annotations" | ||
| assert calls[0]["kwargs"]["payload"] == { | ||
| "project": "my-project", | ||
| "type": "segmentation", | ||
| "value": "cat", | ||
| "title": "Cat", | ||
| } | ||
|
|
||
|
|
||
| def test_create_annotation_with_max_area_count(client, capture_request): | ||
| calls = capture_request(client, "post_request", return_value="anno-id") | ||
|
|
||
| client.create_annotation( | ||
| project="my-project", | ||
| type="segmentation", | ||
| value="cat", | ||
| title="Cat", | ||
| max_area_count=10, | ||
| ) | ||
|
|
||
| assert calls[0]["kwargs"]["payload"]["maxAreaCount"] == 10 | ||
|
|
||
|
|
||
| def test_create_annotation_without_max_area_count_limit(client, capture_request): | ||
| calls = capture_request(client, "post_request", return_value="anno-id") | ||
|
|
||
| client.create_annotation( | ||
| project="my-project", | ||
| type="segmentation", | ||
| value="cat", | ||
| title="Cat", | ||
| max_area_count=None, | ||
| ) | ||
|
|
||
| # None is sent as an explicit null, which means no limit on the server side | ||
| assert calls[0]["kwargs"]["payload"]["maxAreaCount"] is None | ||
|
|
||
|
|
||
| # --- update_annotation ----------------------------------------------------- | ||
|
|
||
|
|
||
| def test_update_annotation_omits_max_area_count_by_default(client, capture_request): | ||
| calls = capture_request(client, "put_request", return_value="anno-id") | ||
|
|
||
| client.update_annotation(annotation_id="anno-id", title="Cat") | ||
|
|
||
| assert calls[0]["endpoint"] == "annotations/anno-id" | ||
| assert calls[0]["kwargs"]["payload"] == {"title": "Cat"} | ||
|
|
||
|
|
||
| def test_update_annotation_with_max_area_count(client, capture_request): | ||
| calls = capture_request(client, "put_request", return_value="anno-id") | ||
|
|
||
| client.update_annotation(annotation_id="anno-id", max_area_count=10) | ||
|
|
||
| assert calls[0]["kwargs"]["payload"] == {"maxAreaCount": 10} | ||
|
|
||
|
|
||
| def test_update_annotation_without_max_area_count_limit(client, capture_request): | ||
| calls = capture_request(client, "put_request", return_value="anno-id") | ||
|
|
||
| client.update_annotation(annotation_id="anno-id", max_area_count=None) | ||
|
|
||
| # None is sent as an explicit null, which means no limit on the server side | ||
| assert calls[0]["kwargs"]["payload"] == {"maxAreaCount": None} | ||
|
|
||
|
|
||
| # --- the "not passed" marker ----------------------------------------------- | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "round_trip", | ||
| [copy.deepcopy, lambda value: pickle.loads(pickle.dumps(value))], | ||
| ids=["deepcopy", "pickle"], | ||
| ) | ||
| def test_create_annotation_keeps_marker_meaning_after_round_trip( | ||
| client, capture_request, round_trip | ||
| ): | ||
| calls = capture_request(client, "post_request", return_value="anno-id") | ||
|
|
||
| # Callers that collect keyword arguments and pass them around must still | ||
| # get "omitted" out of the default, which relies on the marker's identity | ||
| kwargs = round_trip( | ||
| { | ||
| "project": "my-project", | ||
| "type": "segmentation", | ||
| "value": "cat", | ||
| "title": "Cat", | ||
| "max_area_count": fastlabel._UNSET, | ||
| } | ||
| ) | ||
| client.create_annotation(**kwargs) | ||
|
|
||
| assert "maxAreaCount" not in calls[0]["kwargs"]["payload"] |
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.
Uh oh!
There was an error while loading. Please reload this page.