Skip to content

Commit 86d1fa7

Browse files
committed
Test str(table)
1 parent faba20a commit 86d1fa7

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Orange/tests/test_table.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,10 @@ def test_repr_sparse_with_one_row(self):
11821182
table = data.Table("iris")[:1]
11831183
with table.unlocked_reference():
11841184
table.X = sp.csr_matrix(table.X)
1185-
repr(table) # make sure repr does not crash
1185+
r = repr(table) # make sure repr does not crash
1186+
self.assertEqual(r.replace("\n", ""),
1187+
"[[sepal length=5.1, sepal width=3.5, "
1188+
"petal length=1.4, petal width=0.2 | Iris-setosa]]")
11861189

11871190
def test_inf(self):
11881191
a = np.array([[2, 0, 0, 0],
@@ -1192,6 +1195,34 @@ def test_inf(self):
11921195
tab = data.Table.from_numpy(None, a)
11931196
self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)
11941197

1198+
def test_str(self):
1199+
iris = Table("iris")
1200+
# instance
1201+
self.assertEqual("[5.1, 3.5, 1.4, 0.2 | Iris-setosa]", str(iris[0]))
1202+
# table
1203+
table_str = str(iris)
1204+
lines = table_str.split('\n')
1205+
self.assertEqual(150, len(lines))
1206+
self.assertEqual("[[5.1, 3.5, 1.4, 0.2 | Iris-setosa],", lines[0])
1207+
self.assertEqual(" [5.9, 3.0, 5.1, 1.8 | Iris-virginica]]", lines[-1])
1208+
1209+
def test_str_sparse(self):
1210+
iris = Table("iris")
1211+
with iris.unlocked_reference():
1212+
iris.X = sp.csr_matrix(iris.X)
1213+
# instance
1214+
s0 = "[sepal length=5.1, sepal width=3.5, " \
1215+
"petal length=1.4, petal width=0.2 | Iris-setosa]"
1216+
self.assertEqual(s0, str(iris[0]))
1217+
# table
1218+
table_str = str(iris)
1219+
lines = table_str.split('\n')
1220+
self.assertEqual(150, len(lines))
1221+
self.assertEqual("[" + s0 + ",", lines[0])
1222+
slast = "[sepal length=5.9, sepal width=3.0, " \
1223+
"petal length=5.1, petal width=1.8 | Iris-virginica]"
1224+
self.assertEqual(" " + slast + "]", lines[-1])
1225+
11951226

11961227
def column_sizes(table):
11971228
return (len(table.domain.attributes),

0 commit comments

Comments
 (0)