def duplicate(self, components_list: List["Component"]) -> "Component": return Component( self.file, self.file.duplicate_nx_group( self.group, generate_unique_name(self.name, components_list) ), )
def test_GIVEN_name_with_1_in_already_WHEN_generating_unique_name_THEN_number_is_appended_to_the_suffix_of_the_name( ): comp = DummyComponent("something1") assert (generate_unique_name( comp.name, [DummyComponent("something1"), DummyComponent("something2")]) == comp.name + "1")
def generate_name_suggestion(self): """ Generates a component name suggestion for use in the tooltip when a component is invalid. :return: The component name suggestion, based on the current nx_class. """ return generate_unique_name( self.componentTypeComboBox.currentText().lstrip("NX"), self.instrument.get_component_list(), )
def _create_new_transformation(parent_component, transformation_list, transformation_type): if transformation_type == TransformationType.TRANSLATION: new_transformation = parent_component.add_translation( name=generate_unique_name(TransformationType.TRANSLATION, transformation_list), vector=QVector3D(1.0, 0, 0), ) elif transformation_type == TransformationType.ROTATION: new_transformation = parent_component.add_rotation( name=generate_unique_name("Rotation", transformation_list), axis=QVector3D(1.0, 0, 0), angle=0.0, ) else: raise ValueError( f"Unknown transformation type: {transformation_type}") return new_transformation
def test_GIVEN_unique_name_WHEN_generating_unique_name_THEN_returns_unchanged_name( ): name = "something" assert generate_unique_name(name, []) == name
def test_GIVEN_name_with_1_as_suffix_and_name_with_11_already_in_list_WHEN_generating_unique_name_THEN_following_number_is_incremented_and_name_is_unique( ): comp = DummyComponent("something1") assert (generate_unique_name( comp.name, [comp, DummyComponent(comp.name + "1")])) == "something12"
def test_GIVEN_name_already_in_list_WHEN_generating_unique_name_THEN_returns_changed_name( ): comp = DummyComponent("something") assert generate_unique_name(comp.name, [comp]) == comp.name + "1"