Enhance project foundation with coverage, ConfigManager tests, and modern types#49
Enhance project foundation with coverage, ConfigManager tests, and modern types#49luyiourwong merged 12 commits intomainfrom
Conversation
- Update `pyproject.toml` to reflect project maturity from Alpha to Beta. - Exclude `.github*` and `.gemini*` directories from package builds. Signed-off-by: yiourwonglu <yiourwong.lu@flowring.com>
- Enhanced unit tests for `test_world_handler` to validate new `TextVariable` and additional scenario choices. - Updated `.coveragerc` to set up code coverage configuration, ensuring tests exclude unnecessary files and lines. Signed-off-by: yiourwonglu <yiourwong.lu@flowring.com>
- Replace Union[int, float] with int | float for value type hint - Replace Union[int, float, None] with int | float | None for min_value and max_value - Remove unused Union import from typing module - Fixes Sonar issue python:S6546 about union type expressions
This commit introduces a comprehensive suite of unit tests for the `ConfigManager` class, located in `terminara/core/config_manager.py`. The tests are implemented using `pytest` in the new file `tests/test_core/test_config_manager.py`. Key features of the test suite: - A pytest fixture with monkeypatching creates an isolated `ConfigManager` instance in a temporary directory, ensuring tests do not interfere with actual user configuration. - All public methods of `ConfigManager` are covered, including edge cases like handling missing, empty, or invalid configuration files. Additionally, the `.gitignore` file has been updated to exclude common Python artifacts (`__pycache__/`, `*.py[cod]`) and the virtual environment directory (`/.venv/`), improving repository hygiene.
- Update requires-python from >=3.8 to >=3.10 in pyproject.toml - Remove Python 3.8 and 3.9 from classifiers since modern union syntax requires Python 3.10+ - Addresses GitHub comment feedback
…pe-hints fix: replace typing.Union with modern union syntax in NumericVariable
The manual monkeypatching in this fixture is brittle. If an exception occurs during ConfigManager() instantiation, the original __init__ method won't be restored, which could lead to test pollution. A more robust approach is to use pytest's built-in monkeypatch fixture, which automatically handles the setup and teardown of the patch, ensuring test isolation even in case of errors. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: yiourwonglu <yiourwong.lu@flowring.com>
feat: Add unit tests for ConfigManager
Summary of ChangesHello @luyiourwong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the project's foundational aspects, including development environment configuration, code quality, and testing infrastructure. It introduces a dedicated code coverage setup, updates project metadata to align with current Python standards, and modernizes type hinting practices. A significant addition is a comprehensive suite of unit tests for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. New tests now stand so tall, Python's types, a modern call. Coverage, a guiding light, Code's future, shining bright. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several updates, including adding a .coveragerc file, updating .gitignore, and cleaning up documentation. Key changes involve upgrading the required Python version to 3.10 and updating dependencies in pyproject.toml. The code is updated to use modern type hints (| operator). New tests for ConfigManager have been added, and existing tests for world_handler have been expanded to cover new functionality. My review focuses on improving the new and updated tests for better clarity and coverage.
| try: | ||
| config_manager.delete_value("nonexistent_key") | ||
| except Exception as e: | ||
| pytest.fail(f"Deleting a nonexistent key raised an exception: {e}") |
There was a problem hiding this comment.
|
|
||
| from terminara.core.world_handler import load_world | ||
| from terminara.objects.scenario import Scenario, Choice, VariableAction | ||
| from terminara.objects.scenario import Scenario, VariableAction |
There was a problem hiding this comment.
To properly test the new ItemAction functionality, you should import ItemAction here. This will allow you to use assertIsInstance to verify the action type in test_load_world, as suggested in another comment.
| from terminara.objects.scenario import Scenario, VariableAction | |
| from terminara.objects.scenario import Scenario, VariableAction, ItemAction |
| self.assertIsInstance(world_settings.scenario.init, Scenario) | ||
| self.assertEqual(world_settings.scenario.init.text, "You stand at the entrance to a mysterious cave in the test world.") | ||
| self.assertEqual(len(world_settings.scenario.init.choices), 2) | ||
| self.assertEqual(len(world_settings.scenario.init.choices), 3) |
There was a problem hiding this comment.
While the test correctly asserts that there are 3 choices, it doesn't verify the content of the newly added third choice. Please add assertions to check its text and actions to ensure the parsing logic is correct for ItemAction.
You can add the following assertions at the end of the test method:
self.assertEqual(world_settings.scenario.init.choices[2].text, "3. Flee into the misty woods")
self.assertEqual(len(world_settings.scenario.init.choices[2].actions), 1)
self.assertIsInstance(world_settings.scenario.init.choices[2].actions[0], ItemAction)
self.assertEqual(world_settings.scenario.init.choices[2].actions[0].item_name, "potion")
self.assertEqual(world_settings.scenario.init.choices[2].actions[0].quantity, 1)Note that you'll need to import ItemAction for this to work (as mentioned in another comment).
- Removed unnecessary exception handling in `test_config_manager` for `delete_value`. Signed-off-by: yiourwonglu <yiourwong.lu@flowring.com>
This pull request focuses on enhancing the project's foundational aspects, including development environment configuration, code quality, and testing infrastructure. It introduces a dedicated code coverage setup, updates project metadata to align with current Python standards, and modernizes type hinting practices. A significant addition is a comprehensive suite of unit tests for the
ConfigManager, ensuring reliable handling of application settings. Minor adjustments to documentation and existing tests further refine the codebase.Highlights
.coveragercfile has been added to configure code coverage reporting, specifying source directories, files to omit (like tests and virtual environments), and lines to exclude from coverage calculations (e.g.,__repr__,__str__,raisestatements).pyproject.tomlfile has been updated to require Python 3.10 or newer, reflect a change in development status from Alpha to Beta, and refine the package exclusion rules to include.githuband.geminidirectories.terminara/objects/world_settings.pyhave been updated to utilize the more conciseint | floatsyntax (PEP 604) for union types, improving readability and consistency.tests/test_core/test_config_manager.py, has been introduced, providing extensive unit tests for theConfigManagerclass. These tests cover initialization, file handling, saving, retrieving, setting, and deleting configuration values, ensuring robustness.AGENTS.mddocumentation has been streamlined by removing outdated sections on GUI screens, implementation steps, and dependencies. Additionally,test_world_handler.pyhas been expanded to include tests for text variables and an increased number of scenario choices.