Exemple #1
0
    def add_component(self, component: Metadatable, name: str = None,
                      update_snapshot: bool = True) -> str:
        """
        Record one component as part of this Station.

        Args:
            component (Any): components to add to the Station.
            name (str): name of the component
            update_snapshot (bool): immediately update the snapshot
                of each component as it is added to the Station, default true

        Returns:
            str: The name assigned this component, which may have been changed
                 to make it unique among previously added components.

        """
        try:
            component.snapshot(update=update_snapshot)
        except:
            pass
        if name is None:
            name = getattr(component, 'name',
                           'component{}'.format(len(self.components)))
        namestr = make_unique(str(name), self.components)
        self.components[namestr] = component
        return namestr
Exemple #2
0
 def test_changes(self):
     self.assertEqual(make_unique('a', ('a', )), 'a_2')
     self.assertEqual(make_unique('a_2', ('a_2', )), 'a_2_2')
     self.assertEqual(make_unique('a', ('a', 'a_2', 'a_3')), 'a_4')
Exemple #3
0
 def test_no_changes(self):
     for s, existing in (('a', []), ('a', {}), ('a', ('A', ' a', 'a '))):
         self.assertEqual(make_unique(s, existing), s)