Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 542925313
  • Loading branch information
OpenHTF Owners authored and copybara-github committed Jun 23, 2023
1 parent 5f11f03 commit 5e04cce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 8 additions & 5 deletions openhtf/core/phase_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ def __call__(self, phase_func: PhaseT) -> 'PhaseDescriptor':
phase.options.repeat_limit = self.repeat_limit
if self.run_under_pdb:
phase.options.run_under_pdb = self.run_under_pdb
if self.phase_name_case == PhaseNameCase.CAMEL:
name = phase.name if phase.options.name is None else phase.options.name
phase.options.name = inflection.camelize(name)
if self.stop_on_measurement_fail:
phase.options.stop_on_measurement_fail = self.stop_on_measurement_fail
if self.phase_name_case:
phase.options.phase_name_case = self.phase_name_case
return phase


Expand Down Expand Up @@ -233,8 +232,12 @@ def _asdict(self) -> Dict[Text, Any]:
@property
def name(self) -> Text:
if self.options.name and isinstance(self.options.name, str):
return self.options.name
return self.func.__name__
name = self.options.name
else:
name = self.func.__name__
if self.options.phase_name_case == PhaseNameCase.CAMEL:
name = inflection.camelize(name)
return name

@property
def doc(self) -> Optional[Text]:
Expand Down
11 changes: 11 additions & 0 deletions test/phase_descriptor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ def snake_cased_phase():

self.assertEqual(snake_cased_phase.name, 'SnakeCasedPhase')

def test_camel_phase_name_casing_formats_templated_name(self):
@phase_descriptor.PhaseOptions(
name='{snake}_cased_phase', phase_name_case=openhtf.PhaseNameCase.CAMEL
)
def snake_cased_phase():
"""Empty function to generate phase descriptor."""

self.assertEqual(
snake_cased_phase.with_args(snake='snake').name, 'SnakeCasedPhase'
)

def test_keep_phase_name_casing_does_not_change_name(self):

@phase_descriptor.PhaseOptions(phase_name_case=openhtf.PhaseNameCase.KEEP)
Expand Down

0 comments on commit 5e04cce

Please sign in to comment.