File: test_filedialogs.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (28 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from AnyQt.QtCore import QUrl, QMimeData

from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.tests.utils import dragDrop
from Orange.widgets.utils.filedialogs import OWUrlDropBase


class TestOWUrlDropBase(WidgetTest):
    def test_drop(self):
        class TestW(OWUrlDropBase):
            path = None

            def canDropUrl(self, url: QUrl) -> bool:
                return url.toLocalFile().endswith(".foo")

            def handleDroppedUrl(self, url: QUrl) -> None:
                self.path = url.toLocalFile()

        w = self.create_widget(TestW)
        url = QUrl("file:///bar.foo")
        mime = QMimeData()
        mime.setUrls([url])
        self.assertTrue(dragDrop(w, mime))
        self.assertEqual(w.path, url.toLocalFile())
        url = QUrl("file:///bar.baz")
        mime.setUrls([url])
        self.assertFalse(dragDrop(w, mime))
        self.assertNotEqual(w.path, url.toLocalFile())