-
Notifications
You must be signed in to change notification settings - Fork 83
Improving test coverage and adding coverage reporting script #451
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
ba6a9ff
Expanding test coverage and fixing a few bugs
rodrigobr-msft 20935f2
Another commit
rodrigobr-msft 0fd4fff
Adding coverage dev utility
rodrigobr-msft 60746bd
Modifying coverage script
rodrigobr-msft b94ba21
Merge branch 'main' into users/robrandao/test-coverage
rodrigobr-msft 24fb69f
Potential fix for pull request finding
rodrigobr-msft 2253de4
Potential fix for pull request finding
rodrigobr-msft 34363e6
Potential fix for pull request finding
rodrigobr-msft 913c4f2
Potential fix for pull request finding
rodrigobr-msft 534af0a
Potential fix for pull request finding
rodrigobr-msft c23432f
Merge branch 'main' into users/robrandao/test-coverage
kylerohn-msft 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [run] | ||
| omit = | ||
| */microsoft-agents-testing/* | ||
|
rodrigobr-msft marked this conversation as resolved.
|
||
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
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,2 @@ | ||
| python -m coverage run --source=microsoft_agents -m pytest | ||
| python -m coverage html |
Empty file.
File renamed without changes.
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,82 @@ | ||
| import pytest | ||
| from pydantic import ValidationError | ||
|
|
||
| from microsoft_agents.activity.entity import Entity | ||
|
|
||
|
|
||
| def test_entity_requires_type(): | ||
| with pytest.raises(ValidationError): | ||
| Entity() | ||
|
|
||
|
|
||
| def test_entity_additional_properties_returns_extra_fields(): | ||
| entity = Entity(type="custom", custom_value="value", count=1) | ||
|
|
||
| assert entity.additional_properties == { | ||
| "custom_value": "value", | ||
| "count": 1, | ||
| } | ||
|
|
||
|
|
||
| def test_entity_validates_camel_case_extra_fields_as_snake_case(): | ||
| entity = Entity.model_validate( | ||
| { | ||
| "type": "custom", | ||
| "customValue": "value", | ||
| } | ||
| ) | ||
|
|
||
| assert entity.additional_properties == {"custom_value": "value"} | ||
| assert entity.model_dump(by_alias=True) == { | ||
| "type": "custom", | ||
| "customValue": "value", | ||
| } | ||
| assert entity.model_dump(by_alias=False) == { | ||
| "type": "custom", | ||
| "custom_value": "value", | ||
| } | ||
|
|
||
|
|
||
| def test_entity_serialization_always_includes_type(): | ||
| entity = Entity(type="custom") | ||
|
|
||
| assert entity.model_dump(exclude_unset=True) == {"type": "custom"} | ||
| assert entity.model_dump(exclude_none=True) == {"type": "custom"} | ||
|
|
||
|
|
||
| def test_entity_preserves_schema_at_fields_when_serializing_by_alias(): | ||
| entity = Entity.model_validate( | ||
| { | ||
| "type": "custom", | ||
| "@type": "schema-type", | ||
| "@context": "https://schema.org", | ||
| "@id": "schema-id", | ||
| } | ||
| ) | ||
|
|
||
| assert entity.additional_properties == { | ||
| "@type": "schema-type", | ||
| "@context": "https://schema.org", | ||
| "@id": "schema-id", | ||
| "at_type": "schema-type", | ||
| "at_context": "https://schema.org", | ||
| "at_id": "schema-id", | ||
| } | ||
| assert entity.model_dump(by_alias=True) == { | ||
| "type": "custom", | ||
| "@type": "schema-type", | ||
| "@context": "https://schema.org", | ||
| "@id": "schema-id", | ||
| "atType": "schema-type", | ||
| "atContext": "https://schema.org", | ||
| "atId": "schema-id", | ||
| } | ||
| assert entity.model_dump(by_alias=False) == { | ||
| "type": "custom", | ||
| "@type": "schema-type", | ||
| "@context": "https://schema.org", | ||
| "@id": "schema-id", | ||
| "at_type": "schema-type", | ||
| "at_context": "https://schema.org", | ||
| "at_id": "schema-id", | ||
| } |
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,58 @@ | ||
| from uuid import UUID | ||
|
|
||
| import pytest | ||
| from pydantic import ValidationError | ||
|
|
||
| from microsoft_agents.activity import ( | ||
| ActivityEventNames, | ||
| ActivityTypes, | ||
| ChannelAccount, | ||
| ConversationAccount, | ||
| ConversationReference, | ||
| ) | ||
|
|
||
|
|
||
| def _create_conversation_reference(user: ChannelAccount | None = None): | ||
| return ConversationReference( | ||
| activity_id="activity-123", | ||
| channel_id="msteams", | ||
| service_url="https://smba.trafficmanager.net/teams/", | ||
| conversation=ConversationAccount(id="conversation-123", name="Test Chat"), | ||
| user=user if user is not None else ChannelAccount(id="user-123", name="User"), | ||
| agent=ChannelAccount(id="agent-123", name="Agent"), | ||
| locale="en-US", | ||
| ) | ||
|
|
||
|
|
||
| def test_get_continuation_activity_sets_expected_fields(): | ||
| conversation_reference = _create_conversation_reference() | ||
|
|
||
| continuation_activity = conversation_reference.get_continuation_activity() | ||
|
|
||
| UUID(continuation_activity.id) | ||
| assert continuation_activity.id != conversation_reference.activity_id | ||
| assert continuation_activity.type == ActivityTypes.event | ||
| assert continuation_activity.name == ActivityEventNames.continue_conversation | ||
| assert continuation_activity.channel_id == conversation_reference.channel_id | ||
| assert continuation_activity.service_url == conversation_reference.service_url | ||
| assert continuation_activity.conversation == conversation_reference.conversation | ||
| assert continuation_activity.recipient == conversation_reference.agent | ||
| assert continuation_activity.from_property == conversation_reference.user | ||
| assert continuation_activity.relates_to == conversation_reference | ||
|
|
||
|
|
||
| def test_get_continuation_activity_generates_new_id_each_time(): | ||
| conversation_reference = _create_conversation_reference() | ||
|
|
||
| first_activity = conversation_reference.get_continuation_activity() | ||
| second_activity = conversation_reference.get_continuation_activity() | ||
|
|
||
| assert first_activity.id != second_activity.id | ||
|
|
||
|
|
||
| def test_get_continuation_activity_raises_when_user_is_missing(): | ||
| conversation_reference = _create_conversation_reference(user=None) | ||
| conversation_reference.user = None | ||
|
|
||
| with pytest.raises(ValidationError): | ||
| conversation_reference.get_continuation_activity() |
Oops, something went wrong.
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.