redash/tests/query_runner/test_utils.py
Arik Fraimovich 2dff8b9a00
Black support for the Python codebase (#4297)
* Apply black formatting

* Add auto formatting when committing to master

* Update CONTRIBUTING.md re. Black & Prettier
2019-12-11 13:54:29 +02:00

41 lines
1.3 KiB
Python

from unittest import TestCase
from redash.query_runner import (
TYPE_DATETIME,
TYPE_FLOAT,
TYPE_INTEGER,
TYPE_BOOLEAN,
TYPE_STRING,
guess_type,
)
class TestGuessType(TestCase):
def test_handles_unicode(self):
self.assertEqual(guess_type("Текст"), TYPE_STRING)
def test_detects_booleans(self):
self.assertEqual(guess_type("true"), TYPE_BOOLEAN)
self.assertEqual(guess_type("True"), TYPE_BOOLEAN)
self.assertEqual(guess_type("TRUE"), TYPE_BOOLEAN)
self.assertEqual(guess_type("false"), TYPE_BOOLEAN)
self.assertEqual(guess_type("False"), TYPE_BOOLEAN)
self.assertEqual(guess_type("FALSE"), TYPE_BOOLEAN)
self.assertEqual(guess_type(False), TYPE_BOOLEAN)
def test_detects_strings(self):
self.assertEqual(guess_type(None), TYPE_STRING)
self.assertEqual(guess_type(""), TYPE_STRING)
self.assertEqual(guess_type("redash"), TYPE_STRING)
def test_detects_integer(self):
self.assertEqual(guess_type("42"), TYPE_INTEGER)
self.assertEqual(guess_type(42), TYPE_INTEGER)
def test_detects_float(self):
self.assertEqual(guess_type("3.14"), TYPE_FLOAT)
self.assertEqual(guess_type(3.14), TYPE_FLOAT)
def test_detects_date(self):
self.assertEqual(guess_type("2018-10-31"), TYPE_DATETIME)