Skip to content

Commit

Permalink
Added tests and removed unnecessary imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lenatr99 committed May 29, 2024
1 parent 2d5bb04 commit dd245da
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
50 changes: 50 additions & 0 deletions orangecontrib/single_cell/tests/test_owspatialautocorrelation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import unittest
from Orange.data import Table
from Orange.widgets.tests.base import WidgetTest
from orangecontrib.single_cell.widgets.owspatialautocorrelation import OWSpatialAutocorrelation
from Orange.widgets.utils.concurrent import TaskState


class TestOWSpatialAutocorrelation(WidgetTest):
def setUp(self):
self.widget = self.create_widget(OWSpatialAutocorrelation)

def test_input_data(self):
data = Table("iris")
self.widget.set_data(data)
self.assertEqual(self.widget.data, data)

def test_feature_selection(self):
data = Table("iris")
self.widget.set_data(data)
self.widget.feature_x_combo.setCurrentIndex(1)
self.widget.feature_y_combo.setCurrentIndex(2)
self.assertEqual(self.widget.feature_x, "sepal width")
self.assertEqual(self.widget.feature_y, "petal length")

def test_method_selection(self):
self.widget.method = "Geary C"
self.assertEqual(self.widget.method, "Geary C")

def test_k_neighbors_input(self):
self.widget.k_input.setText("10")
self.widget._on_k_changed()
self.assertEqual(self.widget.k_neighbors, 10)

def test_auto_commit(self):
self.widget.auto_commit = False
self.assertFalse(self.widget.auto_commit)

def test_calculate(self):
data = Table("iris")
self.widget.set_data(data)
self.widget.feature_x_combo.setCurrentIndex(0)
self.widget.feature_y_combo.setCurrentIndex(1)
self.widget.k_input.setText("5")
self.widget._on_k_changed()
self.widget.calculate(TaskState())
self.assertIsNotNone(self.widget.adjacency_matrix)


if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions orangecontrib/single_cell/widgets/owspatialautocorrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from AnyQt.QtCore import Qt
from AnyQt.QtGui import QIntValidator
from AnyQt.QtWidgets import QApplication, QComboBox, QVBoxLayout, QWidget, QLineEdit
from AnyQt.QtWidgets import QApplication, QComboBox, QLineEdit

from Orange.data import Table, ContinuousVariable
from Orange.widgets import gui
from Orange.widgets.settings import ContextSetting, Setting, DomainContextHandler
from Orange.widgets.settings import Setting, DomainContextHandler
from Orange.widgets.widget import Input, Output, Msg, OWWidget
from Orange.preprocess import score
from Orange.widgets.utils.concurrent import ConcurrentWidgetMixin, TaskState
Expand Down

0 comments on commit dd245da

Please sign in to comment.