Skip to content

Commit

Permalink
widgets/tests: Fix tests for OWFile
Browse files Browse the repository at this point in the history
* Use full local file url (with file: schema).
  On Qt5 QUrl("/abs/path") is not considered to be a local file
* Use `os.path.samepath` to check path equality (windows)
  • Loading branch information
ales-erjavec committed Oct 27, 2016
1 parent e9e0330 commit 888b505
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from Orange.widgets.data.owfile import OWFile
from Orange.widgets.tests.base import WidgetTest

TITANIC_URL = path.join(path.dirname(Orange.__file__), 'datasets', 'titanic.tab')
TITANIC_PATH = path.join(path.dirname(Orange.__file__), 'datasets', 'titanic.tab')


class TestOWFile(WidgetTest):
Expand All @@ -22,17 +22,17 @@ def setUp(self):
self.widget = self.create_widget(OWFile)

def test_dragEnterEvent_accepts_urls(self):
event = self._drag_enter_event(TITANIC_URL)
event = self._drag_enter_event(QUrl.fromLocalFile(TITANIC_PATH))
self.widget.dragEnterEvent(event)
self.assertTrue(event.isAccepted())

def test_dragEnterEvent_skips_osx_file_references(self):
event = self._drag_enter_event('/.file/id=12345')
event = self._drag_enter_event(QUrl.fromLocalFile('/.file/id=12345'))
self.widget.dragEnterEvent(event)
self.assertFalse(event.isAccepted())

def test_dragEnterEvent_skips_usupported_files(self):
event = self._drag_enter_event('file.unsupported')
event = self._drag_enter_event(QUrl.fromLocalFile('file.unsupported'))
self.widget.dragEnterEvent(event)
self.assertFalse(event.isAccepted())

Expand All @@ -48,11 +48,11 @@ def test_dropEvent_selects_file(self):
self.widget.load_data = Mock()
self.widget.source = OWFile.URL

event = self._drop_event(TITANIC_URL)
event = self._drop_event(QUrl.fromLocalFile(TITANIC_PATH))
self.widget.dropEvent(event)

self.assertEqual(self.widget.source, OWFile.LOCAL_FILE)
self.assertEqual(self.widget.last_path(), TITANIC_URL)
self.assertTrue(path.samefile(self.widget.last_path(), TITANIC_PATH))
self.widget.load_data.assert_called_with()

def _drop_event(self, url):
Expand Down

0 comments on commit 888b505

Please sign in to comment.