diff options
author | Darik Gamble <darik.gamble@gmail.com> | 2015-09-22 11:31:41 -0400 |
---|---|---|
committer | Darik Gamble <darik.gamble.spam@gmail.com> | 2015-09-29 09:07:20 -0400 |
commit | 07030e20d29f17a88d4bc5644a0e421f935af101 (patch) | |
tree | 4557e67f87d38f872973b94e2fd22df17f5cff62 /tests | |
parent | a0266de19270d0331cfbe552b3b0072e331872ca (diff) |
Move FunctionMetadata definition into its own package
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_function_metadata.py | 57 | ||||
-rw-r--r-- | tests/test_pgexecute.py | 3 | ||||
-rw-r--r-- | tests/test_smart_completion_multiple_schemata.py | 2 | ||||
-rw-r--r-- | tests/test_smart_completion_public_schema_only.py | 2 |
4 files changed, 61 insertions, 3 deletions
diff --git a/tests/test_function_metadata.py b/tests/test_function_metadata.py new file mode 100644 index 00000000..ff722cfb --- /dev/null +++ b/tests/test_function_metadata.py @@ -0,0 +1,57 @@ +import sqlparse +from pgcli.packages.function_metadata import ( + FunctionMetadata, parse_typed_field_list, field_names) + + +def test_function_metadata_eq(): + f1 = FunctionMetadata('s', 'f', 'x int', 'int', False, False, False) + f2 = FunctionMetadata('s', 'f', 'x int', 'int', False, False, False) + f3 = FunctionMetadata('s', 'g', 'x int', 'int', False, False, False) + assert f1 == f2 + assert f1 != f3 + assert not (f1 != f2) + assert not (f1 == f3) + assert hash(f1) == hash(f2) + assert hash(f1) != hash(f3) + +def test_parse_typed_field_list_simple(): + sql = 'a int, b int[][], c double precision, d text' + tokens = sqlparse.parse(sql)[0].flatten() + args = list(parse_typed_field_list(tokens)) + assert [arg.name for arg in args] == ['a', 'b', 'c', 'd'] + + +def test_parse_typed_field_list_more_complex(): + sql = ''' IN a int = 5, + IN b text default 'abc'::text, + IN c double precision = 9.99", + OUT d double precision[] ''' + tokens = sqlparse.parse(sql)[0].flatten() + args = list(parse_typed_field_list(tokens)) + assert [arg.name for arg in args] == ['a', 'b', 'c', 'd'] + assert [arg.mode for arg in args] == ['IN', 'IN', 'IN', 'OUT'] + + +def test_parse_typed_field_list_no_arg_names(): + #waiting on sqlparse/169 + sql = 'int, double precision, text' + tokens = sqlparse.parse(sql)[0].flatten() + args = list(parse_typed_field_list(tokens)) + assert(len(args) == 3) + + +def test_table_column_names(): + tbl_str = ''' + x INT, + y DOUBLE PRECISION, + z TEXT ''' + names = list(field_names(tbl_str, mode_filter=None)) + assert names == ['x', 'y', 'z'] + + +def test_argument_names(): + func_header = 'IN x INT DEFAULT 2, OUT y DOUBLE PRECISION' + names = field_names(func_header, mode_filter=['OUT', 'INOUT']) + assert list(names) == ['y'] + + diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py index 7be1d0b4..5d14eae8 100644 --- a/tests/test_pgexecute.py +++ b/tests/test_pgexecute.py @@ -2,9 +2,10 @@ import pytest from pgspecial.main import PGSpecial +from pgcli.packages.function_metadata import FunctionMetadata from textwrap import dedent from utils import run, dbtest, requires_json, requires_jsonb -from pgcli.pgexecute import FunctionMetadata + @dbtest def test_conn(executor): diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py index ea6c3381..6597f6d0 100644 --- a/tests/test_smart_completion_multiple_schemata.py +++ b/tests/test_smart_completion_multiple_schemata.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import pytest from prompt_toolkit.completion import Completion from prompt_toolkit.document import Document -from pgcli.pgexecute import FunctionMetadata +from pgcli.packages.function_metadata import FunctionMetadata metadata = { 'tables': { diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py index 98e8f088..cbf7d990 100644 --- a/tests/test_smart_completion_public_schema_only.py +++ b/tests/test_smart_completion_public_schema_only.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import pytest from prompt_toolkit.completion import Completion from prompt_toolkit.document import Document -from pgcli.pgexecute import FunctionMetadata +from pgcli.packages.function_metadata import FunctionMetadata metadata = { 'tables': { |