def test_normalize_field_name(self, sample_name, sample_prefix): with mock.patch("ntgen.utils.convert_to_snake_case", ) as mock_convert_to_snake_case, mock.patch( "ntgen.utils.replace_leading_underscores", ) as mock_replace_leading_underscores: normalize_field_name(name=sample_name, leading_undescores_prefix=sample_prefix) mock_convert_to_snake_case.assert_called_once() mock_replace_leading_underscores.assert_called_once()
def normalize_keys(data: Dict) -> Dict: assert isinstance(data, dict) normalized_dict = {} for key, value in data.items(): normalized_key = replace_leading_underscores(normalize_field_name(key)) normalized_dict[normalized_key] = normalize_keys(value) if isinstance( value, dict) else value return normalized_dict
def test_repr_field_name(self, sample_attribute): with mock.patch( "ntgen.models.normalize_field_name", side_effect=normalize_field_name, ) as mock_normalize_field_name: assert sample_attribute.repr_field_name == normalize_field_name( name=sample_attribute.original_name, leading_undescores_prefix=None, ) mock_normalize_field_name.assert_called_once()
def test_normalize_field_name(name, prefix, expected_field_name): assert normalize_field_name( name=name, leading_undescores_prefix=prefix) == expected_field_name
def repr_field_name(self) -> str: """Return the attribute name normalized to be a valid pythonic NamedTuple field name.""" return normalize_field_name(name=self.original_name, leading_undescores_prefix=None)