Skip to content

Conversation

@gaborbernat
Copy link
Member

@gaborbernat gaborbernat commented Jan 3, 2026

Modernize the codebase with idiomatic Kotlin patterns, fix deprecated IntelliJ API usage, and add comprehensive test coverage.

Changes

Deprecated API Fix

  • Replace MessageType.INFO with NotificationType.INFORMATION in notifications
  • Add proper notification title parameter

Kotlin Idioms

  • Use property syntax: file.path instead of file.getPath(), node.virtualFile instead of node.getVirtualFile()
  • Replace nested null checks with scope functions (?.let, takeIf)
  • Replace try-catch with runCatching for cleaner error handling
  • Remove unnecessary @JvmStatic annotations (no Java callers in the codebase)

Performance

  • Add ConcurrentHashMap cache to VenvProjectViewNodeDecorator to avoid re-reading pyvenv.cfg files on every tree render

Test Coverage

Added comprehensive unit tests and UI tests:

Test Class Tests Coverage
VenvUtilsTest 7 tests Version parsing, edge cases, error handling
VenvProjectViewNodeDecoratorTest 6 tests Decoration logic, caching behavior
UITest (new scenarios) 4 tests Version display, icon decoration, context menu

New test scenarios:

  • Valid/invalid pyvenv.cfg parsing
  • Missing version key handling
  • Empty file handling
  • Decorator caching verification
  • UI: Python version display in tree
  • UI: Context menu on non-venv items

- Replace deprecated MessageType.INFO with NotificationType.INFORMATION
- Use Kotlin property syntax (file.path instead of file.getPath())
- Replace nested null checks with scope functions (?.let, takeIf)
- Replace try-catch with runCatching for cleaner error handling
- Add version caching to VenvProjectViewNodeDecorator for performance
- Remove unnecessary @JvmStatic annotations (no Java callers)
Unit tests for VenvUtils:
- Test getPythonVersionFromPyVenv with valid/invalid/missing files
- Test version parsing with edge cases (trimming, equals signs)

Unit tests for VenvProjectViewNodeDecorator:
- Test decoration with valid venv directories
- Test no decoration for non-venv files
- Verify version caching behavior

Additional UI test scenarios:
- Test Python version display in project tree
- Test venv icon decoration
- Test context menu behavior on non-venv items

Dependencies:
- Add mockk for mocking IntelliJ classes in unit tests
@gaborbernat gaborbernat merged commit f3c0f08 into tox-dev:main Jan 3, 2026
11 checks passed
@gaborbernat gaborbernat deleted the refactor/kotlin-best-practices branch January 3, 2026 01:28
gaborbernat added a commit to gaborbernat/PyVenvManage that referenced this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant