diff --git a/openhtf/core/phase_descriptor.py b/openhtf/core/phase_descriptor.py index 4dff0d4b4..fe5100697 100644 --- a/openhtf/core/phase_descriptor.py +++ b/openhtf/core/phase_descriptor.py @@ -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 @@ -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]: diff --git a/test/phase_descriptor_test.py b/test/phase_descriptor_test.py index 1fdd92dca..1397b9bfb 100644 --- a/test/phase_descriptor_test.py +++ b/test/phase_descriptor_test.py @@ -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)