Skip to content

Commit

Permalink
test_owcsvimport: Fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Aug 5, 2021
1 parent a51bdea commit 4b7c66e
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions Orange/widgets/data/tests/test_owcsvimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_basic(self):
data_regions_options = owcsvimport.Options(
encoding="ascii", dialect=csv.excel_tab(),
columntypes=[
(range(0, 1), ColumnType.Categorical),
(range(0, 1), ColumnType.Numeric),
(range(1, 2), ColumnType.Text),
(range(2, 3), ColumnType.Categorical),
], rowspec=[
Expand All @@ -90,10 +90,10 @@ def test_basic(self):
def _check_data_regions(self, table):
self.assertEqual(len(table), 3)
self.assertEqual(len(table), 3)
self.assertTrue(table.domain["id"].is_discrete)
self.assertTrue(table.domain["id"].is_continuous)
self.assertTrue(table.domain["continent"].is_discrete)
self.assertTrue(table.domain["state"].is_string)
assert_array_equal(table.X, [[0, 1], [1, 1], [2, 0]])
assert_array_equal(table.X, [[1, 1], [2, 1], [3, 0]])
assert_array_equal(table.metas,
np.array([["UK"], ["Russia"], ["Mexico"]], object))

Expand Down Expand Up @@ -253,34 +253,22 @@ def test_browse(self):
cur = widget.current_item()
self.assertIsNotNone(cur)
self.assertTrue(samepath(cur.path(), path))
self.assertIsInstance(cur.varPath(), PathItem.AbsPath)

def test_browse_prefix(self):
def test_browse_relative(self):
widget = self.widget
path = self.data_regions_path
with self._browse_setup(widget, path):
basedir = os.path.dirname(__file__)
widget.workflowEnv = lambda: {"basedir": basedir}
widget.workflowEnvChanged("basedir", basedir, "")
widget.browse_relative(prefixname="basedir")
widget.browse()

cur = widget.current_item()
self.assertIsNotNone(cur)
self.assertTrue(samepath(cur.path(), path))
self.assertIsInstance(cur.varPath(), PathItem.VarPath)

def test_browse_prefix_parent(self):
widget = self.widget
path = self.data_regions_path

with self._browse_setup(widget, path):
basedir = os.path.join(os.path.dirname(__file__), "bs")
widget.workflowEnv = lambda: {"basedir": basedir}
widget.workflowEnvChanged("basedir", basedir, "")
mb = widget._path_must_be_relative_mb = mock.Mock()
widget.browse_relative(prefixname="basedir")
mb.assert_called()
self.assertIsNone(widget.current_item())

def test_browse_for_missing(self):
missing = os.path.dirname(__file__) + "/this file does not exist.csv"
widget = self.create_widget(
Expand Down Expand Up @@ -375,6 +363,7 @@ def test_unsafe_cast_warning(self):
self.process_events(until=lambda: w.data is not None)
index = w.domain_editor.model().index(0, 1)
w.domain_editor.model().setData(index, 'text')
w.apply_domain_edit()
self.assertTrue(w.Warning.numeric_cast.is_shown())


Expand Down

0 comments on commit 4b7c66e

Please sign in to comment.