test: unit tests for get_package and get_partitions methods#56
Conversation
Iterate through all packages declared in the project file and create a deb file for each file, adding proper control metadata to each one. Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Co-authored-by: cmatsuoka <317355+cmatsuoka@users.noreply.github.com>
Co-authored-by: cmatsuoka <317355+cmatsuoka@users.noreply.github.com>
|
We can land this directly on main after landing #54 |
There was a problem hiding this comment.
Pull request overview
This PR adds unit test coverage for two methods in project models: Project.get_package() and PackagesProject.get_partitions(), addressing review feedback from a previous PR (#54).
- Tests for successful package retrieval and error cases (no packages, package not found)
- Tests for partition generation with and without packages defined
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert result is not None | ||
| assert "default" in result | ||
| assert "package/pkg-a" in result | ||
| assert "package/pkg-b" in result | ||
| assert len(result) == 3 |
There was a problem hiding this comment.
The test uses multiple assertions to verify the result instead of a single comprehensive assertion. Since get_partitions() returns a deterministic list, use a single assertion comparing the full result. Replace lines 131-135 with: assert result == [\"default\", \"package/pkg-a\", \"package/pkg-b\"]. This is clearer, more maintainable, and catches ordering issues.
| assert result is not None | |
| assert "default" in result | |
| assert "package/pkg-a" in result | |
| assert "package/pkg-b" in result | |
| assert len(result) == 3 | |
| assert result == ["default", "package/pkg-a", "package/pkg-b"] |
| } | ||
| ) | ||
| result = packages_project.get_partitions() | ||
| assert result is not None |
There was a problem hiding this comment.
This assertion is redundant. The get_partitions() method always returns a list (either [\"default\"] or a list with packages), never None. The return type annotation list[str] | None appears to allow None, but examining the implementation shows it always returns a list. This check can be removed.
| assert result is not None |
| def test_get_package_success(default_project): | ||
| """Test that get_package returns the correct package.""" | ||
| package = default_project.get_package("package-1") | ||
| assert package is not None |
There was a problem hiding this comment.
This assertion is redundant. The get_package() method either returns a Package or raises an exception, so it can never return None. Line 91 already verifies the package content by checking the version. Remove this assertion.
| assert package is not None |
|
@copilot rebase this on main. |
Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
I'm unable to perform git rebase operations as I don't have access to force push. Could you please rebase this branch on main? |
make lint && make test?Addresses review feedback from #54 requesting unit test coverage for the new
get_packageandget_partitionsmethods in project models.Changes
Added tests for
Project.get_package():Added tests for
PackagesProject.get_partitions():["default"]when no packages defined["default", "package/<name>", ...]when packages defined💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.