Skip to content

Reduce boilerplate for setting tactics and plays in tests#3648

Merged
nycrat merged 32 commits intomasterfrom
avah/change_set_tactic_syntax
Mar 21, 2026
Merged

Reduce boilerplate for setting tactics and plays in tests#3648
nycrat merged 32 commits intomasterfrom
avah/change_set_tactic_syntax

Conversation

@nycrat
Copy link
Member

@nycrat nycrat commented Mar 14, 2026

Description

In pytests, setting robot tactics required quite a bit of boilerplate related to creating the AssignedTacticPlayControlParams protos. This PR modifies the set_tactics and set_play functions to reduce repeated code, and also makes the code more readable.

Old:

params = AssignedTacticPlayControlParams()
params.assigned_tactics[0].goalie.CopyFrom(
    GoalieTactic(max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT)
)
simulated_test_runner.set_tactics(params, is_friendly=True)

params = AssignedTacticPlayControlParams()
simulated_test_runner.set_tactics(params, is_friendly=False)

New:

simulated_test_runner.set_tactics(
    blue_tactics={
        0: GoalieTactic(
            max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT
        )
    }
)

Old:

blue_play = Play()
blue_play.name = PlayName.OffensePlay

yellow_play = Play()
yellow_play.name = PlayName.HaltPlay

simulated_test_runner.set_play(blue_play, is_friendly=True)
simulated_test_runner.set_play(yellow_play, is_friendly=False)

New:

simulated_test_runner.set_plays(
    blue_play=PlayName.OffensePlay, yellow_play=PlayName.HaltPlay
)

Testing Done

Behaviour of tests is still the same after the refactors.

Resolved Issues

Length Justification and Key Files to Review

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

sauravbanna
sauravbanna previously approved these changes Mar 14, 2026
@nycrat nycrat force-pushed the avah/move_pytests_to_own_directory branch from 320e9b7 to ced6821 Compare March 14, 2026 19:46
@nycrat nycrat closed this Mar 16, 2026
@nycrat nycrat force-pushed the avah/change_set_tactic_syntax branch from abc1836 to 2f5f892 Compare March 16, 2026 02:57
@nycrat nycrat reopened this Mar 16, 2026
@nycrat nycrat changed the title Change set_tactic syntax Reduce boilerplate with set_tactics function Mar 16, 2026
@nycrat nycrat changed the title Reduce boilerplate with set_tactics function Reduce boilerplate for setting tactics and plays in tests Mar 16, 2026
@nycrat nycrat changed the base branch from avah/move_pytests_to_own_directory to master March 21, 2026 22:56
@nycrat nycrat dismissed sauravbanna’s stale review March 21, 2026 22:56

The base branch was changed.

Copy link
Contributor

@StarrryNight StarrryNight left a comment

Choose a reason for hiding this comment

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

LGTM

@nycrat nycrat merged commit f8609b0 into master Mar 21, 2026
6 checks passed
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.

4 participants