Skip to content

Commit

Permalink
Merge pull request #1698 from ales-erjavec/test-fixes
Browse files Browse the repository at this point in the history
[FIX] Fix tests
  • Loading branch information
astaric authored Nov 2, 2016
2 parents 7549c97 + d78d5dc commit 3d865bc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
9 changes: 5 additions & 4 deletions Orange/canvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
Qt, QEvent, QSize, QUrl, QTimer, QFile, QByteArray, QSettings, QT_VERSION
)

if QT_VERSION < 0x50500:
try:
from AnyQt.QtWebEngineWidgets import QWebEngineView
USE_WEB_ENGINE = True
except ImportError:
from AnyQt.QtWebKitWidgets import QWebView
from AnyQt.QtNetwork import QNetworkDiskCache
USE_WEB_ENGINE = False
else:
from PyQt5.QtWebEngineWidgets import QWebEngineView
USE_WEB_ENGINE = True


from AnyQt.QtCore import pyqtProperty as Property

Expand Down
7 changes: 5 additions & 2 deletions Orange/tests/sql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import Orange
from Orange.data.sql.table import SqlTable
from Orange.data.sql.backend.postgres import Psycopg2Backend
from psycopg2.pool import ThreadedConnectionPool


def sql_test(f):
Expand Down Expand Up @@ -150,13 +148,17 @@ def assertDictContainsSubset(self, subset, dictionary, msg=None):
class PostgresTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
from psycopg2.pool import ThreadedConnectionPool
from Orange.data.sql.backend.postgres import Psycopg2Backend

Psycopg2Backend.connection_pool = \
ThreadedConnectionPool(1, 1, **connection_params())
cls.backend = Psycopg2Backend(connection_params())
cls.conn, cls.iris = create_iris()

@classmethod
def tearDownClass(cls):
from Orange.data.sql.backend.postgres import Psycopg2Backend
Psycopg2Backend.connection_pool.closeall()
Psycopg2Backend.connection_pool = None

Expand All @@ -166,6 +168,7 @@ def create_sql_table(self, data, columns=None):

@contextlib.contextmanager
def sql_table_from_data(self, data, guess_values=True):
from Orange.data.sql.backend.postgres import Psycopg2Backend
assert Psycopg2Backend.connection_pool is not None

table_name = self._create_sql_table(data)
Expand Down
14 changes: 12 additions & 2 deletions Orange/tests/sql/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
Please note that such use is deprecated.
"""
import unittest

from Orange.data.sql.table import SqlTable
from Orange.preprocess import Discretize
from Orange.preprocess.discretize import EqualFreq
from Orange.tests.sql.base import PostgresTest
from Orange.widgets.visualize.owmosaic import get_conditional_distribution
from Orange.widgets.visualize.utils.lac import create_sql_contingency, get_bin_centers
try:
from Orange.widgets.visualize.owmosaic import get_conditional_distribution
from Orange.widgets.visualize.utils.lac import \
create_sql_contingency, get_bin_centers
except ImportError:
no_widgets = True
else:
no_widgets = False


class MiscSqlTests(PostgresTest):
Expand All @@ -16,12 +24,14 @@ def test_discretization(self):
sepal_length = iris.domain["sepal length"]
EqualFreq(n=4)(iris, sepal_length)

@unittest.skipIf(no_widgets, "Cannot import widgets")
def test_get_conditional_distribution(self):
iris = SqlTable(self.conn, self.iris, inspect_values=True)
sepal_length = iris.domain["sepal length"]
get_conditional_distribution(iris, [sepal_length])
get_conditional_distribution(iris, list(iris.domain))

@unittest.skipIf(no_widgets, "Cannot import widgets")
def test_create_sql_contingency(self):
iris = SqlTable(self.conn, self.iris, inspect_values=True)
d_iris = Discretize()(iris)
Expand Down
3 changes: 2 additions & 1 deletion Orange/tests/test_manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def __lle_test_helper(self, data, n_com):
lle = lle(data)

ltsa = LocallyLinearEmbedding(n_neighbors=5, n_components=n_com,
method="ltsa")
method="ltsa",
eigen_solver="dense")
ltsa = ltsa(data)

hessian = LocallyLinearEmbedding(n_neighbors=15, n_components=n_com,
Expand Down
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 3d865bc

Please sign in to comment.