Esempio n. 1
0
def test_slugify():
    assert slugify("a") == "a"
    assert slugify("1a") == "1a"
    assert slugify("1") == "1"
    assert slugify("a a") == "a_a"

    assert slugify("a", valid_variable_name=True) == "a"
    assert slugify("1a", valid_variable_name=True) == "Number_1a"
    assert slugify("1", valid_variable_name=True) == "Number_1"

    assert slugify("a", valid_variable_name=False) == "a"
    assert slugify("1a", valid_variable_name=False) == "1a"
    assert slugify("1", valid_variable_name=False) == "1"
Esempio n. 2
0
def test_slugify():
    assert slugify('a') == 'a'
    assert slugify('1a') == '1a'
    assert slugify('1') == '1'
    assert slugify('a a') == 'a_a'

    assert slugify('a', valid_variable_name=True) == 'a'
    assert slugify('1a', valid_variable_name=True) == 'Number_1a'
    assert slugify('1', valid_variable_name=True) == 'Number_1'

    assert slugify('a', valid_variable_name=False) == 'a'
    assert slugify('1a', valid_variable_name=False) == '1a'
    assert slugify('1', valid_variable_name=False) == '1'
Esempio n. 3
0
def test_slugify():
    assert slugify('a') == 'a'
    assert slugify('1a') == '1a'
    assert slugify('1') == '1'
    assert slugify('a a') == 'a_a'

    assert slugify('a', valid_variable_name=True) == 'a'
    assert slugify('1a', valid_variable_name=True) == 'Number_1a'
    assert slugify('1', valid_variable_name=True) == 'Number_1'

    assert slugify('a', valid_variable_name=False) == 'a'
    assert slugify('1a', valid_variable_name=False) == '1a'
    assert slugify('1', valid_variable_name=False) == '1'
Esempio n. 4
0
 def __delattr__(self, name):
     if name in self:
         del self[name]
     else:
         for k in self:
             if name == slugify(k, True):
                 del self[k]
Esempio n. 5
0
 def __getattr__(self, name):
     if name in self:
         return self[name]
     else:
         for k in self:
             if name == slugify(k, True):
                 return self[k]
Esempio n. 6
0
    def export(self, folder=None, name=None, format="hspy", save_std=False):
        """Save the data to a file.

        All the arguments are optional.

        Parameters
        ----------
        folder : str or None
            The path to the folder where the file will be saved.
             If `None` the current folder is used by default.
        name : str or None
            The name of the file. If `None` the Components name followed
             by the Parameter `name` attributes will be used by default.
              If a file with the same name exists the name will be
              modified by appending a number to the file path.
        save_std : bool
            If True, also the standard deviation will be saved
        format: str
            The extension of any file format supported by HyperSpy, default hspy

        """
        if format is None:
            format = "hspy"
        if name is None:
            name = self.component.name + '_' + self.name
        filename = incremental_filename(slugify(name) + '.' + format)
        if folder is not None:
            filename = os.path.join(folder, filename)
        self.as_signal().save(filename)
        if save_std is True:
            self.as_signal(field='std').save(append2pathname(filename, '_std'))
Esempio n. 7
0
 def export(self, folder=None, name=None, format=None, save_std=False):
     """Save the data to a file.
     
     All the arguments are optional.
     
     Parameters
     ----------
     folder : str or None
         The path to the folder where the file will be saved.
          If `None` the current folder is used by default.
     name : str or None
         The name of the file. If `None` the Components name followed
          by the Parameter `name` attributes will be used by default.
           If a file with the same name exists the name will be 
           modified by appending a number to the file path.
     save_std : bool
         If True, also the standard deviation will be saved
     
     """
     if format is None:
         format = preferences.General.default_export_format
     if name is None:
         name = self.component.name + "_" + self.name
     filename = incremental_filename(slugify(name) + "." + format)
     if folder is not None:
         filename = os.path.join(folder, filename)
     self.as_signal().save(filename)
     if save_std is True:
         self.as_signal(field="std").save(append2pathname(filename, "_std"))
Esempio n. 8
0
 def test_components_class_change_invalid_name(self):
     m = self.model
     g1 = hs.model.components1D.Gaussian()
     m.append(g1)
     g1.name = "1, Test This!"
     assert (getattr(m.components, slugify(g1.name,
                                           valid_variable_name=True)) is g1)
Esempio n. 9
0
 def __getattr__(self, name):
     if name in self:
         return self[name]
     else:
         for k in self:
             if name == slugify(k, True):
                 return self[k]
Esempio n. 10
0
 def __delattr__(self, name):
     if name in self:
         del self[name]
     else:
         for k in self:
             if name == slugify(k, True):
                 del self[k]
Esempio n. 11
0
    def export(self, folder=None, name=None, format="hspy",
               save_std=False):
        """Save the data to a file.

        All the arguments are optional.

        Parameters
        ----------
        folder : str or None
            The path to the folder where the file will be saved.
             If `None` the current folder is used by default.
        name : str or None
            The name of the file. If `None` the Components name followed
             by the Parameter `name` attributes will be used by default.
              If a file with the same name exists the name will be
              modified by appending a number to the file path.
        save_std : bool
            If True, also the standard deviation will be saved
        format: str
            The extension of any file format supported by HyperSpy, default hspy

        """
        if format is None:
            format = "hspy"
        if name is None:
            name = self.component.name + '_' + self.name
        filename = incremental_filename(slugify(name) + '.' + format)
        if folder is not None:
            filename = os.path.join(folder, filename)
        self.as_signal().save(filename)
        if save_std is True:
            self.as_signal(field='std').save(append2pathname(
                filename, '_std'))
