|
2 | 2 | # pylint: disable=missing-docstring |
3 | 3 |
|
4 | 4 | import unittest |
| 5 | +import unittest.mock |
5 | 6 |
|
6 | 7 | import numpy as np |
7 | 8 | from numpy.testing import assert_almost_equal |
8 | 9 |
|
9 | 10 | from Orange.data import filter, ContinuousVariable, DiscreteVariable, \ |
10 | | - StringVariable, Table, Domain |
| 11 | + StringVariable, TimeVariable, Table, Domain |
11 | 12 | from Orange.data.sql.table import SqlTable |
12 | 13 | from Orange.preprocess.discretize import EqualWidth |
13 | 14 | from Orange.statistics.basic_stats import BasicStats, DomainBasicStats |
@@ -367,16 +368,66 @@ def test_meta_varchar(self): |
367 | 368 | sql_table = SqlTable(conn, table_name, inspect_values=True) |
368 | 369 | self.assertFirstMetaIsInstance(sql_table, StringVariable) |
369 | 370 |
|
370 | | - def test_date(self): |
| 371 | + def test_time_date(self): |
371 | 372 | table = np.array(['2014-04-12', '2014-04-13', '2014-04-14', |
372 | 373 | '2014-04-15', '2014-04-16']).reshape(-1, 1) |
373 | 374 | conn, table_name = self.create_sql_table(table, ['date']) |
374 | 375 |
|
375 | 376 | sql_table = SqlTable(conn, table_name, inspect_values=False) |
376 | | - self.assertFirstMetaIsInstance(sql_table, StringVariable) |
| 377 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
377 | 378 |
|
378 | 379 | sql_table = SqlTable(conn, table_name, inspect_values=True) |
379 | | - self.assertFirstMetaIsInstance(sql_table, StringVariable) |
| 380 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 381 | + |
| 382 | + def test_time_time(self): |
| 383 | + table = np.array(['17:39:51', '11:51:48.46', '05:20:21.492149', |
| 384 | + '21:47:06', '04:47:35.8']).reshape(-1, 1) |
| 385 | + conn, table_name = self.create_sql_table(table, ['time']) |
| 386 | + |
| 387 | + sql_table = SqlTable(conn, table_name, inspect_values=False) |
| 388 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 389 | + |
| 390 | + sql_table = SqlTable(conn, table_name, inspect_values=True) |
| 391 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 392 | + |
| 393 | + def test_time_timetz(self): |
| 394 | + table = np.array(['17:39:51+0200', '11:51:48.46+01', '05:20:21.4921', |
| 395 | + '21:47:06-0600', '04:47:35.8+0330']).reshape(-1, 1) |
| 396 | + conn, table_name = self.create_sql_table(table, ['timetz']) |
| 397 | + |
| 398 | + sql_table = SqlTable(conn, table_name, inspect_values=False) |
| 399 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 400 | + |
| 401 | + sql_table = SqlTable(conn, table_name, inspect_values=True) |
| 402 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 403 | + |
| 404 | + def test_time_timestamp(self): |
| 405 | + table = np.array(['2014-07-15 17:39:51.348149', |
| 406 | + '2008-10-05 11:51:48.468149', |
| 407 | + '2008-11-03 05:20:21.492149', |
| 408 | + '2015-01-02 21:47:06.228149', |
| 409 | + '2016-04-16 04:47:35.892149']).reshape(-1, 1) |
| 410 | + conn, table_name = self.create_sql_table(table, ['timestamp']) |
| 411 | + |
| 412 | + sql_table = SqlTable(conn, table_name, inspect_values=False) |
| 413 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 414 | + |
| 415 | + sql_table = SqlTable(conn, table_name, inspect_values=True) |
| 416 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 417 | + |
| 418 | + def test_time_timestamptz(self): |
| 419 | + table = np.array(['2014-07-15 17:39:51.348149+0200', |
| 420 | + '2008-10-05 11:51:48.468149+02', |
| 421 | + '2008-11-03 05:20:21.492149+01', |
| 422 | + '2015-01-02 21:47:06.228149+0100', |
| 423 | + '2016-04-16 04:47:35.892149+0330']).reshape(-1, 1) |
| 424 | + conn, table_name = self.create_sql_table(table, ['timestamptz']) |
| 425 | + |
| 426 | + sql_table = SqlTable(conn, table_name, inspect_values=False) |
| 427 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
| 428 | + |
| 429 | + sql_table = SqlTable(conn, table_name, inspect_values=True) |
| 430 | + self.assertFirstAttrIsInstance(sql_table, TimeVariable) |
380 | 431 |
|
381 | 432 | def test_double_precision(self): |
382 | 433 | table = np.arange(25).reshape((-1, 1)) |
|
0 commit comments