Add 55 tests for deps/_utils.py and view.py coverage#682
Add 55 tests for deps/_utils.py and view.py coverage#682
Conversation
- 43 tests for commands/deps/_utils.py: _is_nested_under_package, _count_primitives, _count_package_files, _count_workflows, _get_detailed_context_counts, _get_package_display_info, _get_detailed_package_info, _scan_installed_packages - 12 tests for commands/view.py: _lookup_lockfile_ref (6 tests), --global flag, context/workflow/hook display, lockfile ref display - All 3877 tests pass Agent-Logs-Url: https://github.com/microsoft/apm/sessions/1c34cfd0-85c8-4350-a475-0395a41f0707 Co-authored-by: sergio-sisternes-epam <207026618+sergio-sisternes-epam@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/apm/sessions/1c34cfd0-85c8-4350-a475-0395a41f0707 Co-authored-by: sergio-sisternes-epam <207026618+sergio-sisternes-epam@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds targeted unit test coverage for dependency utility helpers and the apm view command to improve confidence in filesystem scanning/counting and lockfile-ref rendering.
Changes:
- Added a new
tests/unit/test_deps_utils.pysuite coveringapm_cli.commands.deps._utilshelpers and edge cases. - Expanded
tests/unit/test_view_command.pywith additional CLI scenarios and direct unit tests for_lookup_lockfile_ref.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/unit/test_deps_utils.py | New unit tests for deps utility helpers (scan/count/metadata error paths). |
| tests/unit/test_view_command.py | Additional apm view CLI coverage + focused unit tests for lockfile ref lookup. |
| fake_home = Path(tempfile.mkdtemp()) | ||
| pkg_dir = fake_home / "apm_modules" / "gorg" / "grepo" | ||
| pkg_dir.mkdir(parents=True) | ||
| (pkg_dir / "apm.yml").write_text( | ||
| "name: grepo\nversion: 1.0.0\ndescription: global pkg\nauthor: X\n" | ||
| ) | ||
| with patch( | ||
| "apm_cli.core.scope.get_apm_dir", return_value=fake_home, | ||
| ), _force_rich_fallback(): | ||
| result = self.runner.invoke( | ||
| cli, ["view", "gorg/grepo", "-g"] | ||
| ) | ||
| assert result.exit_code == 0 | ||
| assert "grepo" in result.output |
There was a problem hiding this comment.
test_view_global_flag uses tempfile.mkdtemp() to create fake_home but never cleans it up, which can leak temp directories across test runs. Prefer using tempfile.TemporaryDirectory() (or creating fake_home under the existing _chdir_tmp() path) so the directory is always removed.
| fake_home = Path(tempfile.mkdtemp()) | |
| pkg_dir = fake_home / "apm_modules" / "gorg" / "grepo" | |
| pkg_dir.mkdir(parents=True) | |
| (pkg_dir / "apm.yml").write_text( | |
| "name: grepo\nversion: 1.0.0\ndescription: global pkg\nauthor: X\n" | |
| ) | |
| with patch( | |
| "apm_cli.core.scope.get_apm_dir", return_value=fake_home, | |
| ), _force_rich_fallback(): | |
| result = self.runner.invoke( | |
| cli, ["view", "gorg/grepo", "-g"] | |
| ) | |
| assert result.exit_code == 0 | |
| assert "grepo" in result.output | |
| with tempfile.TemporaryDirectory() as fake_home_dir: | |
| fake_home = Path(fake_home_dir) | |
| pkg_dir = fake_home / "apm_modules" / "gorg" / "grepo" | |
| pkg_dir.mkdir(parents=True) | |
| (pkg_dir / "apm.yml").write_text( | |
| "name: grepo\nversion: 1.0.0\ndescription: global pkg\nauthor: X\n" | |
| ) | |
| with patch( | |
| "apm_cli.core.scope.get_apm_dir", return_value=fake_home, | |
| ), _force_rich_fallback(): | |
| result = self.runner.invoke( | |
| cli, ["view", "gorg/grepo", "-g"] | |
| ) | |
| assert result.exit_code == 0 | |
| assert "grepo" in result.output |
| import tempfile | ||
| from pathlib import Path | ||
| from unittest.mock import patch |
There was a problem hiding this comment.
tests/unit/test_deps_utils.py imports tempfile and patch but does not use them. Removing unused imports keeps the test module clean and avoids future lint/type-check noise.
| import tempfile | |
| from pathlib import Path | |
| from unittest.mock import patch | |
| from pathlib import Path |
Description
Addresses backlog items #4 (
commands/deps/_utils.py, 50% coverage) and #5 (commands/view.py, 66% coverage) from the Test Improver tracking issue.tests/unit/test_deps_utils.py— 43 tests (new file)_is_nested_under_package: nested/boundary/deep nesting cases_count_primitives: all primitive types, root-level files, hooks in both dirs, combined counts_count_package_files/_count_workflows: context dirs, workflow sources, combined_get_detailed_context_counts: per-type counts, singularcontext/dir mapping_get_package_display_info: valid yml, empty version, missing yml, malformed yml_get_detailed_package_info: full metadata, no-yml fallback, error path, defaults_scan_installed_packages: ADO 3-level, hidden dirs,.apm/detection, single-level exclusiontests/unit/test_view_command.py— 12 new tests_lookup_lockfile_ref: exact match, substring fallback, no match, exception swallowing,Nonelockfile--globalflag, context/workflow/hook display, lockfile ref+commit renderingAll 3,877 tests pass.
Type of change
Testing