Esempio n. 12
0
 def _set_name(self, value):
     old_value = self._name
     if self.model:
         for component in self.model:
             if value == component.name:
                 if not (component is self):
                     raise ValueError("Another component already has "
                                      "the name " + str(value))
         self._name = value
         setattr(self.model.components,
                 slugify(value, valid_variable_name=True), self)
         self.model.components.__delattr__(
             slugify(old_value, valid_variable_name=True))
     else:
         self._name = value
     self.trait_property_changed('name', old_value, self._name)
Esempio n. 13
0
 def _set_name(self, value):
     old_value = self._name
     if self.model:
         for component in self.model:
             if value == component.name:
                 if not (component is self):
                     raise ValueError(
                         "Another component already has "
                         "the name " + str(value))
         self._name = value
         setattr(self.model.components, slugify(
             value, valid_variable_name=True), self)
         self.model.components.__delattr__(
             slugify(old_value, valid_variable_name=True))
     else:
         self._name = value
     self.trait_property_changed('name', old_value, self._name)
Esempio n. 14
0
 def test_components_class_change_name_del_default(self):
     m = self.model
     g1 = hs.model.components.Gaussian()
     m.append(g1)
     invalid_name = "1, Test This!"
     g1.name = invalid_name
     g1.name = "test"
     getattr(m.components, slugify(invalid_name))
Esempio n. 15
0
 def test_components_class_change_name_del_default(self):
     m = self.model
     g1 = hs.model.components1D.Gaussian()
     m.append(g1)
     invalid_name = "1, Test This!"
     g1.name = invalid_name
     g1.name = "test"
     getattr(m.components, slugify(invalid_name))
Esempio n. 16
0
 def test_components_class_change_invalid_name(self):
     m = self.model
     g1 = hs.model.components.Gaussian()
     m.append(g1)
     g1.name = "1, Test This!"
     nt.assert_is(
         getattr(m.components,
                 slugify(g1.name, valid_variable_name=True)), g1)
Esempio n. 17
0
 def test_components_class_change_name_del_default(self):
     m = self.model
     g1 = hs.model.components1D.Gaussian()
     m.append(g1)
     invalid_name = "1, Test This!"
     g1.name = invalid_name
     g1.name = "test"
     with pytest.raises(AttributeError):
         getattr(m.components, slugify(invalid_name))
Esempio n. 18
0
 def __setattr__(self, name, value):
     if name in self:
         self[name] = value
     else:
         for k in self:
             if name == slugify(k, True):
                 self[k] = value
         else:
             self[name] = value
Esempio n. 19
0
 def __setattr__(self, name, value):
     if name in self:
         self[name] = value
     else:
         for k in self:
             if name == slugify(k, True):
                 self[k] = value
         else:
             self[name] = value
Esempio n. 20
0
 def test_components_class_change_name_del_default2(self):
     m = self.model
     g1 = hs.model.components1D.Gaussian()
     m.append(g1)
     invalid_name = "1, Test This!"
     g1.name = invalid_name
     g1.name = "test"
     with pytest.raises(AttributeError):
         getattr(m.components, slugify(invalid_name))
Esempio n. 21
0
    def backup(self, filename=None, on_count=True):
        """Backs-up the samfire results in a file

        Parameters
        ----------
        filename: {str, None}
            the filename. If None, a default value of "backup\_"+signal_title
            is used.
        on_count: bool
            if True (default), only saves on the required count of steps
        """
        if filename is None:
            title = self.model.signal.metadata.General.title
            filename = slugify('backup_' + title)
        # maybe add saving marker + strategies as well?
        if self.count % self.save_every == 0 or not on_count:
            self.model.save(filename, name='samfire_backup', overwrite=True)
            self.model.signal.models.remove('samfire_backup')
Esempio n. 22
0
    def backup(self, filename=None, on_count=True):
        """Backs-up the samfire results in a file

        Parameters
        ----------
        filename: {str, None}
            the filename. If None, a default value of "backup_"+signal_title is
            used
        on_count: bool
            if True (default), only saves on the required count of steps
        """
        if filename is None:
            title = self.model.signal.metadata.General.title
            filename = slugify('backup_' + title)
        # maybe add saving marker + strategies as well?
        if self.count % self.save_every == 0 or not on_count:
            self.model.save(filename,
                            name='samfire_backup', overwrite=True)
            self.model.signal.models.remove('samfire_backup')
Esempio n. 23
0
def test_slugify():
    nose.tools.assert_equal(slugify('ab !@#_ ja &(]'), u'ab___ja')
Esempio n. 24
0
def test_slugify():
    assert slugify("a") == "a"
    assert slugify("1a") == "1a"
    assert slugify("1") == "1"
    assert slugify("a a") == "a_a"
    assert slugify(42) == "42"
    assert slugify(3.14159) == "314159"
    assert slugify("├── Node1") == "Node1"

    assert slugify("a", valid_variable_name=True) == "a"
    assert slugify("1a", valid_variable_name=True) == "Number_1a"
    assert slugify("1", valid_variable_name=True) == "Number_1"

    assert slugify("a", valid_variable_name=False) == "a"
    assert slugify("1a", valid_variable_name=False) == "1a"
    assert slugify("1", valid_variable_name=False) == "1"
Esempio n. 25
0
 def __dir__(self):
     return [slugify(k, True) for k in self]
Esempio n. 26
0
 def __dir__(self):
     return [slugify(k, True) for k in self]
Esempio n. 27
0
def test_slugify():
    nose.tools.assert_equal(slugify("ab !@#_ ja &(]"), "ab___ja")
Esempio n. 28
0
def test_slugify():
    assert slugify('ab !@#_ ja &(]') == 'ab___ja'