Skip to content

Commit

Permalink
Merge pull request #159 from PrimozGodec/fix-tests
Browse files Browse the repository at this point in the history
Fix failing tests
  • Loading branch information
PrimozGodec committed Apr 3, 2023
2 parents 982eca8 + 2185930 commit 474dcf6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 48 deletions.
24 changes: 5 additions & 19 deletions orangecontrib/educational/widgets/ow1ka.py
Expand Up @@ -20,20 +20,7 @@
from Orange.data import Table
from Orange.widgets.utils.signals import Output
from Orange.widgets.utils.webview import WebviewWidget
try:
from Orange.widgets.utils.webview import wait
except ImportError: # WebKit and before wait() was toplevel
import time
from AnyQt.QtWidgets import qApp
from AnyQt.QtCore import QEventLoop

def wait(until: callable, timeout=5000):
started = time.perf_counter()
while not until():
qApp.processEvents(QEventLoop.ExcludeUserInputEvents)
if (time.perf_counter() - started) * 1000 > timeout:
raise TimeoutError()

from orangewidget.utils.webview import wait

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -353,8 +340,7 @@ def set_info(self):


if __name__ == "__main__":
a = QApplication([])
ow = OW1ka()
ow.combo.setEditText('https://www.1ka.si/podatki/139234/A4228E24/')
ow.show()
a.exec_()
from orangewidget.utils.widgetpreview import WidgetPreview

# use link: https://www.1ka.si/podatki/139234/A4228E24/
widget_preview = WidgetPreview(OW1ka).run()
6 changes: 3 additions & 3 deletions orangecontrib/educational/widgets/owgradientdescent.py
Expand Up @@ -307,12 +307,12 @@ def disable_controls(self, disabled):
self.restart_button, self.properties_box, self.options_box]:
item.setDisabled(disabled)

key_actions = {(0, Qt.Key_Space): step} # space button for step
key_actions = {(Qt.NoModifier, Qt.Key_Space): step} # space button for step

def keyPressEvent(self, e):
"""Bind 'back' key to step back"""
if (int(e.modifiers()), e.key()) in self.key_actions:
fun = self.key_actions[(int(e.modifiers()), e.key())]
if (e.modifiers(), e.key()) in self.key_actions:
fun = self.key_actions[(e.modifiers(), e.key())]
fun(self)
else:
super().keyPressEvent(e)
Expand Down
3 changes: 1 addition & 2 deletions orangecontrib/educational/widgets/owkmeans.py
Expand Up @@ -613,8 +613,7 @@ def _prepare_data(self):
Return None if there are no non-nan columns
"""
attrs = [self.attr_x, self.attr_y]
x = np.vstack(tuple(self.data.get_column_view(attr)[0]
for attr in attrs)).T
x = np.vstack(tuple(self.data.get_column(attr) for attr in attrs)).T
not_nan = ~np.isnan(x).any(axis=1)
x = x[not_nan] # remove rows with nan
if not x.size:
Expand Down
Expand Up @@ -82,7 +82,7 @@ def __call__(self, data):
elif inst:
data_col = np.array([float(data[attr_index])])
else:
data_col = data.get_column_view(attr_index)[0]
data_col = data.get_column(attr_index)
data_all.append(data_col)
transformed_col = self.transform(data_all)
if (inst and isinstance(transformed_col, np.ndarray) and
Expand Down
Expand Up @@ -43,30 +43,31 @@ def test_plynomial_transform(self):
transformed_data = polynomial_transform(self.data)

for i, row in enumerate(transformed_data):
self.assertEqual(row[0], self.data[i][0])
self.assertEqual(row[1], self.data[i][1])
self.assertAlmostEqual(row[0], self.data[i][0])
self.assertAlmostEqual(row[1], self.data[i][1])

self.assertEqual(row[2], self.data[i][0] ** 2)
self.assertEqual(row[3], self.data[i][0] * self.data[i][1])
self.assertEqual(row[4], self.data[i][1] ** 2)
self.assertAlmostEqual(row[2], self.data[i][0] ** 2)
self.assertAlmostEqual(row[3], self.data[i][0] * self.data[i][1])
self.assertAlmostEqual(row[4], self.data[i][1] ** 2)

self.assertEqual(row[5], self.data[i][0] ** 3)
self.assertEqual(row[6], self.data[i][0] ** 2 * self.data[i][1])
self.assertEqual(row[7], self.data[i][0] * self.data[i][1] ** 2)
self.assertEqual(row[8], self.data[i][1] ** 3)
self.assertAlmostEqual(row[5], self.data[i][0] ** 3)
self.assertAlmostEqual(row[6], self.data[i][0] ** 2 * self.data[i][1])
self.assertAlmostEqual(row[7], self.data[i][0] * self.data[i][1] ** 2)
self.assertAlmostEqual(row[8], self.data[i][1] ** 3)

self.assertEqual(row[9], self.data[i][0] ** 4)
self.assertEqual(row[10], self.data[i][0] ** 3 * self.data[i][1])
self.assertEqual(
row[11], self.data[i][0] ** 2 * self.data[i][1] ** 2)
self.assertEqual(row[12], self.data[i][0] * self.data[i][1] ** 3)
self.assertEqual(row[13], self.data[i][1] ** 4)
self.assertAlmostEqual(row[9], self.data[i][0] ** 4)
self.assertAlmostEqual(row[10], self.data[i][0] ** 3 * self.data[i][1])
self.assertAlmostEqual(row[11], self.data[i][0] ** 2 * self.data[i][1] ** 2)
self.assertAlmostEqual(row[12], self.data[i][0] * self.data[i][1] ** 3)
self.assertAlmostEqual(row[13], self.data[i][1] ** 4)

self.assertEqual(row[14], self.data[i][0] ** 5)
self.assertEqual(row[15], self.data[i][0] ** 4 * self.data[i][1])
self.assertEqual(
row[16], self.data[i][0] ** 3 * self.data[i][1] ** 2)
self.assertEqual(
row[17], self.data[i][0] ** 2 * self.data[i][1] ** 3)
self.assertEqual(row[18], self.data[i][0] * self.data[i][1] ** 4)
self.assertEqual(row[19], self.data[i][1] ** 5)
self.assertAlmostEqual(row[14], self.data[i][0] ** 5)
self.assertAlmostEqual(row[15], self.data[i][0] ** 4 * self.data[i][1])
self.assertAlmostEqual(row[16], self.data[i][0] ** 3 * self.data[i][1] ** 2)
self.assertAlmostEqual(row[17], self.data[i][0] ** 2 * self.data[i][1] ** 3)
self.assertAlmostEqual(row[18], self.data[i][0] * self.data[i][1] ** 4)
self.assertAlmostEqual(row[19], self.data[i][1] ** 5)


if __name__ == "__main__":
unittest.main()

0 comments on commit 474dcf6

Please sign in to comment.