Skip to content

Jules - Factory Boy 2#11

Draft
s2t2 wants to merge 1 commit intocopybara_pushfrom
feat/refactor-tests-with-factories
Draft

Jules - Factory Boy 2#11
s2t2 wants to merge 1 commit intocopybara_pushfrom
feat/refactor-tests-with-factories

Conversation

@s2t2
Copy link
Owner

@s2t2 s2t2 commented May 26, 2025

I refactored your tests to use factory_boy for test data generation.

I introduced factory_boy and refactored several of your test files to use factories, simplifying test data setup and improving maintainability.

Here are the key changes:

  • Added factory_boy to your project dependencies.
  • Created smart_control/utils/factory_utils.py with factories for:
    • Protobufs: ActionRequest, ObservationRequest, ObservationResponse, RewardInfo and their sub-components.
    • Custom classes: SimpleBuilding, MaterialProperties, Building (deprecated), FloorPlanBasedBuilding.
  • Refactored tests in:
    • smart_control/environment/environment_test.py
    • smart_control/simulator/building_test.py
    • smart_control/simulator/simulator_building_test_lib.py
    • smart_control/simulator/tf_simulator_test.py
    • smart_control/reward/base_setpoint_energy_carbon_reward_test.py
    • smart_control/reward/setpoint_energy_carbon_regret_test.py
  • Added smart_control/utils/factory_utils_test.py with usage examples.
  • Updated smart_control/utils/BUILD for new files and dependencies.
  • Documented factory usage in README.md.

This work is part of an ongoing effort to improve test clarity and reduce boilerplate by leveraging factories for test object creation.

Fixes #<issue_number_goes_here>

It's a good idea to open an issue first for discussion.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

I introduced factory_boy and refactored several of your test files to use factories, simplifying test data setup and improving maintainability.

Here are the key changes:
- Added `factory_boy` to your project dependencies.
- Created `smart_control/utils/factory_utils.py` with factories for:
    - Protobufs: `ActionRequest`, `ObservationRequest`, `ObservationResponse`, `RewardInfo` and their sub-components.
    - Custom classes: `SimpleBuilding`, `MaterialProperties`, `Building` (deprecated), `FloorPlanBasedBuilding`.
- Refactored tests in:
    - `smart_control/environment/environment_test.py`
    - `smart_control/simulator/building_test.py`
    - `smart_control/simulator/simulator_building_test_lib.py`
    - `smart_control/simulator/tf_simulator_test.py`
    - `smart_control/reward/base_setpoint_energy_carbon_reward_test.py`
    - `smart_control/reward/setpoint_energy_carbon_regret_test.py`
- Added `smart_control/utils/factory_utils_test.py` with usage examples.
- Updated `smart_control/utils/BUILD` for new files and dependencies.
- Documented factory usage in `README.md`.

This work is part of an ongoing effort to improve test clarity and reduce boilerplate by leveraging factories for test object creation.
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