Add unit tests for data models with factory methods - #3
Conversation
Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
- Changed imports from individual module imports to unified pattern: `from enapter_mcp_server.mcp import models` - Removed 7 trivial "creation" tests that only verified basic object instantiation - Updated Makefile to include coverage reporting in test-unit target - All 65 tests pass with 100% coverage on model files Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
- Updated all test files to use `from enapter_mcp_server.mcp import models` pattern - Removed all tests that only verify object instantiation without factory methods - Kept only tests for factory methods (from_domain, from_dto, from_manifest) and behavior validation - Test count: 48 tests (down from 65, removed 17 instantiation-only tests) Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
- Deleted all enum test files (no logic in enums, just stdlib) - Deleted DeviceContext and SiteContext tests (no logic to test) - Deleted HistoricalTelemetry tests (no factory methods) - Removed instantiation-only tests from remaining files - Fixed import: changed `from unittest.mock import Mock` to `from unittest import mock` - Kept only tests for factory methods (from_domain, from_dto, from_manifest) - Test count: 13 tests (down from 48) Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
rnovatorov
left a comment
There was a problem hiding this comment.
It's much better now, but some changes are still needed.
- Replaced unittest.mock.Mock with actual enapter.http.api dataclasses in tests - Updated test_device.py to use enapter.http.api.devices.Device - Updated test_site.py to use enapter.http.api.sites.Site - Fixed Makefile test-unit target to include --cov --cov-report term-missing - All 13 tests passing with 100% coverage on model factory methods Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
rnovatorov
left a comment
There was a problem hiding this comment.
Fixes of enapter SDK import statements required.
- Changed 'import enapter.http.api.devices' to 'import enapter' in test_device.py - Changed 'import enapter.http.api.sites' to 'import enapter' in test_site.py - Matches the import style used in source files - All 13 tests passing Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
rnovatorov
left a comment
There was a problem hiding this comment.
@copilot, just one more thing. I see two approaches to testing results of factory method calls:
- Compare each attribute as you did. (
assert alert.name == "low_pressure") - Compare the resulting model objects (
assert alert == models.Alert(...)).
Could you compare two approaches and describe their cons and pros and explain why you chose the current approach?
Comparison of Testing ApproachesApproach 1: Individual attribute assertions (current) assert alert.name == "low_pressure"
assert alert.display_name == "Low Pressure Alert"
assert alert.severity == models.AlertSeverity.ERRORPros:
Cons:
Approach 2: Object comparison assert alert == models.AlertDeclaration(
name="low_pressure",
display_name="Low Pressure Alert",
severity=models.AlertSeverity.ERROR,
...
)Pros:
Cons:
Why I chose Approach 1: For factory method tests, the primary goal is to verify that the transformation logic works correctly - i.e., that the factory method correctly maps from domain objects or DTOs to the model. Individual attribute assertions make it immediately clear which transformation failed, which is crucial for debugging. Since these models use Pydantic, |
* Initial plan * Add comprehensive unit tests for data models Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> * Refactor test imports and remove nonsense creation tests Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> * Refactor test imports and remove trivial creation tests - Changed imports from individual module imports to unified pattern: `from enapter_mcp_server.mcp import models` - Removed 7 trivial "creation" tests that only verified basic object instantiation - Updated Makefile to include coverage reporting in test-unit target - All 65 tests pass with 100% coverage on model files Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> * Fix imports and remove all instantiation tests - Updated all test files to use `from enapter_mcp_server.mcp import models` pattern - Removed all tests that only verify object instantiation without factory methods - Kept only tests for factory methods (from_domain, from_dto, from_manifest) and behavior validation - Test count: 48 tests (down from 65, removed 17 instantiation-only tests) Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> * Remove tests without actual logic to test - Deleted all enum test files (no logic in enums, just stdlib) - Deleted DeviceContext and SiteContext tests (no logic to test) - Deleted HistoricalTelemetry tests (no factory methods) - Removed instantiation-only tests from remaining files - Fixed import: changed `from unittest.mock import Mock` to `from unittest import mock` - Kept only tests for factory methods (from_domain, from_dto, from_manifest) - Test count: 13 tests (down from 48) Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> * Use real enapter dataclasses instead of mocks and add coverage - Replaced unittest.mock.Mock with actual enapter.http.api dataclasses in tests - Updated test_device.py to use enapter.http.api.devices.Device - Updated test_site.py to use enapter.http.api.sites.Site - Fixed Makefile test-unit target to include --cov --cov-report term-missing - All 13 tests passing with 100% coverage on model factory methods Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> * Use 'import enapter' instead of specific submodule imports - Changed 'import enapter.http.api.devices' to 'import enapter' in test_device.py - Changed 'import enapter.http.api.sites' to 'import enapter' in test_site.py - Matches the import style used in source files - All 13 tests passing Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
from enapter_mcp_server.mcp import modelsimport enapter(consistent with source files)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.