def parse(path):
            html = filescheme.dirbrowser_html(path).decode('utf-8')
            soup = bs4.BeautifulSoup(html, 'html.parser')

            with testutils.ignore_bs4_warning():
                print(soup.prettify())

            container = soup('div', id='dirbrowserContainer')[0]

            parent_elem = container('ul', class_='parent')
            if not parent_elem:
                parent = None
            else:
                parent = parent_elem[0].li.a.string

            folders = []
            files = []

            for li in container('ul', class_='folders')[0]('li'):
                item = self.Item(link=li.a['href'], text=str(li.a.string))
                folders.append(item)

            for li in container('ul', class_='files')[0]('li'):
                item = self.Item(link=li.a['href'], text=str(li.a.string))
                files.append(item)

            return self.Parsed(parent=parent, folders=folders, files=files)
Beispiel #2
0
 def test_dir(self, tmpdir):
     url = QUrl.fromLocalFile(str(tmpdir))
     req = QNetworkRequest(url)
     reply = filescheme.handler(req, None, None)
     # The URL will always use /, even on Windows - so we force this here
     # too.
     tmpdir_path = str(tmpdir).replace(os.sep, '/')
     assert reply.readAll() == filescheme.dirbrowser_html(tmpdir_path)
Beispiel #3
0
 def test_dir(self, tmpdir):
     url = QUrl.fromLocalFile(str(tmpdir))
     req = QNetworkRequest(url)
     reply = filescheme.handler(req, None, None)
     # The URL will always use /, even on Windows - so we force this here
     # too.
     tmpdir_path = str(tmpdir).replace(os.sep, '/')
     assert reply.readAll() == filescheme.dirbrowser_html(tmpdir_path)
Beispiel #4
0
 def test_oserror(self, mocker):
     m = mocker.patch('qutebrowser.browser.webkit.network.filescheme.'
                      'os.listdir')
     m.side_effect = OSError('Error message')
     html = filescheme.dirbrowser_html('').decode('utf-8')
     soup = bs4.BeautifulSoup(html, 'html.parser')
     print(soup.prettify())
     error_msg = soup('p', id='error-message-text')[0].string
     assert error_msg == 'Error message'
Beispiel #5
0
 def test_basic(self):
     html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
     soup = bs4.BeautifulSoup(html, 'html.parser')
     print(soup.prettify())
     container = soup.div
     assert container['id'] == 'dirbrowserContainer'
     title_elem = container('div', id='dirbrowserTitle')[0]
     title_text = title_elem('p', id='dirbrowserTitleText')[0].text
     assert title_text == 'Browse directory: {}'.format(os.getcwd())
Beispiel #6
0
 def test_oserror(self, mocker):
     m = mocker.patch('qutebrowser.browser.webkit.network.filescheme.'
                      'os.listdir')
     m.side_effect = OSError('Error message')
     html = filescheme.dirbrowser_html('').decode('utf-8')
     soup = bs4.BeautifulSoup(html, 'html.parser')
     print(soup.prettify())
     error_msg = soup('p', id='error-message-text')[0].string
     assert error_msg == 'Error message'
Beispiel #7
0
 def test_basic(self):
     html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
     soup = bs4.BeautifulSoup(html, 'html.parser')
     print(soup.prettify())
     container = soup.div
     assert container['id'] == 'dirbrowserContainer'
     title_elem = container('div', id='dirbrowserTitle')[0]
     title_text = title_elem('p', id='dirbrowserTitleText')[0].text
     assert title_text == 'Browse directory: {}'.format(os.getcwd())
    def test_icons(self, monkeypatch):
        """Make sure icon paths are correct file:// URLs."""
        html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
        soup = bs4.BeautifulSoup(html, 'html.parser')

        with testutils.ignore_bs4_warning():
            print(soup.prettify())

        css = soup.html.head.style.string
        assert "background-image: url('qute://resource/img/folder.svg');" in css
Beispiel #9
0
    def test_icons(self, monkeypatch):
        """Make sure icon paths are correct file:// URLs."""
        monkeypatch.setattr(filescheme.jinja.utils, 'resource_filename',
                            lambda name: '/test path/foo.svg')

        html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
        soup = bs4.BeautifulSoup(html, 'html.parser')
        print(soup.prettify())

        css = soup.html.head.style.string
        assert "background-image: url('file:///test%20path/foo.svg');" in css
Beispiel #10
0
    def test_icons(self, monkeypatch):
        """Make sure icon paths are correct file:// URLs."""
        monkeypatch.setattr(filescheme.jinja.utils, 'resource_filename',
                            lambda name: '/test path/foo.svg')

        html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
        soup = bs4.BeautifulSoup(html, 'html.parser')
        print(soup.prettify())

        css = soup.html.head.style.string
        assert "background-image: url('file:///test%20path/foo.svg');" in css
Beispiel #11
0
        def parse(path):
            html = filescheme.dirbrowser_html(path).decode('utf-8')
            soup = bs4.BeautifulSoup(html, 'html.parser')
            print(soup.prettify())
            container = soup('div', id='dirbrowserContainer')[0]

            parent_elem = container('ul', class_='parent')
            if not parent_elem:
                parent = None
            else:
                parent = parent_elem[0].li.a.string

            folders = []
            files = []

            for li in container('ul', class_='folders')[0]('li'):
                item = self.Item(link=li.a['href'], text=str(li.a.string))
                folders.append(item)

            for li in container('ul', class_='files')[0]('li'):
                item = self.Item(link=li.a['href'], text=str(li.a.string))
                files.append(item)

            return self.Parsed(parent=parent, folders=folders, files=files)