Skip to content

Refactor test suite to use parametrized tests and reduce duplication#98

Merged
dceoy merged 6 commits into
mainfrom
claude/pdmt5-test-parametrize-tp9ast
Jul 4, 2026
Merged

Refactor test suite to use parametrized tests and reduce duplication#98
dceoy merged 6 commits into
mainfrom
claude/pdmt5-test-parametrize-tp9ast

Conversation

@dceoy

@dceoy dceoy commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

Consolidates multiple similar test methods into parametrized test cases across the test suite, reducing code duplication and improving maintainability. This refactoring applies the DRY principle to test code while maintaining full coverage of the tested functionality.

Key Changes

  • test_dataframe.py:

    • Merged test_orders_get_with_data and test_positions_get_with_data into a single parametrized test_orders_positions_get_with_data method
    • Consolidated five separate *_as_dicts test methods (symbols_get_as_dicts, orders_get_as_dicts, positions_get_as_dicts, history_orders_get_as_dicts, history_deals_get_as_dicts) into a single parametrized test_get_as_dicts_skip_to_datetime method
    • Merged copy_rates_from_as_df and copy_ticks_from_as_df index_keys tests into test_copy_methods_with_index_keys
    • Split test_dataframe_methods_with_index_keys into two focused parametrized tests: test_orders_positions_get_as_df_with_index_keys and test_copy_methods_with_index_keys
    • Extracted _MockSymbolRow class to replace inline mock definitions
    • Removed test_symbols_total (redundant coverage)
  • test_mt5.py:

    • Merged test_orders_get and test_positions_get into a single parametrized test_orders_positions_get method
  • test_utils.py:

    • Consolidated three separate test functions (test_decorator_with_other_result_type variants) into a single parametrized test method
  • pyproject.toml:

    • Bumped version from 1.0.4 to 1.1.0

Implementation Details

  • All parametrized tests use pytest.param with descriptive id arguments for clarity in test output
  • Mock data and expected values are passed as parameters, eliminating repetitive setup code
  • Test behavior and assertions remain identical to the original implementations
  • The refactoring maintains 100% test coverage while reducing overall test file size and improving readability

https://claude.ai/code/session_01PLmm9eBm4WRiLfCcQCuqae

claude added 2 commits July 3, 2026 18:38
Consolidate orders_get/positions_get, *_as_dicts skip_to_datetime, and
index_keys coverage in test_dataframe.py into pytest.mark.parametrize
cases with stable IDs, drop the symbols_total test now redundant with
test_total_methods, and parametrize the equivalent orders_get/positions_get
pair in test_mt5.py plus the small decorator branch cases in test_utils.py.
@dceoy dceoy self-assigned this Jul 3, 2026
@dceoy dceoy marked this pull request as ready for review July 3, 2026 18:41
claude added 4 commits July 3, 2026 18:46
Merge symbol_info_as_dict/symbol_info_tick_as_dict skip_to_datetime
coverage into one parametrized test, and split symbols_get_as_df_with_params
into isolated skip_to_datetime and index_keys cases.
Add explicit skip/convert parametrize axes to test_get_as_dicts_skip_to_datetime,
test_symbol_info_dict_methods_with_skip_to_datetime, test_copy_rates_as_dicts,
and test_copy_ticks_as_dicts so a failure in either mode is isolated. Also
parametrize test_decorator_with_skip_toggle in test_utils.py and
test_version_methods_raise_mt5_runtime_error_on_none_response by client_method.
Merge test_history_orders_get_filters and test_history_deals_get_filter
into one parametrized test_history_get_filters covering both entities
against the shared filter matrix. Also fold the redundant
detect_and_convert_time_to_datetime dict/list-return checks into the
main decorator test (strengthening its assertions instead), drop the
empty-DataFrame case from test_set_index_if_possible_decorator since
it duplicates test_orders_get_as_df_empty_result_has_no_index, and
parametrize test_market_book_get_as_dicts by skip_to_datetime.
Split test_inheritance_behavior into a parametrized
test_inheritance_exposes_expected_methods (one case per inherited/own
method name) and a focused test_inheritance_behavior covering parent
initialize/last_error behavior. Remove test_detect_and_convert_time_decorator,
whose dict/list skip-vs-convert branches are now fully covered by
test_symbol_info_dict_methods_with_skip_to_datetime and
test_get_as_dicts_skip_to_datetime.

@dceoy dceoy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM. I reviewed the diff with a focus on semantic equivalence of the parametrized test refactor and did not find any blocking issues.

The parametrized replacements preserve the important assertions for orders/positions DataFrame conversion, history filters, *_as_dicts time conversion behavior, copy method index_keys, inherited methods, and decorator behavior. CI is also green: pytest, ruff, pyright, and CodeQL all completed successfully.

Non-blocking note: this is effectively a test-suite refactor, while pyproject.toml and uv.lock bump the package version from 1.0.4 to 1.1.0. Keep that only if this PR is intentionally preparing a release; otherwise consider reverting the version bump to keep release metadata separate from test-only maintenance.

@dceoy dceoy merged commit bf9ab25 into main Jul 4, 2026
8 checks passed
@dceoy dceoy deleted the claude/pdmt5-test-parametrize-tp9ast branch July 4, 2026 04:36
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.

2 participants