-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import enum | ||
|
||
from sqlalchemy import Column | ||
from sqlalchemy.sql.ddl import CreateTable | ||
|
||
from clickhouse_sqlalchemy import types, engines, Table | ||
from tests.testcase import BaseTestCase, CompilationTestCase | ||
from tests.util import with_native_and_http_sessions | ||
|
||
|
||
class TestEnum(enum.IntEnum): | ||
First = 1 | ||
Second = 2 | ||
|
||
|
||
class Enum16CompilationTestCase(CompilationTestCase): | ||
def test_create_table(self): | ||
table = Table( | ||
"test", | ||
BaseTestCase.metadata(), | ||
Column("x", types.Enum16(TestEnum)), | ||
engines.Memory(), | ||
) | ||
|
||
self.assertEqual( | ||
self.compile(CreateTable(table)), | ||
"CREATE TABLE test (x Enum16('First' = 1, 'Second' = 2)) " | ||
"ENGINE = Memory" | ||
) | ||
|
||
|
||
@with_native_and_http_sessions | ||
class Enum8TestCase(BaseTestCase): | ||
table = Table( | ||
'test', BaseTestCase.metadata(), | ||
Column('x', types.Enum16(TestEnum)), | ||
engines.Memory() | ||
) | ||
|
||
def test_select_insert(self): | ||
value = TestEnum.First | ||
with self.create_table(self.table): | ||
self.session.execute(self.table.insert(), [{'x': value}]) | ||
self.assertEqual(self.session.query(self.table.c.x).scalar(), | ||
value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import enum | ||
|
||
from sqlalchemy import Column | ||
from sqlalchemy.sql.ddl import CreateTable | ||
|
||
from clickhouse_sqlalchemy import types, engines, Table | ||
from tests.testcase import BaseTestCase, CompilationTestCase | ||
from tests.util import with_native_and_http_sessions | ||
|
||
|
||
class TestEnum(enum.IntEnum): | ||
First = 1 | ||
Second = 2 | ||
|
||
|
||
class Enum8CompilationTestCase(CompilationTestCase): | ||
def test_create_table(self): | ||
table = Table( | ||
"test", | ||
BaseTestCase.metadata(), | ||
Column("x", types.Enum8(TestEnum)), | ||
engines.Memory(), | ||
) | ||
|
||
self.assertEqual( | ||
self.compile(CreateTable(table)), | ||
"CREATE TABLE test (x Enum8('First' = 1, 'Second' = 2)) " | ||
"ENGINE = Memory" | ||
) | ||
|
||
|
||
@with_native_and_http_sessions | ||
class Enum8TestCase(BaseTestCase): | ||
table = Table( | ||
'test', BaseTestCase.metadata(), | ||
Column('x', types.Enum8(TestEnum)), | ||
engines.Memory() | ||
) | ||
|
||
def test_select_insert(self): | ||
value = TestEnum.First | ||
with self.create_table(self.table): | ||
self.session.execute(self.table.insert(), [{'x': value}]) | ||
self.assertEqual(self.session.query(self.table.c.x).scalar(), | ||
value) |