Skip to content

Enhance project foundation with coverage, ConfigManager tests, and modern types#49

Merged
luyiourwong merged 12 commits intomainfrom
feature/next-20250924
Sep 26, 2025
Merged

Enhance project foundation with coverage, ConfigManager tests, and modern types#49
luyiourwong merged 12 commits intomainfrom
feature/next-20250924

Conversation

@luyiourwong
Copy link
Copy Markdown
Owner

@luyiourwong luyiourwong commented Sep 26, 2025

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

  • Code Coverage Configuration: A new .coveragerc file 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__, raise statements).
  • Project Metadata Updates: The pyproject.toml file 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 .github and .gemini directories.
  • Modernized Type Hints: Type hints within terminara/objects/world_settings.py have been updated to utilize the more concise int | float syntax (PEP 604) for union types, improving readability and consistency.
  • Comprehensive ConfigManager Tests: A new test file, tests/test_core/test_config_manager.py, has been introduced, providing extensive unit tests for the ConfigManager class. These tests cover initialization, file handling, saving, retrieving, setting, and deleting configuration values, ensuring robustness.
  • Documentation and Test Refinements: The AGENTS.md documentation has been streamlined by removing outdated sections on GUI screens, implementation steps, and dependencies. Additionally, test_world_handler.py has been expanded to include tests for text variables and an increased number of scenario choices.

yiourwonglu and others added 11 commits September 24, 2025 15:06
- 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
Signed-off-by: yiourwonglu <yiourwong.lu@flowring.com>
…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
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 ConfigManager, ensuring reliable handling of application settings. Minor adjustments to documentation and existing tests further refine the codebase.

Highlights

  • Code Coverage Configuration: A new .coveragerc file 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__, raise statements).
  • Project Metadata Updates: The pyproject.toml file 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 .github and .gemini directories.
  • Modernized Type Hints: Type hints within terminara/objects/world_settings.py have been updated to utilize the more concise int | float syntax (PEP 604) for union types, improving readability and consistency.
  • Comprehensive ConfigManager Tests: A new test file, tests/test_core/test_config_manager.py, has been introduced, providing extensive unit tests for the ConfigManager class. These tests cover initialization, file handling, saving, retrieving, setting, and deleting configuration values, ensuring robustness.
  • Documentation and Test Refinements: The AGENTS.md documentation has been streamlined by removing outdated sections on GUI screens, implementation steps, and dependencies. Additionally, test_world_handler.py has been expanded to include tests for text variables and an increased number of scenario choices.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@luyiourwong luyiourwong changed the title Feature/next 20250924 Enhance project foundation with coverage, ConfigManager tests, and modern types Sep 26, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/test_core/test_config_manager.py Outdated
Comment on lines +112 to +115
try:
config_manager.delete_value("nonexistent_key")
except Exception as e:
pytest.fail(f"Deleting a nonexistent key raised an exception: {e}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This try...except pytest.fail() block is verbose for testing the absence of an exception. Pytest will automatically fail the test if delete_value() raises an unexpected exception. You can simplify this by just calling the method directly.

        config_manager.delete_value("nonexistent_key")


from terminara.core.world_handler import load_world
from terminara.objects.scenario import Scenario, Choice, VariableAction
from terminara.objects.scenario import Scenario, VariableAction
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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>
@luyiourwong luyiourwong merged commit 2dc31ea into main Sep 26, 2025
2 checks passed
@luyiourwong luyiourwong deleted the feature/next-20250924 branch September 26, 2025 01:58
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