def __init__(self, parent=None): super().__init__(parent) self._lineparser = lineparser.AppendLineParser(standarddir.data(), 'history', parent=self) self._history_dict = collections.OrderedDict() with self._lineparser.open(): for line in self._lineparser: data = line.rstrip().split(maxsplit=1) if not data: # empty line continue elif len(data) != 2: # other malformed line log.init.warning( "Invalid history entry {!r}!".format(line)) continue atime, url = data # This de-duplicates history entries; only the latest # entry for each URL is kept. If you want to keep # information about previous hits change the items in # old_urls to be lists or change HistoryEntry to have a # list of atimes. self._history_dict[url] = HistoryEntry(atime, url) self._history_dict.move_to_end(url) self._new_history = [] self._saved_count = 0 objreg.get('save-manager').add_saveable('history', self.save, self.item_added)
def test_iter_not_found(self, open_mock): """Test __iter__ with no file.""" open_mock.side_effect = FileNotFoundError linep = lineparser.AppendLineParser('foo', 'bar') linep.new_data = ['new data 1', 'new data 2'] expected_data = linep.new_data with linep.open(): self.assertEqual(list(linep), expected_data)
def test_iter_not_found(self, mocker): """Test __iter__ with no file.""" open_mock = mocker.patch( 'qutebrowser.misc.lineparser.AppendLineParser._open') open_mock.side_effect = FileNotFoundError new_data = ['new data 1', 'new data 2'] linep = lineparsermod.AppendLineParser('foo', 'bar') linep.new_data = new_data with linep.open(): assert list(linep) == new_data
def __init__(self, hist_dir, hist_name, parent=None): super().__init__(parent) self._initial_read_started = False self._initial_read_done = False self._lineparser = lineparser.AppendLineParser(hist_dir, hist_name, parent=self) self.history_dict = collections.OrderedDict() self._temp_history = collections.OrderedDict() self._new_history = [] self._saved_count = 0 objreg.get('save-manager').add_saveable( 'history', self.save, self.item_added)
def lineparser(self, tmpdir): """Fixture to get an AppendLineParser for tests.""" lp = lineparsermod.AppendLineParser(str(tmpdir), 'file') lp.new_data = self.BASE_DATA lp.save() return lp
def test_get_recent_none(self, tmpdir): """Test get_recent with no data.""" (tmpdir / 'file2').ensure() linep = lineparsermod.AppendLineParser(str(tmpdir), 'file2') assert linep.get_recent() == []