Exemplo n.º 1
0
    def _init_neighborlist(self) -> None:
        """Initialize self._neighborlist.

        It is a NeighborList with the zoom levels."""
        levels = config.val.zoom.levels
        self._neighborlist = usertypes.NeighborList(
            levels, mode=usertypes.NeighborList.Modes.edge)
        self._neighborlist.fuzzyval = config.val.zoom.default
Exemplo n.º 2
0
    def start(self, text):
        """Start browsing to the history.

        Called when the user presses the up/down key and wasn't browsing the
        history already.

        Args:
            text: The preset text.
        """
        log.misc.debug("Preset text: '{}'".format(text))
        if text:
            items = [e for e in self.history if e.startswith(text)]
        else:
            items = self.history
        if not items:
            raise HistoryEmptyError
        self._tmphist = usertypes.NeighborList(items)
        return self._tmphist.lastitem()
Exemplo n.º 3
0
 def neighborlist(self):
     return usertypes.NeighborList()
Exemplo n.º 4
0
 def test_invalid_reset(self):
     """Test reset without default."""
     nl = usertypes.NeighborList([1, 2, 3, 4, 5])
     with pytest.raises(ValueError):
         nl.reset()
Exemplo n.º 5
0
 def test_unset(self):
     """Test unset default value."""
     nl = usertypes.NeighborList([1, 2, 3])
     assert nl._idx is None
Exemplo n.º 6
0
 def test_none(self):
     """Test default 'None'."""
     nl = usertypes.NeighborList([1, 2, None], default=None)
     assert nl._idx == 2
Exemplo n.º 7
0
 def test_simple(self):
     """Test default with a numeric argument."""
     nl = usertypes.NeighborList([1, 2, 3], default=2)
     assert nl._idx == 1
Exemplo n.º 8
0
 def test_invalid_mode(self):
     """Test with an invalid mode."""
     with pytest.raises(TypeError):
         usertypes.NeighborList(mode='blah')
Exemplo n.º 9
0
 def test_contains(self):
     """Test 'in' on NeighborList."""
     nl = usertypes.NeighborList([1, 2, 3])
     assert 2 in nl
     assert 4 not in nl
Exemplo n.º 10
0
 def test_len(self):
     """Test len() on NeighborList."""
     nl = usertypes.NeighborList([1, 2, 3])
     assert len(nl) == 3
Exemplo n.º 11
0
 def test_items(self):
     """Test constructing a NeighborList with items."""
     nl = usertypes.NeighborList([1, 2, 3])
     assert nl.items == [1, 2, 3]
Exemplo n.º 12
0
 def test_empty(self):
     """Test constructing an empty NeighborList."""
     nl = usertypes.NeighborList()
     assert nl.items == []
Exemplo n.º 13
0
 def neighborlist(self):
     return usertypes.NeighborList([20, 9, 1, 5])
Exemplo n.º 14
0
 def neighborlist(self):
     return usertypes.NeighborList(
         [1, 2, 3, 4, 5],
         default=3,
         mode=usertypes.NeighborList.Modes.exception)
Exemplo n.º 15
0
 def neighborlist(self):
     return usertypes.NeighborList([1], default=1)
Exemplo n.º 16
0
 def neighborlist(self):
     return usertypes.NeighborList([1, 2, 3, 4, 5], default=3)