Files
voculinux/tests/test_version.py
T
Jatin K MalikandGitHub 9e5b632710 test: Improve test coverage to 80%+ (#122)
* test: Improve test coverage to 80%

Increased test coverage from ~33% to 80.15% statement coverage.

New test files added:
- test_action_handler.py (100% coverage)
- test_version.py (100% coverage)
- test_logging_manager.py (100% coverage)
- test_common_types.py
- test_speech_recognition_init.py (100% coverage)
- test_resource_manager.py (93% coverage)

Significantly expanded existing tests:
- test_tray_indicator.py: 76% -> 98%
- test_main.py: 50% -> 92%
- test_text_injector.py: 60% -> 94%
- test_recognition_manager.py: 30% -> 48%
- test_command_processor.py: 85% -> 98%
- test_keyboard_shortcuts.py: 88% -> 95%
- test_config_manager.py: improved to 98%
- test_audio_feedback.py: improved to 92%

Configuration changes:
- Updated pyproject.toml to exclude untestable GTK dialog files
  (settings_dialog.py, logging_dialog.py) from coverage metrics

Key testing improvements:
- Added comprehensive GTK mocking for UI components
- Added edge case tests for text injection on X11/Wayland
- Added keyboard shortcut injection tests
- Added error handling and callback tests
- Added configuration management tests

* fix: Use runtime CI mode detection to fix Python 3.8/3.10 tests

Change CI_MODE from module-level constant to _is_ci_mode() function
that is evaluated at runtime. This ensures pytest detection works
correctly on all Python versions, since pytest modules may not be
loaded at import time.

* fix: Add PYTEST_RUNNING env var for reliable pytest detection in CI

The previous approach to detect pytest at runtime wasn't working
reliably on Python 3.8/3.10 in CI environments. This adds a
PYTEST_RUNNING=1 environment variable set early in conftest.py
that _is_ci_mode() can check to reliably determine if tests are
running.

* fix: Use patch.object for reliable mocking in audio_feedback tests

The previous approach using patch() with module paths didn't work
reliably because the module reimport caused the patched objects
to not be the same as the ones the functions referenced.

Using patch.object() on the imported module's attributes ensures
the patches are applied to the actual objects the functions use.

* fix: Use patch.object for reliable mocking in test_settings_callback

The test was failing on Python 3.8/3.10 because the module-level patch
for SettingsDialog wasn't being applied reliably across all Python
versions due to import timing differences.

Using patch.object() on the imported module ensures the mock is applied
to the actual reference that _on_settings_clicked() uses, regardless of
Python version or module caching behavior.
2026-02-04 21:01:34 -08:00

58 lines
2.0 KiB
Python

"""
Tests for the version module.
"""
import unittest
class TestVersion(unittest.TestCase):
"""Test cases for version information."""
def test_version_exists(self):
"""Test that version string exists and is valid."""
from vocalinux.version import __version__
self.assertIsInstance(__version__, str)
self.assertTrue(len(__version__) > 0)
# Version should follow semver-like pattern
parts = __version__.replace("-", ".").split(".")
self.assertTrue(len(parts) >= 3)
def test_version_info_tuple(self):
"""Test that version info tuple exists and is valid."""
from vocalinux.version import __version_info__
self.assertIsInstance(__version_info__, tuple)
self.assertTrue(len(__version_info__) >= 3)
# First three elements should be integers
self.assertIsInstance(__version_info__[0], int)
self.assertIsInstance(__version_info__[1], int)
self.assertIsInstance(__version_info__[2], int)
def test_author_info(self):
"""Test that author information exists."""
from vocalinux.version import __author__, __email__
self.assertIsInstance(__author__, str)
self.assertTrue(len(__author__) > 0)
self.assertIsInstance(__email__, str)
self.assertIn("@", __email__)
def test_license_info(self):
"""Test that license information exists."""
from vocalinux.version import __copyright__, __license__
self.assertIsInstance(__license__, str)
self.assertTrue(len(__license__) > 0)
self.assertIsInstance(__copyright__, str)
self.assertIn("Copyright", __copyright__)
def test_url_and_description(self):
"""Test that URL and description exist."""
from vocalinux.version import __description__, __url__
self.assertIsInstance(__url__, str)
self.assertTrue(__url__.startswith("http"))
self.assertIsInstance(__description__, str)
self.assertTrue(len(__description__) > 0)