code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def test_schema_describe_05(self): self._assert_describe( """ type Foo { required single property middle_name -> std::str { default := 'abc'; readonly := true; }; } type Bar extending Foo; """, 'DESCRIBE TYPE Foo AS TEXT', """ type test::Foo { required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; }; required single property middle_name: std::str { default := 'abc'; readonly := true; }; }; """, 'DESCRIBE TYPE Foo AS TEXT VERBOSE', """ type test::Foo { required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; constraint std::exclusive; }; required single property middle_name: std::str { default := 'abc'; readonly := true; }; }; """, 'DESCRIBE TYPE Bar AS TEXT', """ type test::Bar extending test::Foo { required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; }; required single property middle_name: std::str { default := 'abc'; readonly := true; }; }; """, 'DESCRIBE TYPE Foo AS SDL', ''' type test::Foo { required single property middle_name: std::str { default := 'abc'; readonly := true; }; }; ''', 'DESCRIBE TYPE Bar AS SDL', 'type test::Bar extending test::Foo;' )
type Foo { required single property middle_name -> std::str { default := 'abc'; readonly := true; }; } type Bar extending Foo; """, 'DESCRIBE TYPE Foo AS TEXT',
test_schema_describe_05
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_06(self): self._assert_describe( """ abstract type HasImage { # just a URL to the image required property image -> str; index on (__subject__.image); } type User extending HasImage { property name -> str; } """, 'DESCRIBE TYPE User AS TEXT VERBOSE', """ type test::User extending test::HasImage { index on (__subject__.image); required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; constraint std::exclusive; }; required single property image: std::str; optional single property name: std::str; }; """, 'DESCRIBE TYPE User AS TEXT', """ type test::User extending test::HasImage { required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; }; required single property image: std::str; optional single property name: std::str; }; """, 'DESCRIBE TYPE User AS SDL', ''' type test::User extending test::HasImage { property name: std::str; }; ''', 'DESCRIBE TYPE HasImage AS TEXT VERBOSE', ''' abstract type test::HasImage { index on (__subject__.image); required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; constraint std::exclusive; }; required single property image: std::str; }; ''', 'DESCRIBE TYPE HasImage AS TEXT', ''' abstract type test::HasImage { required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; }; required single property image: std::str; }; ''', 'DESCRIBE TYPE HasImage AS SDL', ''' abstract type test::HasImage { index on (__subject__.image); required property image: std::str; }; ''', 'DESCRIBE TYPE HasImage AS DDL', ''' CREATE ABSTRACT TYPE test::HasImage { CREATE REQUIRED PROPERTY image: std::str; CREATE INDEX ON (__subject__.image); }; ''' )
abstract type HasImage { # just a URL to the image required property image -> str; index on (__subject__.image); } type User extending HasImage { property name -> str; } """, 'DESCRIBE TYPE User AS TEXT VERBOSE',
test_schema_describe_06
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_07(self): self._assert_describe( """ scalar type constraint_enum extending str { constraint one_of('foo', 'bar'); } abstract constraint my_one_of(one_of: array<anytype>) { using (contains(one_of, __subject__)); } scalar type constraint_my_enum extending str { constraint my_one_of(['fuz', 'buz']); } abstract link translated_label { property lang -> str; property prop1 -> str; } type Label { property text -> str; } type UniqueName { link translated_label extending translated_label -> Label { constraint exclusive on ( (__subject__@source, __subject__@lang) ); constraint exclusive on (__subject__@prop1); } } """, 'DESCRIBE OBJECT constraint_my_enum AS TEXT VERBOSE', """ scalar type test::constraint_my_enum extending std::str { constraint test::my_one_of(['fuz', 'buz']); }; """, 'DESCRIBE OBJECT my_one_of AS DDL', ''' CREATE ABSTRACT CONSTRAINT test::my_one_of(one_of: array<anytype>) { USING (std::contains(one_of, __subject__)); }; ''', 'DESCRIBE OBJECT UniqueName AS SDL', ''' type test::UniqueName { link translated_label: test::Label { extending test::translated_label; constraint std::exclusive on ( (__subject__@source, __subject__@lang) ); constraint std::exclusive on (__subject__@prop1); }; }; ''', 'DESCRIBE OBJECT UniqueName AS TEXT', ''' type test::UniqueName { required single link __type__: schema::ObjectType { readonly := true; }; optional single link translated_label: test::Label { extending test::translated_label; optional single property lang: std::str; optional single property prop1: std::str; }; required single property id: std::uuid { readonly := true; }; }; ''', 'DESCRIBE OBJECT UniqueName AS TEXT VERBOSE', ''' type test::UniqueName { required single link __type__: schema::ObjectType { readonly := true; }; optional single link translated_label: test::Label { extending test::translated_label; constraint std::exclusive on ( (__subject__@source, __subject__@lang)); constraint std::exclusive on (__subject__@prop1); optional single property lang: std::str; optional single property prop1: std::str; }; required single property id: std::uuid { readonly := true; constraint std::exclusive; }; }; ''', 'DESCRIBE OBJECT std::max_len_value AS DDL', ''' CREATE ABSTRACT CONSTRAINT std::max_len_value(max: std::int64) EXTENDING std::max_value, std::len_value { SET errmessage := '{__subject__} must be no longer than {max} characters.'; CREATE ANNOTATION std::description := 'Specifies the maximum length of subject string representation.'; }; ''', 'DESCRIBE OBJECT std::len_value AS SDL', ''' abstract constraint std::len_value on (std::len(<std::str>__subject__)) { errmessage := 'invalid {__subject__}'; }; ''', 'DESCRIBE OBJECT std::len_value AS TEXT', ''' abstract constraint std::len_value on (std::len(<std::str>__subject__)) { errmessage := 'invalid {__subject__}'; }; ''', 'DESCRIBE OBJECT std::len_value AS TEXT VERBOSE', ''' abstract constraint std::len_value on (std::len(<std::str>__subject__)) { errmessage := 'invalid {__subject__}'; }; ''' )
scalar type constraint_enum extending str { constraint one_of('foo', 'bar'); } abstract constraint my_one_of(one_of: array<anytype>) { using (contains(one_of, __subject__)); } scalar type constraint_my_enum extending str { constraint my_one_of(['fuz', 'buz']); } abstract link translated_label { property lang -> str; property prop1 -> str; } type Label { property text -> str; } type UniqueName { link translated_label extending translated_label -> Label { constraint exclusive on ( (__subject__@source, __subject__@lang) ); constraint exclusive on (__subject__@prop1); } } """, 'DESCRIBE OBJECT constraint_my_enum AS TEXT VERBOSE',
test_schema_describe_07
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_08(self): self._assert_describe( """ type Foo { property bar -> str { readonly := False; } }; """, 'DESCRIBE TYPE Foo', """ CREATE TYPE test::Foo { CREATE PROPERTY bar: std::str { SET readonly := false; }; }; """, 'DESCRIBE TYPE Foo AS SDL', """ type test::Foo { property bar: std::str { readonly := false; }; }; """, )
type Foo { property bar -> str { readonly := False; } }; """, 'DESCRIBE TYPE Foo',
test_schema_describe_08
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_09(self): # Test normalization of with block. The default module should # be inlined into the explicit fully-qualified name. self._assert_describe( r''' abstract constraint my_constr0(val: int64) { using ( WITH MODULE math SELECT abs(__subject__ + val) > 2 ); }; abstract constraint my_constr1(val: int64) { using ( WITH m AS MODULE math SELECT m::abs(__subject__ + val) > 2 ); }; abstract constraint my_constr2(val: int64) { using ( WITH MODULE math, x := __subject__ + val SELECT abs(x) > 2 ); }; ''', 'DESCRIBE CONSTRAINT my_constr0 AS SDL', ''' abstract constraint test::my_constr0(val: std::int64) { using (SELECT (std::math::abs((__subject__ + val)) > 2) ); }; ''', 'DESCRIBE CONSTRAINT my_constr1 AS SDL', ''' abstract constraint test::my_constr1(val: std::int64) { using ( SELECT (std::math::abs((__subject__ + val)) > 2) ); }; ''', 'DESCRIBE CONSTRAINT my_constr2 AS SDL', ''' abstract constraint test::my_constr2(val: std::int64) { using (WITH x := (__subject__ + val) SELECT (std::math::abs(x) > 2) ); }; ''', )
, 'DESCRIBE CONSTRAINT my_constr0 AS SDL',
test_schema_describe_09
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_10(self): # Test normalization of unusual defaults: query expressions. # Note that these defaults may not necessarily be practical, # but are used to test expression normalization in various # contexts. self._assert_describe( r''' type Foo { required property val -> int64; } type Bar0 { link insert_foo -> Foo { # insert a new Foo if not supplied default := ( INSERT Foo { val := -1 } ) }; } type Bar1 { multi link update_foo -> Foo { # if not supplied, update some specific Foo and link it default := ( UPDATE Foo FILTER .val = 1 SET { val := .val + 1 } ) }; } type Bar2 { multi link for_foo -> Foo { # if not supplied, select some specific Foo using FOR default := ( FOR x IN {2, 3} UNION ( SELECT Foo FILTER .val = x ) ) }; } type Bar3 { property delete_foo -> int64 { # if not supplied, update some specific Foo and link it default := ( SELECT ( DELETE Foo FILTER .val > 1 LIMIT 1 ).val ) }; } ''', 'DESCRIBE TYPE Bar0 AS SDL', ''' type test::Bar0 { link insert_foo: test::Foo { default := (INSERT test::Foo { val := -1 }); }; }; ''', 'DESCRIBE TYPE Bar1 AS SDL', ''' type test::Bar1 { multi link update_foo: test::Foo { default := (UPDATE test::Foo FILTER (.val = 1) SET { val := (.val + 1) }); }; }; ''', 'DESCRIBE TYPE Bar2 AS SDL', ''' type test::Bar2 { multi link for_foo: test::Foo { default := (FOR x IN {2, 3} UNION (SELECT test::Foo FILTER (.val = x) )); }; }; ''', 'DESCRIBE TYPE Bar3 AS SDL', ''' type test::Bar3 { property delete_foo: std::int64 { default := (SELECT ((DELETE test::Foo FILTER (.val > 1) LIMIT 1 )).val ); }; }; ''', )
, 'DESCRIBE TYPE Bar0 AS SDL',
test_schema_describe_10
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_alias_01(self): self._assert_describe( """ type Foo { property name -> str; }; alias Bar := (SELECT Foo {name, calc := 1}); """, 'DESCRIBE MODULE test', """ CREATE TYPE test::Foo { CREATE PROPERTY name: std::str; }; CREATE ALIAS test::Bar := ( SELECT test::Foo { name, calc := 1 } ); """ )
type Foo { property name -> str; }; alias Bar := (SELECT Foo {name, calc := 1}); """, 'DESCRIBE MODULE test',
test_schema_describe_alias_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_alias_02(self): self._assert_describe( """ type Foo { property name -> str; }; alias Bar { using (SELECT Foo {name, calc := 1}); annotation title := 'bar alias'; }; """, 'DESCRIBE MODULE test', """ CREATE TYPE test::Foo { CREATE PROPERTY name: std::str; }; CREATE ALIAS test::Bar { USING ( SELECT test::Foo { name, calc := 1 } ); CREATE ANNOTATION std::title := 'bar alias'; }; """ )
type Foo { property name -> str; }; alias Bar { using (SELECT Foo {name, calc := 1}); annotation title := 'bar alias'; }; """, 'DESCRIBE MODULE test',
test_schema_describe_alias_02
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_alias_03(self): self._assert_describe( """ alias scalar_alias := {1, 2, 3}; """, 'DESCRIBE MODULE test', """ CREATE ALIAS test::scalar_alias := ( {1, 2, 3} ); """ )
alias scalar_alias := {1, 2, 3}; """, 'DESCRIBE MODULE test',
test_schema_describe_alias_03
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_alias_04(self): self._assert_describe( """ alias tuple_alias := (1, 2, 3); alias array_alias := [1, 2, 3]; """, 'DESCRIBE MODULE test', """ CREATE ALIAS test::array_alias := ( [1, 2, 3] ); CREATE ALIAS test::tuple_alias := ( (1, 2, 3) ); """ )
alias tuple_alias := (1, 2, 3); alias array_alias := [1, 2, 3]; """, 'DESCRIBE MODULE test',
test_schema_describe_alias_04
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_alias_05(self): self._assert_describe( r""" type Foo { property name -> str; }; alias Bar := ( # Test what happens to the default module declared here WITH MODULE test SELECT Foo {name, calc := 1} ); """, 'DESCRIBE MODULE test', """ CREATE TYPE test::Foo { CREATE PROPERTY name: std::str; }; CREATE ALIAS test::Bar := ( SELECT test::Foo { name, calc := 1 } ); """ )
, 'DESCRIBE MODULE test',
test_schema_describe_alias_05
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_computable_01(self): self._assert_describe( """ type Foo { property compprop := 'foo'; link complink := (SELECT Foo LIMIT 1); property annotated_compprop -> str { using ('foo'); annotation title := 'compprop'; }; link annotated_link -> Foo { using (SELECT Foo LIMIT 1); annotation title := 'complink'; }; }; """, 'DESCRIBE MODULE test', """ CREATE TYPE test::Foo { CREATE LINK annotated_link { USING (SELECT test::Foo LIMIT 1); CREATE ANNOTATION std::title := 'complink'; }; CREATE LINK complink := (SELECT test::Foo LIMIT 1); CREATE PROPERTY annotated_compprop { USING ('foo'); CREATE ANNOTATION std::title := 'compprop'; }; CREATE PROPERTY compprop := ('foo'); }; """ )
type Foo { property compprop := 'foo'; link complink := (SELECT Foo LIMIT 1); property annotated_compprop -> str { using ('foo'); annotation title := 'compprop'; }; link annotated_link -> Foo { using (SELECT Foo LIMIT 1); annotation title := 'complink'; }; }; """, 'DESCRIBE MODULE test',
test_schema_describe_computable_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_computable_02(self): self._assert_describe( """ type Foo { property compprop := 'foo'; link complink := (SELECT Foo LIMIT 1); property annotated_compprop -> str { using ('foo'); annotation title := 'compprop'; }; link annotated_link -> Foo { using (SELECT Foo LIMIT 1); annotation title := 'complink'; }; }; """, 'DESCRIBE TYPE test::Foo', """ CREATE TYPE test::Foo { CREATE LINK annotated_link { USING (SELECT test::Foo LIMIT 1); CREATE ANNOTATION std::title := 'complink'; }; CREATE LINK complink := ( SELECT test::Foo LIMIT 1 ); CREATE PROPERTY annotated_compprop { USING ('foo'); CREATE ANNOTATION std::title := 'compprop'; }; CREATE PROPERTY compprop := ('foo'); }; """ )
type Foo { property compprop := 'foo'; link complink := (SELECT Foo LIMIT 1); property annotated_compprop -> str { using ('foo'); annotation title := 'compprop'; }; link annotated_link -> Foo { using (SELECT Foo LIMIT 1); annotation title := 'complink'; }; }; """, 'DESCRIBE TYPE test::Foo',
test_schema_describe_computable_02
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_computable_03(self): self._assert_describe( r""" type Foo { property name -> str; property comp := ( WITH x := count(Object) SELECT .name ++ <str>x ) }; """, 'DESCRIBE MODULE test', """ CREATE TYPE test::Foo { CREATE PROPERTY name: std::str; CREATE PROPERTY comp := (WITH x := std::count(std::Object) SELECT (.name ++ <std::str>x) ); }; """ )
, 'DESCRIBE MODULE test',
test_schema_describe_computable_03
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_builtins_01(self): self._assert_describe( """ """, 'DESCRIBE TYPE schema::ObjectType', # the links order is non-deterministic """ CREATE TYPE schema::ObjectType EXTENDING schema::Source, schema::ConsistencySubject, schema::InheritingObject, schema::Type, schema::AnnotationSubject { CREATE MULTI LINK access_policies: schema::AccessPolicy { EXTENDING schema::reference; ON TARGET DELETE ALLOW; CREATE CONSTRAINT std::exclusive; }; CREATE MULTI LINK intersection_of: schema::ObjectType; CREATE MULTI LINK union_of: schema::ObjectType; CREATE PROPERTY compound_type := ( (EXISTS (.union_of) OR EXISTS (.intersection_of)) ); CREATE PROPERTY is_compound_type := (.compound_type); CREATE MULTI LINK links := ( .pointers[IS schema::Link] ); CREATE MULTI LINK properties := ( .pointers[IS schema::Property] ); CREATE MULTI LINK triggers: schema::Trigger { EXTENDING schema::reference; ON TARGET DELETE ALLOW; CREATE CONSTRAINT std::exclusive; }; }; """, 'DESCRIBE TYPE schema::ObjectType AS SDL', """ type schema::ObjectType extending schema::Source, schema::ConsistencySubject, schema::InheritingObject, schema::Type, schema::AnnotationSubject { multi link access_policies: schema::AccessPolicy { extending schema::reference; on target delete allow; constraint std::exclusive; }; multi link intersection_of: schema::ObjectType; multi link links := (.pointers[IS schema::Link]); multi link properties := ( .pointers[IS schema::Property] ); multi link triggers: schema::Trigger { extending schema::reference; on target delete allow; constraint std::exclusive; }; multi link union_of: schema::ObjectType; property compound_type := ( (EXISTS (.union_of) OR EXISTS (.intersection_of)) ); property is_compound_type := (.compound_type); }; """, )
""", 'DESCRIBE TYPE schema::ObjectType', # the links order is non-deterministic
test_schema_describe_builtins_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_on_target_delete_01(self): # Test "on target delete". self._assert_describe( """ type Foo { link bar -> Object { on target delete allow; }; } """, 'DESCRIBE TYPE Foo', """ CREATE TYPE test::Foo { CREATE LINK bar: std::Object { ON TARGET DELETE ALLOW; }; }; """, 'DESCRIBE TYPE Foo AS SDL', """ type test::Foo { link bar: std::Object { on target delete allow; }; }; """, 'DESCRIBE TYPE Foo AS TEXT', """ type test::Foo { required single link __type__: schema::ObjectType { readonly := true; }; optional single link bar: std::Object { on target delete allow; }; required single property id: std::uuid { readonly := true; }; }; """, )
type Foo { link bar -> Object { on target delete allow; }; } """, 'DESCRIBE TYPE Foo',
test_schema_describe_on_target_delete_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_poly_01(self): self._assert_describe( """ type Object { property real -> bool; } function all() -> bool { using ( SELECT true ); } """, 'DESCRIBE OBJECT all AS TEXT', """ function test::all() -> std::bool using (SELECT true ); # The following builtins are masked by the above: # function std::all(vals: SET OF std::bool) -> std::bool { # volatility := 'Immutable'; # annotation std::description := 'Generalized boolean `AND` applied to the set of *values*.'; # using sql function 'bool_and' # ;}; """, 'DESCRIBE OBJECT Object AS TEXT', """ type test::Object { required single link __type__: schema::ObjectType { readonly := true; }; required single property id: std::uuid { readonly := true; }; optional single property real: std::bool; }; # The following builtins are masked by the above: # abstract type std::Object extending std::BaseObject { # required single link __type__: schema::ObjectType { # readonly := true; # }; # required single property id: std::uuid { # readonly := true; # }; # }; """, )
type Object { property real -> bool; } function all() -> bool { using ( SELECT true ); } """, 'DESCRIBE OBJECT all AS TEXT',
test_schema_describe_poly_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_ddl_01(self): self._assert_describe( """ CREATE MODULE test; CREATE TYPE Tree { CREATE REQUIRED PROPERTY val -> str { CREATE CONSTRAINT exclusive; }; CREATE LINK parent -> Tree; CREATE MULTI LINK children := .<parent[IS Tree]; CREATE MULTI LINK test_comp := ( SELECT Tree FILTER .val = 'test' ) }; """, 'DESCRIBE MODULE test', """ CREATE TYPE test::Tree { CREATE LINK parent: test::Tree; CREATE MULTI LINK children := (.<parent[IS test::Tree]); CREATE REQUIRED PROPERTY val: std::str { CREATE CONSTRAINT std::exclusive; }; CREATE MULTI LINK test_comp := ( SELECT test::Tree FILTER (.val = 'test') ); }; """, as_ddl=True, )
CREATE MODULE test; CREATE TYPE Tree { CREATE REQUIRED PROPERTY val -> str { CREATE CONSTRAINT exclusive; }; CREATE LINK parent -> Tree; CREATE MULTI LINK children := .<parent[IS Tree]; CREATE MULTI LINK test_comp := ( SELECT Tree FILTER .val = 'test' ) }; """, 'DESCRIBE MODULE test',
test_schema_describe_ddl_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_schema_01(self): self._assert_describe( """ type Foo; abstract annotation anno; scalar type int_t extending int64 { annotation anno := 'ext int'; constraint max_value(15); } abstract link f { property p -> int_t { annotation anno := 'annotated link property'; constraint max_value(10); } } type Parent { multi property name -> str; } type Parent2 { link foo -> Foo; index on (.foo); } type Child extending Parent, Parent2 { annotation anno := 'annotated'; overloaded link foo extending f -> Foo { constraint exclusive { annotation anno := 'annotated constraint'; } annotation anno := 'annotated link'; } } """, 'DESCRIBE SCHEMA AS DDL', """ CREATE MODULE default IF NOT EXISTS; CREATE MODULE test IF NOT EXISTS; CREATE ABSTRACT ANNOTATION test::anno; CREATE SCALAR TYPE test::int_t EXTENDING std::int64 { CREATE ANNOTATION test::anno := 'ext int'; CREATE CONSTRAINT std::max_value(15); }; CREATE ABSTRACT LINK test::f { CREATE PROPERTY p: test::int_t { CREATE CONSTRAINT std::max_value(10); CREATE ANNOTATION test::anno := 'annotated link property'; }; }; CREATE TYPE test::Foo; CREATE TYPE test::Parent { CREATE MULTI PROPERTY name: std::str; }; CREATE TYPE test::Parent2 { CREATE LINK foo: test::Foo; CREATE INDEX ON (.foo); }; CREATE TYPE test::Child EXTENDING test::Parent, test::Parent2 { CREATE ANNOTATION test::anno := 'annotated'; ALTER LINK foo { EXTENDING test::f; SET OWNED; SET TYPE test::Foo; CREATE ANNOTATION test::anno := 'annotated link'; CREATE CONSTRAINT std::exclusive { CREATE ANNOTATION test::anno := 'annotated constraint'; }; }; }; """, 'DESCRIBE SCHEMA AS SDL', r""" module default{}; module test { abstract annotation anno; abstract link f { property p: test::int_t { annotation test::anno := 'annotated link property'; constraint std::max_value(10); }; }; scalar type int_t extending std::int64 { annotation test::anno := 'ext int'; constraint std::max_value(15); }; type Child extending test::Parent, test::Parent2 { annotation test::anno := 'annotated'; overloaded link foo: test::Foo { extending test::f; annotation test::anno := 'annotated link'; constraint std::exclusive { annotation test::anno := 'annotated constraint'; }; }; }; type Foo; type Parent { multi property name: std::str; }; type Parent2 { index on (.foo); link foo: test::Foo; }; }; """, )
type Foo; abstract annotation anno; scalar type int_t extending int64 { annotation anno := 'ext int'; constraint max_value(15); } abstract link f { property p -> int_t { annotation anno := 'annotated link property'; constraint max_value(10); } } type Parent { multi property name -> str; } type Parent2 { link foo -> Foo; index on (.foo); } type Child extending Parent, Parent2 { annotation anno := 'annotated'; overloaded link foo extending f -> Foo { constraint exclusive { annotation anno := 'annotated constraint'; } annotation anno := 'annotated link'; } } """, 'DESCRIBE SCHEMA AS DDL',
test_schema_describe_schema_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_schema_02(self): self._assert_describe( """ using extension notebook version '1.0'; module default { type Foo { link bar -> test::Bar; }; }; module test { type Bar { link foo -> default::Foo; }; }; """, 'DESCRIBE SCHEMA AS DDL', """ CREATE EXTENSION NOTEBOOK VERSION '1.0'; CREATE MODULE default IF NOT EXISTS; CREATE MODULE test IF NOT EXISTS; CREATE TYPE default::Foo; CREATE TYPE test::Bar { CREATE LINK foo: default::Foo; }; ALTER TYPE default::Foo { CREATE LINK bar: test::Bar; }; """, 'DESCRIBE SCHEMA AS SDL', r""" using extension notebook version '1.0'; module default { type Foo { link bar: test::Bar; }; }; module test { type Bar { link foo: default::Foo; }; }; """, explicit_modules=True, )
using extension notebook version '1.0'; module default { type Foo { link bar -> test::Bar; }; }; module test { type Bar { link foo -> default::Foo; }; }; """, 'DESCRIBE SCHEMA AS DDL',
test_schema_describe_schema_02
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_schema_03(self): self._assert_describe( """ using extension pgvector version '0.5'; module default { scalar type v3 extending ext::pgvector::vector<3>; type Foo { data: v3; } }; """, 'describe schema as ddl', """ create extension vector version '0.5'; create module default if not exists; create scalar type default::v3 extending ext::pgvector::vector<3>; create type default::Foo { create property data: default::v3; }; """, 'describe schema as sdl', r""" using extension pgvector version '0.5'; module default { scalar type v3 extending ext::pgvector::vector<3>; type Foo { property data: default::v3; }; }; """, explicit_modules=True, )
using extension pgvector version '0.5'; module default { scalar type v3 extending ext::pgvector::vector<3>; type Foo { data: v3; } }; """, 'describe schema as ddl',
test_schema_describe_schema_03
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_except_01(self): # Test that except works right self._assert_describe( """ abstract constraint always_ok { using (true); }; type ExceptTest { property e -> std::bool; constraint always_ok on (.e); constraint always_ok on (.e) except (.e); constraint expression on (true) except (.e); index on (.id) except (.e); }; """, 'DESCRIBE TYPE ExceptTest', """ create type test::ExceptTest { create property e: std::bool; create constraint std::expression on (true) except (.e); create constraint test::always_ok on (.e) except (.e); create constraint test::always_ok on (.e); create index on (.id) except (.e); }; """, )
abstract constraint always_ok { using (true); }; type ExceptTest { property e -> std::bool; constraint always_ok on (.e); constraint always_ok on (.e) except (.e); constraint expression on (true) except (.e); index on (.id) except (.e); }; """, 'DESCRIBE TYPE ExceptTest',
test_schema_describe_except_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_missing_01(self): with self.assertRaisesRegex( errors.InvalidReferenceError, "function 'lol' does not exist"): self._assert_describe( """ # nothing, whatever """, 'describe function lol', """ # we'll error instead of checking this """, )
# nothing, whatever """, 'describe function lol',
test_schema_describe_missing_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_missing_02(self): with self.assertRaisesRegex( errors.InvalidReferenceError, "module 'lol' does not exist"): self._assert_describe( """ # nothing, whatever """, 'describe module lol', """ # we'll error instead of checking this """, )
# nothing, whatever """, 'describe module lol',
test_schema_describe_missing_02
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_missing_03(self): with self.assertRaisesRegex( errors.InvalidReferenceError, "object type 'std::lol' does not exist"): self._assert_describe( """ # nothing, whatever """, 'describe type lol', """ # we'll error instead of checking this """, )
# nothing, whatever """, 'describe type lol',
test_schema_describe_missing_03
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_name_override_01(self): self._assert_describe( """ type Other { obj: Object; } type Object; """, 'DESCRIBE MODULE test', """ create type test::Object; create type test::Other { create link obj: test::Object; }; """ )
type Other { obj: Object; } type Object; """, 'DESCRIBE MODULE test',
test_schema_describe_name_override_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_name_override_02(self): self._assert_describe( """ type Object; type Other { obj: test::Object; } """, 'DESCRIBE MODULE test', """ create type test::Object; create type test::Other { create link obj: test::Object; }; """ )
type Object; type Other { obj: test::Object; } """, 'DESCRIBE MODULE test',
test_schema_describe_name_override_02
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_name_override_03(self): self._assert_describe( """ type User { single link identity: Identity; } abstract type BaseObject {} type Identity extending BaseObject { link user := .<identity[is User]; } type IdentityCredential extending BaseObject {} """, 'DESCRIBE MODULE test', """ create abstract type test::BaseObject; create type test::Identity extending test::BaseObject; create type test::IdentityCredential extending test::BaseObject; create type test::User { create single link identity: test::Identity; }; alter type test::Identity { create link user := (.<identity[is test::User]); }; """ )
type User { single link identity: Identity; } abstract type BaseObject {} type Identity extending BaseObject { link user := .<identity[is User]; } type IdentityCredential extending BaseObject {} """, 'DESCRIBE MODULE test',
test_schema_describe_name_override_03
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_overload_01(self): self._assert_describe( """ abstract type Animal { name: str; parent: Animal; } type Human extending Animal { overloaded parent: Human; } """, 'describe type test::Human as sdl', """ type test::Human extending test::Animal { overloaded link parent: test::Human; }; """, )
abstract type Animal { name: str; parent: Animal; } type Human extending Animal { overloaded parent: Human; } """, 'describe type test::Human as sdl',
test_schema_describe_overload_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_01(self): schema_text = f''' module dummy {{}} module A {{ type Foo; }} ''' queries = [] with_mod = '' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH MODULE A ' queries += [ with_mod + 'SELECT <Foo>{}', with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH AAA as MODULE A ' queries += [ with_mod + 'SELECT <A::Foo>{}', with_mod + 'SELECT <AAA::Foo>{}', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH std as MODULE A ' queries += [ with_mod + 'SELECT <std::Foo>{}', with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH A as MODULE std ' queries += [] normalized = 'SELECT <A::Foo>{}' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH MODULE A ' queries += [ with_mod + 'SELECT <Foo>{}', with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH AAA as MODULE A ' queries += [ with_mod + 'SELECT <A::Foo>{}', with_mod + 'SELECT <AAA::Foo>{}', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH std as MODULE A ' queries += [ with_mod + 'SELECT <std::Foo>{}', with_mod + 'SELECT <A::Foo>{}', ] with_mod = 'WITH A as MODULE std ' queries += [] normalized = 'SELECT <A::Foo>{}' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_02(self): schema_text = f''' module dummy {{}} module A {{ function abs(x: int64) -> int64 using (x); }} ''' queries = [] with_mod = '' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH MODULE A ' queries += [ with_mod + 'SELECT abs(1)', with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH AAA as MODULE A ' queries += [ with_mod + 'SELECT A::abs(1)', with_mod + 'SELECT AAA::abs(1)', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH std as MODULE A ' queries += [ with_mod + 'SELECT std::abs(1)', with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH A as MODULE std ' queries += [] normalized = 'SELECT A::abs(1)' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH MODULE A ' queries += [ with_mod + 'SELECT abs(1)', with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH AAA as MODULE A ' queries += [ with_mod + 'SELECT A::abs(1)', with_mod + 'SELECT AAA::abs(1)', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH std as MODULE A ' queries += [ with_mod + 'SELECT std::abs(1)', with_mod + 'SELECT A::abs(1)', ] with_mod = 'WITH A as MODULE std ' queries += [] normalized = 'SELECT A::abs(1)' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_02
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_03(self): schema_text = f''' module dummy {{}} ''' queries = [] with_mod = '' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH def as MODULE default ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', with_mod + 'SELECT <s::int64>{} = 1', ] with_mod = 'WITH std as MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', ] normalized = 'SELECT (<std::int64>{} = 1)' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH def as MODULE default ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', with_mod + 'SELECT <s::int64>{} = 1', ] with_mod = 'WITH std as MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', ] normalized = 'SELECT (<std::int64>{} = 1)' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_03
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_04a(self): schema_text = f''' module dummy {{}} module default {{ type int64; }} ''' queries = [] with_mod = '' queries += [ with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH def as MODULE default ' queries += [ with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <std::int64>{} = 1', with_mod + 'SELECT <s::int64>{} = 1', ] with_mod = 'WITH std as MODULE dummy ' queries += [] with_mod = 'WITH std as MODULE default ' queries += [] normalized = 'SELECT (<std::int64>{} = 1)' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); type default::int64; ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <int64>{} = 1', with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH def as MODULE default ' queries += [ with_mod + 'SELECT <std::int64>{} = 1', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <std::int64>{} = 1', with_mod + 'SELECT <s::int64>{} = 1', ] with_mod = 'WITH std as MODULE dummy ' queries += [] with_mod = 'WITH std as MODULE default ' queries += [] normalized = 'SELECT (<std::int64>{} = 1)' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_04a
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_04b(self): schema_text = f''' module dummy {{}} module default {{ type int64; }} ''' queries = [] with_mod = '' queries += [ with_mod + 'SELECT <int64>{}', with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH def as MODULE default ' queries += [ with_mod + 'SELECT <default::int64>{}', with_mod + 'SELECT <def::int64>{}', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH std as MODULE dummy ' queries += [] with_mod = 'WITH std as MODULE default ' queries += [] normalized = 'SELECT <default::int64>{}' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); type default::int64; ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'SELECT <int64>{}', with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH MODULE dummy ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH MODULE std ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH dum as MODULE dummy ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH def as MODULE default ' queries += [ with_mod + 'SELECT <default::int64>{}', with_mod + 'SELECT <def::int64>{}', ] with_mod = 'WITH s as MODULE std ' queries += [ with_mod + 'SELECT <default::int64>{}', ] with_mod = 'WITH std as MODULE dummy ' queries += [] with_mod = 'WITH std as MODULE default ' queries += [] normalized = 'SELECT <default::int64>{}' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_04b
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_05(self): schema_text = f''' module dummy {{}} ''' queries = [] with_mod = '' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module dummy ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module _test ' queries += [ with_mod + 'select abs(1)', with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std::_test ' queries += [ with_mod + 'select abs(1)', with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with t as module _test ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', with_mod + 'select t::abs(1)', ] with_mod = 'with s as module std ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with st as module std::_test ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', with_mod + 'select st::abs(1)', ] with_mod = 'with std as module _test ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::abs(1)', ] normalized = 'SELECT std::_test::abs(1)' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module dummy ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module _test ' queries += [ with_mod + 'select abs(1)', with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std::_test ' queries += [ with_mod + 'select abs(1)', with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with t as module _test ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', with_mod + 'select t::abs(1)', ] with_mod = 'with s as module std ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with st as module std::_test ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::_test::abs(1)', with_mod + 'select st::abs(1)', ] with_mod = 'with std as module _test ' queries += [ with_mod + 'select _test::abs(1)', with_mod + 'select std::abs(1)', ] normalized = 'SELECT std::_test::abs(1)' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_05
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_describe_with_module_06(self): schema_text = f''' module dummy {{}} module _test {{}} ''' queries = [] with_mod = '' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module dummy ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module _test ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std::_test ' queries += [ with_mod + 'select abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with t as module _test ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with s as module std ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with st as module std::_test ' queries += [ with_mod + 'select std::_test::abs(1)', with_mod + 'select st::abs(1)', ] with_mod = 'with std as module _test ' queries += [] with_mod = 'with std as module std::_test ' queries += [ with_mod + 'select std::abs(1)', ] normalized = 'SELECT std::_test::abs(1)' for query in queries: self._assert_describe( schema_text + f''' module default {{ alias query := ({query}); }} ''', 'describe module default as sdl', f''' alias default::query := ({normalized}); ''', explicit_modules=True, )
queries = [] with_mod = '' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module dummy ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module _test ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with module std::_test ' queries += [ with_mod + 'select abs(1)', with_mod + 'select std::_test::abs(1)', ] with_mod = 'with t as module _test ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with s as module std ' queries += [ with_mod + 'select std::_test::abs(1)', ] with_mod = 'with st as module std::_test ' queries += [ with_mod + 'select std::_test::abs(1)', with_mod + 'select st::abs(1)', ] with_mod = 'with std as module _test ' queries += [] with_mod = 'with std as module std::_test ' queries += [ with_mod + 'select std::abs(1)', ] normalized = 'SELECT std::_test::abs(1)' for query in queries: self._assert_describe( schema_text + f
test_schema_describe_with_module_06
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
def test_schema_create_migration_sequence_01(self): schema = self.schema schema = self.run_ddl(schema, 'CREATE MODULE default;') m1 = 'm1vrzjotjgjxhdratq7jz5vdxmhvg2yun2xobiddag4aqr3y4gavgq' schema = self.run_ddl( schema, f''' CREATE MIGRATION {m1} {{ CREATE TYPE Foo; }}; ''' ) m2 = 'm1fgy2elz3ks3t5wdpujxsjnmojs24n4ov7i5yvgtz7x643ekda6oq' schema = self.run_ddl( schema, f''' CREATE MIGRATION {m2} ONTO {m1} {{ CREATE TYPE Bar; }}; ''' ) # This does not specify parent. So parent is computed as a last # migration and then it is used to calculate hash. And we ensure that # migration contexts match hash before checking if that revision is # already applied. with self.assertRaisesRegex( errors.SchemaDefinitionError, f"specified migration name does not match the name " f"derived from the migration contents", ): schema = self.run_ddl( schema, f''' CREATE MIGRATION {m1} {{ CREATE TYPE Bar; }}; ''' ) with self.assertRaisesRegex( errors.DuplicateMigrationError, f"migration {m2!r} is already applied", ): schema = self.run_ddl( schema, f''' CREATE MIGRATION {m2} ONTO {m1} {{ CREATE TYPE Bar; }}; ''' ) with self.assertRaisesRegex( errors.SchemaDefinitionError, f"specified migration parent is not the most recent migration, " f"expected {str(m2)!r}", ): m3 = 'm1ehveozttov2emc33uh362ojjnenn6kd3secmi5el6y3euhifq5na' schema = self.run_ddl( schema, f''' CREATE MIGRATION {m3} ONTO {m1} {{ CREATE TYPE Baz; }}; ''' ) m3_bad = 'm1vrzjotjgjxhdratq7jz5vdxmhvg2yun2xobiddag4aqr3y4gavgq' m3_good = 'm1ccjw4emykq2c5i4bvaglxjvx7ebr2cgrurvcroggpemdzyjrn6da' with self.assertRaisesRegex( errors.SchemaDefinitionError, f"specified migration name does not match the name derived from " f"the migration contents: {m3_bad!r}, expected {m3_good!r}" ): schema = self.run_ddl( schema, f''' CREATE MIGRATION {m3_bad} ONTO {m2} {{ CREATE TYPE Baz; }}; ''' )
) m2 = 'm1fgy2elz3ks3t5wdpujxsjnmojs24n4ov7i5yvgtz7x643ekda6oq' schema = self.run_ddl( schema, f
test_schema_create_migration_sequence_01
python
geldata/gel
tests/test_schema.py
https://github.com/geldata/gel/blob/master/tests/test_schema.py
Apache-2.0
async def is_testmode_on(self): # The idea is that if __internal_testmode value config is lost # (no longer "true") then this script fails. try: await self.con.execute(''' CREATE FUNCTION testconf() -> bool USING SQL $$ SELECT true; $$; DROP FUNCTION testconf(); ''') except edgedb.InvalidFunctionDefinitionError: return False return await self.con.query_single(''' SELECT cfg::Config.__internal_testmode LIMIT 1 ''')
) except edgedb.InvalidFunctionDefinitionError: return False return await self.con.query_single(
is_testmode_on
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_fetch_single_command_01(self): r = await self.con.query(''' CREATE TYPE server_fetch_single_command_01 { CREATE REQUIRED PROPERTY server_fetch_single_command_01 -> std::str; }; ''') self.assertEqual(r, []) self.assertEqual(self.con._get_last_status(), 'CREATE TYPE') r = await self.con.query(''' DROP TYPE server_fetch_single_command_01; ''') self.assertEqual(r, []) self.assertEqual(self.con._get_last_status(), 'DROP TYPE') r = await self.con.query(''' CREATE TYPE server_fetch_single_command_01 { CREATE REQUIRED PROPERTY server_fetch_single_command_01 -> std::str; }; ''') self.assertEqual(len(r), 0) r = await self.con.query(''' DROP TYPE server_fetch_single_command_01; ''') self.assertEqual(len(r), 0) r = await self.con.query_json(''' CREATE TYPE server_fetch_single_command_01 { CREATE REQUIRED PROPERTY server_fetch_single_command_01 -> std::str; }; ''') self.assertEqual(r, '[]') r = await self.con.query_json(''' DROP TYPE server_fetch_single_command_01; ''') self.assertEqual(r, '[]')
) self.assertEqual(r, []) self.assertEqual(self.con._get_last_status(), 'CREATE TYPE') r = await self.con.query(
test_server_proto_fetch_single_command_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_fetch_single_command_02(self): r = await self.con.query(''' SET MODULE default; ''') self.assertEqual(r, []) self.assertEqual(self.con._get_last_status(), 'SET ALIAS') r = await self.con.query(''' SET ALIAS foo AS MODULE default; ''') self.assertEqual(r, []) r = await self.con.query(''' SET MODULE default; ''') self.assertEqual(len(r), 0) r = await self.con.query_json(''' SET ALIAS foo AS MODULE default; ''') self.assertEqual(r, '[]') r = await self.con.query_json(''' SET MODULE default; ''') self.assertEqual(r, '[]') r = await self.con.query_json(''' SET ALIAS foo AS MODULE default; ''') self.assertEqual(r, '[]')
) self.assertEqual(r, []) self.assertEqual(self.con._get_last_status(), 'SET ALIAS') r = await self.con.query(
test_server_proto_fetch_single_command_02
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_script_01(self): self.assertEqual( await self.con.query(''' SET MODULE test; SELECT 1; '''), [1], ) self.assertEqual( await self.con.query_json(''' SET MODULE test; SELECT 1; '''), '[1]', ) with self.assertRaisesRegex( edgedb.InterfaceError, r'it does not return any data'): await self.con.query_required_single(''' SELECT 1; SET MODULE test; ''') with self.assertRaisesRegex( edgedb.InterfaceError, r'it does not return any data'): await self.con.query_required_single_json(''' SELECT 1; SET MODULE test; ''')
), [1], ) self.assertEqual( await self.con.query_json(
test_server_proto_query_script_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_set_reset_alias_01(self): await self.con.execute(''' SET ALIAS foo AS MODULE std; SET ALIAS bar AS MODULE std; SET MODULE test; ''') self.assertEqual( await self.con.query('SELECT foo::min({1}) + bar::min({0})'), [1]) self.assertEqual( await self.con.query(''' SELECT count( Tmp2 FILTER Tmp2.tmp = "test_server_set_reset_alias_01"); '''), [0]) await self.con.execute(''' RESET ALIAS bar; ''') self.assertEqual( await self.con.query('SELECT foo::min({1})'), [1]) with self.assertRaisesRegex( edgedb.InvalidReferenceError, "function 'bar::min' does not exist"): await self.con.query('SELECT bar::min({1})') await self.con.query(''' RESET ALIAS *; ''') with self.assertRaisesRegex( edgedb.InvalidReferenceError, "function 'foo::min' does not exist"): await self.con.query('SELECT foo::min({3})') self.assertEqual( await self.con.query('SELECT min({4})'), [4]) with self.assertRaisesRegex( edgedb.InvalidReferenceError, "object type or alias 'default::Tmp2' does not exist"): await self.con.query(''' SELECT count( Tmp2 FILTER Tmp2.tmp = "test_server_set_reset_alias_01"); ''')
) self.assertEqual( await self.con.query('SELECT foo::min({1}) + bar::min({0})'), [1]) self.assertEqual( await self.con.query(
test_server_proto_set_reset_alias_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_set_reset_alias_02(self): await self.con.execute(''' SET ALIAS foo AS MODULE std; SET ALIAS bar AS MODULE std; SET MODULE test; ''') self.assertEqual( await self.con.query(''' SELECT count( Tmp2 FILTER Tmp2.tmp = "test_server_set_reset_alias_01"); '''), [0]) await self.con.execute(''' RESET MODULE; ''') with self.assertRaisesRegex( edgedb.InvalidReferenceError, "object type or alias 'default::Tmp2' does not exist"): await self.con.query(''' SELECT count( Tmp2 FILTER Tmp2.tmp = "test_server_set_reset_alias_01"); ''')
) self.assertEqual( await self.con.query(
test_server_proto_set_reset_alias_02
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_set_reset_alias_03(self): with self.assertRaisesRegex( edgedb.UnknownModuleError, "module 'blahhhh' does not exist"): await self.con.execute(''' SET ALIAS foo AS MODULE blahhhh; ''') with self.assertRaisesRegex( edgedb.UnknownModuleError, "module 'blahhhh' does not exist"): await self.con.execute(''' SET MODULE blahhhh; ''') # Test error recovery now await self.con.execute(''' SET MODULE default; ''') self.assertEqual( await self.con.query(''' SELECT count( Tmp FILTER Tmp.tmp = "test_server_set_reset_alias_01"); '''), [0])
) with self.assertRaisesRegex( edgedb.UnknownModuleError, "module 'blahhhh' does not exist"): await self.con.execute(
test_server_proto_set_reset_alias_03
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_set_reset_alias_05(self): # A regression test. # The "DECLARE SAVEPOINT a1; ROLLBACK TO SAVEPOINT a1;" commands # used to propagate the 'foo -> std' alias to the connection state # which the failed to correctly revert it back on ROLLBACK. await self.con.query('START TRANSACTION') await self.con.execute(''' SET ALIAS foo AS MODULE std; ''') await self.con.query('DECLARE SAVEPOINT a1') await self.con.query('ROLLBACK TO SAVEPOINT a1') with self.assertRaises(edgedb.DivisionByZeroError): await self.con.execute(''' SELECT 1/0; ''') await self.con.query('ROLLBACK') with self.assertRaises(edgedb.InvalidReferenceError): await self.con.execute(''' SELECT foo::len('aaa') ''')
) await self.con.query('DECLARE SAVEPOINT a1') await self.con.query('ROLLBACK TO SAVEPOINT a1') with self.assertRaises(edgedb.DivisionByZeroError): await self.con.execute(
test_server_proto_set_reset_alias_05
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_set_reset_alias_07(self): await self.con.query('START TRANSACTION') await self.con.execute(''' SET MODULE test; ''') await self.con.query('select Tmp2') await self.con.execute(''' SET MODULE default; ''') with self.assertRaises(edgedb.InvalidReferenceError): await self.con.query('select Tmp2') await self.con.query('ROLLBACK')
) await self.con.query('select Tmp2') await self.con.execute(
test_server_proto_set_reset_alias_07
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_basic_datatypes_05(self): # A regression test to ensure that typedesc IDs are different # for shapes with equal fields names bit of different kinds # (e.g. in this test it's "@foo" vs "foo"; before fixing the # bug the results of second query were with "@foo" key, not "foo") for _ in range(5): await self.assert_query_result( r""" WITH MODULE schema SELECT ObjectType { name, properties: { name, @foo := 1 } ORDER BY .name LIMIT 1, } FILTER .name = 'default::Tmp'; """, [{ 'name': 'default::Tmp', 'properties': [{ 'name': 'id', '@foo': 1 }], }] ) for _ in range(5): await self.assert_query_result( r""" WITH MODULE schema SELECT ObjectType { name, properties: { name, foo := 1 } ORDER BY .name LIMIT 1, } FILTER .name = 'default::Tmp'; """, [{ 'name': 'default::Tmp', 'properties': [{ 'name': 'id', 'foo': 1 }], }] )
, [{ 'name': 'default::Tmp', 'properties': [{ 'name': 'id', '@foo': 1 }], }] ) for _ in range(5): await self.assert_query_result( r
test_server_proto_basic_datatypes_05
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_basic_datatypes_06(self): # Test that field names are taken into account when # typedesc id is computed. for _ in range(5): await self.assert_query_result( r""" WITH MODULE schema SELECT ObjectType { name, properties: { name, foo1 := 1 } ORDER BY .name LIMIT 1, } FILTER .name = 'default::Tmp'; """, [{ 'name': 'default::Tmp', 'properties': [{ 'name': 'id', 'foo1': 1 }], }] ) for _ in range(5): await self.assert_query_result( r""" WITH MODULE schema SELECT ObjectType { name, properties: { name, foo2 := 1 } ORDER BY .name LIMIT 1, } FILTER .name = 'default::Tmp'; """, [{ 'name': 'default::Tmp', 'properties': [{ 'name': 'id', 'foo2': 1 }], }] )
, [{ 'name': 'default::Tmp', 'properties': [{ 'name': 'id', 'foo1': 1 }], }] ) for _ in range(5): await self.assert_query_result( r
test_server_proto_basic_datatypes_06
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_args_08(self): async with self._run_and_rollback(): await self.con.execute( ''' CREATE TYPE str; CREATE TYPE int64; CREATE TYPE float64; CREATE TYPE decimal; CREATE TYPE bigint; ''' ) self.assertEqual( await self.con.query_single('select ("1", 1, 1.1, 1.1n, 1n)'), ('1', 1, 1.1, decimal.Decimal('1.1'), 1) )
CREATE TYPE str; CREATE TYPE int64; CREATE TYPE float64; CREATE TYPE decimal; CREATE TYPE bigint;
test_server_proto_args_08
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_args_11(self): async with self._run_and_rollback(): self.assertEqual( await self.con.query( ''' insert Tmp { tmp := <str>$0 }; select Tmp.tmp ++ <str>$1; ''', "?", "!"), edgedb.Set(["?!"]), ) async with self._run_and_rollback(): self.assertEqual( await self.con.query( ''' insert Tmp { tmp := <str>$foo }; select Tmp.tmp ++ <str>$bar; ''', foo="?", bar="!"), edgedb.Set(["?!"]), )
insert Tmp { tmp := <str>$0 }; select Tmp.tmp ++ <str>$1; ''', "?", "!"), edgedb.Set(["?!"]), ) async with self._run_and_rollback(): self.assertEqual( await self.con.query(
test_server_proto_args_11
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_savepoint_01(self): # Basic test that SAVEPOINTS actually work; test with DML. typename = 'Savepoint_01' query = f'SELECT {typename}.prop1' con = self.con # __internal_testmode should be ON self.assertTrue(await self.is_testmode_on()) await con.query('START TRANSACTION') await con.execute(f''' CONFIGURE SESSION SET __internal_testmode := false; ''') await con.query('DECLARE SAVEPOINT t1') await con.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; ''') await con.query('DECLARE SAVEPOINT t1') self.assertEqual(self.con._get_last_status(), 'DECLARE SAVEPOINT') # Make sure that __internal_testmode was indeed updated. self.assertFalse(await self.is_testmode_on()) # is_testmode_on call caused an error; rollback await con.query('ROLLBACK TO SAVEPOINT t1') try: await con.execute(f''' INSERT {typename} {{ prop1 := 'aaa' }}; ''') await self.con.query('DECLARE SAVEPOINT t1') await con.execute(f''' INSERT {typename} {{ prop1 := 'bbb' }}; ''') await self.con.query('DECLARE SAVEPOINT t2') await con.execute(f''' INSERT {typename} {{ prop1 := 'ccc' }}; ''') await self.con.query('DECLARE SAVEPOINT t1') await con.execute(f''' INSERT {typename} {{ prop1 := 'ddd' }}; ''') await self.con.query('DECLARE SAVEPOINT t3') self.assertEqual( await con.query(query), edgedb.Set(('aaa', 'bbb', 'ccc', 'ddd'))) for _ in range(10): await con.query('ROLLBACK TO SAVEPOINT t1') self.assertEqual( await con.query(query), edgedb.Set(('aaa', 'bbb', 'ccc'))) await con.query('RELEASE SAVEPOINT t1') self.assertEqual( await con.query(query), edgedb.Set(('aaa', 'bbb', 'ccc'))) for _ in range(5): await con.query('ROLLBACK TO SAVEPOINT t1') self.assertEqual( await con.query(query), edgedb.Set(('aaa',))) await con.query('RELEASE SAVEPOINT t1') await con.query('RELEASE SAVEPOINT t1') await con.query('ROLLBACK TO SAVEPOINT t1') with self.assertRaisesRegex( edgedb.InvalidReferenceError, ".*Savepoint.*does not exist"): await con.query(query) finally: await con.query('ROLLBACK') # __internal_testmode should be ON, just as when the test method # was called. self.assertTrue(await self.is_testmode_on())
) await con.query('DECLARE SAVEPOINT t1') await con.execute(f
test_server_proto_tx_savepoint_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_savepoint_03(self): # Test that PARSE/EXECUTE/OPPORTUNISTIC-EXECUTE play nice # with savepoints. await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT t0') try: self.assertEqual( await self.con.query('SELECT 1;'), [1]) with self.assertRaisesRegex( edgedb.TransactionError, "there is no 't1' savepoint"): await self.con.query(''' RELEASE SAVEPOINT t1; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query_single(''' RELEASE SAVEPOINT t1; ''') await self.con.query(''' ROLLBACK TO SAVEPOINT t0; ''') self.assertEqual( await self.con.query('SELECT 1;'), [1]) with self.assertRaisesRegex( edgedb.TransactionError, "there is no 't1' savepoint"): await self.con.query(''' RELEASE SAVEPOINT t1; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query(''' RELEASE SAVEPOINT t1; ''') finally: await self.con.query('ROLLBACK') self.assertEqual( await self.con.query('SELECT 1;'), [1])
) with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query_single(
test_server_proto_tx_savepoint_03
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_savepoint_04(self): # Test that PARSE/EXECUTE/OPPORTUNISTIC-EXECUTE play nice # with savepoints. await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT t0') try: self.assertEqual( await self.con.query('SELECT 1;'), [1]) with self.assertRaises(edgedb.DivisionByZeroError): await self.con.query(''' SELECT 1 / 0; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query('SELECT 1;') await self.con.query(''' ROLLBACK TO SAVEPOINT t0; ''') self.assertEqual( await self.con.query('SELECT 1;'), [1]) with self.assertRaises(edgedb.DivisionByZeroError): await self.con.query_single(''' SELECT 1 / 0; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query('SELECT 1;') finally: await self.con.query('ROLLBACK') self.assertEqual( await self.con.query('SELECT 1;'), [1])
) with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query('SELECT 1;') await self.con.query(
test_server_proto_tx_savepoint_04
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_savepoint_05(self): # Test RELEASE SAVEPOINT await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT t0') try: await self.con.execute('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "there is no 't1' savepoint"): await self.con.execute(''' RELEASE SAVEPOINT t1; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute(''' RELEASE SAVEPOINT t1; ''') await self.con.query(''' ROLLBACK TO SAVEPOINT t0; ''') await self.con.execute('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "there is no 't1' savepoint"): await self.con.query(''' RELEASE SAVEPOINT t1; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.query(''' RELEASE SAVEPOINT t1; ''') finally: await self.con.query('ROLLBACK') await self.con.execute('SELECT 1;')
) with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute('SELECT 1;') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute(
test_server_proto_tx_savepoint_05
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_savepoint_06(self): # Test that SIMPLE QUERY can combine START TRANSACTION # and DECLARE SAVEPOINT; test basic TransactionError # reflection. await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT t0') try: await self.con.execute('SELECT 1;') with self.assertRaises(edgedb.DivisionByZeroError): await self.con.execute(''' SELECT 1 / 0; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute('SELECT 1;') await self.con.query(''' ROLLBACK TO SAVEPOINT t0; ''') await self.con.execute('SELECT 1;') with self.assertRaises(edgedb.DivisionByZeroError): await self.con.execute(''' SELECT 1 / 0; ''') with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute('SELECT 1;') finally: await self.con.query('ROLLBACK') await self.con.execute('SELECT 1;')
) with self.assertRaisesRegex( edgedb.TransactionError, "current transaction is aborted"): await self.con.execute('SELECT 1;') await self.con.query(
test_server_proto_tx_savepoint_06
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_savepoint_07(self): con = self.con await con.query('START TRANSACTION') await con.query('DECLARE SAVEPOINT t1') await con.execute(f''' SET ALIAS t1 AS MODULE std; SET ALIAS t1 AS MODULE std; ''') await con.query('DECLARE SAVEPOINT t2') await con.execute(f''' SET ALIAS t2 AS MODULE std; ''') self.assertEqual(self.con._get_last_status(), 'SET ALIAS') try: for _ in range(5): self.assertEqual( await con.query('SELECT t1::min({1}) + t2::min({2})'), [3]) await self.con.query('ROLLBACK TO SAVEPOINT t2') for _ in range(5): self.assertEqual( await con.query( 'SELECT t1::min({1}) + std::min({100})'), [101]) with self.assertRaisesRegex( edgedb.InvalidReferenceError, "function 't2::min' does not exist"): await con.query('SELECT t1::min({1}) + t2::min({2})') await self.con.query(''' ROLLBACK TO SAVEPOINT t1; ''') self.assertEqual( await con.query('SELECT std::min({100})'), [100]) with self.assertRaisesRegex( edgedb.InvalidReferenceError, "function 't1::min' does not exist"): await con.query('SELECT t1::min({1})') finally: await con.query('ROLLBACK') with self.assertRaisesRegex( edgedb.InvalidReferenceError, "function 't1::min' does not exist"): await con.query('SELECT t1::min({1})')
) await con.query('DECLARE SAVEPOINT t2') await con.execute(f
test_server_proto_tx_savepoint_07
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_07(self): # Test that START TRANSACTION reflects its modes. try: await self.con.query(''' START TRANSACTION ISOLATION SERIALIZABLE, READ ONLY, DEFERRABLE; ''') with self.assertRaisesRegex( edgedb.TransactionError, 'read-only transaction'): await self.con.query(''' INSERT Tmp { tmp := 'aaa' }; ''') finally: await self.con.query(f''' ROLLBACK; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) with self.assertRaisesRegex( edgedb.TransactionError, 'read-only transaction'): await self.con.query(
test_server_proto_tx_07
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_08(self): try: await self.con.query(''' START TRANSACTION ISOLATION REPEATABLE READ, READ ONLY; ''') self.assertEqual( await self.con.query( 'select <str>sys::get_transaction_isolation();', ), ["RepeatableRead"], ) finally: await self.con.query(f''' ROLLBACK; ''')
) self.assertEqual( await self.con.query( 'select <str>sys::get_transaction_isolation();', ), ["RepeatableRead"], ) finally: await self.con.query(f
test_server_proto_tx_08
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_09(self): try: with self.assertRaisesRegex( edgedb.TransactionError, 'only supported in read-only transactions'): await self.con.query(''' START TRANSACTION ISOLATION REPEATABLE READ; ''') finally: await self.con.query(f''' ROLLBACK; ''')
) finally: await self.con.query(f
test_server_proto_tx_09
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_11(self): # Test that SET ALIAS (and therefore CONFIGURE SESSION SET etc) # tracked by the server behaves exactly like DML tracked by Postgres # when applied around savepoints. async def test_funcs(*, count, working, not_working): for ns in working: self.assertEqual( await self.con.query(f'SELECT {ns}::min({{1}})'), [1]) await self.con.query('DECLARE SAVEPOINT _') for ns in not_working: with self.assertRaises(edgedb.errors.InvalidReferenceError): try: await self.con.query(f'SELECT {ns}::min({{1}})') finally: await self.con.query('ROLLBACK TO SAVEPOINT _;') await self.con.query('RELEASE SAVEPOINT _') actual_count = await self.con.query_single( '''SELECT count( Tmp11 FILTER Tmp11.tmp = "test_server_proto_tx_11") ''') self.assertEqual(actual_count, count) await self.con.execute(''' CREATE TYPE Tmp11 { CREATE REQUIRED PROPERTY tmp -> std::str; }; ''') await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT c0') await self.con.query('SET ALIAS f1 AS MODULE std') await self.con.execute(''' INSERT Tmp11 { tmp := 'test_server_proto_tx_11' }; ''') await self.con.query('DECLARE SAVEPOINT c1') await self.con.query('COMMIT') await self.con.query('START TRANSACTION') await self.con.query('SET ALIAS f2 AS MODULE std') await self.con.execute(''' INSERT Tmp11 { tmp := 'test_server_proto_tx_11' }; ''') await self.con.query('DECLARE SAVEPOINT a0') await self.con.query('SET ALIAS f3 AS MODULE std') await self.con.execute(''' INSERT Tmp11 { tmp := 'test_server_proto_tx_11' }; ''') await self.con.query('DECLARE SAVEPOINT a1') await self.con.query('SET ALIAS f4 AS MODULE std') await self.con.execute(''' INSERT Tmp11 { tmp := 'test_server_proto_tx_11' }; ''') with self.assertRaises(edgedb.DivisionByZeroError): await self.con.query('SELECT 1 / 0') await self.con.query('ROLLBACK TO SAVEPOINT a1') await test_funcs( count=3, working=['f1', 'f2', 'f3'], not_working=['f4', 'f5']) await self.con.query('ROLLBACK TO SAVEPOINT a0') await test_funcs( count=2, working=['f1', 'f2'], not_working=['f3', 'f4', 'f5']) await self.con.query('ROLLBACK') await self.con.query('START TRANSACTION') await test_funcs( count=1, working=['f1'], not_working=['f2', 'f3', 'f4', 'f5']) await self.con.query('COMMIT')
SELECT count( Tmp11 FILTER Tmp11.tmp = "test_server_proto_tx_11") ''') self.assertEqual(actual_count, count) await self.con.execute(
test_server_proto_tx_11
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_12(self): # Test that savepoint's state isn't corrupted by repeated # rolling back to it and stacking changes on top. await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT c0') await self.con.query('SET ALIAS z1 AS MODULE std') await self.con.query('DECLARE SAVEPOINT c1') for _ in range(3): with self.assertRaises(edgedb.DivisionByZeroError): await self.con.execute(''' SET ALIAS z2 AS MODULE std; SELECT 1 / 0; ''') await self.con.query('ROLLBACK TO SAVEPOINT c1') await self.con.query(''' SET ALIAS z3 AS MODULE std; ''') await self.con.query('ROLLBACK TO SAVEPOINT c1') self.assertEqual( await self.con.query('SELECT z1::min({1})'), [1]) await self.con.query('DECLARE SAVEPOINT _;') for ns in ['z2', 'z3']: with self.assertRaises(edgedb.errors.InvalidReferenceError): try: await self.con.query(f'SELECT {ns}::min({{1}})') finally: await self.con.query('ROLLBACK TO SAVEPOINT _;') await self.con.query('RELEASE SAVEPOINT _;') self.assertEqual( await self.con.query('SELECT z1::min({1})'), [1]) await self.con.query('ROLLBACK')
) await self.con.query('ROLLBACK TO SAVEPOINT c1') await self.con.query(
test_server_proto_tx_12
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_13(self): # Test COMMIT abort async def test_funcs(*, working, not_working): for ns in working: self.assertEqual( await self.con.query(f'SELECT {ns}::min({{1}})'), [1]) for ns in not_working: with self.assertRaises(edgedb.errors.InvalidReferenceError): await self.con.query(f'SELECT {ns}::min({{1}})') self.assertTrue(await self.is_testmode_on()) try: await self.con.execute(''' CREATE TYPE Tmp_tx_13 { CREATE PROPERTY tmp_tx_13_1 -> int64; }; ALTER TYPE Tmp_tx_13 { CREATE LINK tmp_tx_13_2 -> Tmp_tx_13 { ON TARGET DELETE DEFERRED RESTRICT; }; }; INSERT Tmp_tx_13 { tmp_tx_13_1 := 1 }; INSERT Tmp_tx_13 { tmp_tx_13_1 := 2, tmp_tx_13_2 := DETACHED ( SELECT Tmp_tx_13 FILTER Tmp_tx_13.tmp_tx_13_1 = 1 LIMIT 1 ) }; SET ALIAS f1 AS MODULE std; ''') await self.con.query('START TRANSACTION') await self.con.execute(''' SET ALIAS f2 AS MODULE std; CONFIGURE SESSION SET __internal_testmode := false; ''') await self.con.query('SET ALIAS f3 AS MODULE std') await self.con.execute(''' DELETE (SELECT Tmp_tx_13 FILTER Tmp_tx_13.tmp_tx_13_1 = 1); SET ALIAS f4 AS MODULE std; ''') self.assertFalse( await self.con.query_single(''' SELECT cfg::Config.__internal_testmode LIMIT 1 ''') ) with self.assertRaises(edgedb.ConstraintViolationError): await self.con.query('COMMIT') await test_funcs(working=['f1'], not_working=['f2', 'f3', 'f4']) finally: await self.con.execute(''' DROP TYPE Tmp_tx_13; ''') self.assertTrue(await self.is_testmode_on())
) await self.con.query('START TRANSACTION') await self.con.execute(
test_server_proto_tx_13
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def worker(con, tx, n): await con.query_single(f''' SELECT count(TransactionTest FILTER .name LIKE 'tx_17_{n}') ''') n2 = 1 if n == 2 else 2 await con.query(f''' INSERT TransactionTest {{ name := 'tx_17_{n2}' }} ''')
) n2 = 1 if n == 2 else 2 await con.query(f
test_server_proto_tx_17.worker
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_17(self): con1 = self.con con2 = await self.connect(database=con1.dbname) tx1 = con1.transaction() tx2 = con2.transaction() await tx1.start() await tx2.start() try: async def worker(con, tx, n): await con.query_single(f''' SELECT count(TransactionTest FILTER .name LIKE 'tx_17_{n}') ''') n2 = 1 if n == 2 else 2 await con.query(f''' INSERT TransactionTest {{ name := 'tx_17_{n2}' }} ''') await asyncio.gather( worker(con1, tx1, 1), worker(con2, tx2, 2) ) await tx1.commit() with self.assertRaises(edgedb.TransactionSerializationError): await tx2.commit() finally: if tx1.is_active(): await tx1.rollback() if tx2.is_active(): await tx2.rollback() await con2.aclose()
) n2 = 1 if n == 2 else 2 await con.query(f
test_server_proto_tx_17
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_19(self): # A regression test ensuring that optimistic execute supports # custom scalar types; unfortunately no way to test that if # the Python driver is implemented correctly. Still, this # test might catch regressions in the python driver or # detect new edge cases in the server implementation. # Not using a transaction here because optimistic execute isn't # enabled in transactions with DDL. # Note: don't change this test. If need be, copy/paste it and # add new stuff to it. typename = f'test_{uuid.uuid4().hex}' await self.con.execute(f''' CREATE SCALAR TYPE {typename} EXTENDING int64; ''') for _ in range(10): result = await self.con.query_single(f''' SELECT <{typename}>100000 ''') self.assertEqual(result, 100000) result = await self.con.query_single(''' SELECT "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ''') self.assertEqual( result, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
) for _ in range(10): result = await self.con.query_single(f
test_server_proto_tx_19
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_23(self): # Test that default_transaction_isolation is respected await self.con.query(''' CONFIGURE SESSION SET default_transaction_isolation := 'RepeatableRead'; ''') try: await self.assert_tx_isolation_and_default('RepeatableRead') finally: await self.con.query(''' CONFIGURE SESSION RESET default_transaction_isolation; ''')
) try: await self.assert_tx_isolation_and_default('RepeatableRead') finally: await self.con.query(
test_server_proto_tx_23
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_24(self): # default_transaction_isolation < Serializable enforces read-only await self.con.query(''' CONFIGURE SESSION SET default_transaction_isolation := 'RepeatableRead'; ''') try: await self.assert_read_only_and_default( "cannot execute.*RepeatableRead", default='ReadWrite', ) finally: await self.con.query(''' CONFIGURE SESSION RESET default_transaction_isolation; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) try: await self.assert_read_only_and_default( "cannot execute.*RepeatableRead", default='ReadWrite', ) finally: await self.con.query(
test_server_proto_tx_24
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_25(self): # default_transaction_isolation < Serializable overrides read-write try: await self.con.query(''' CONFIGURE SESSION SET default_transaction_isolation := 'RepeatableRead'; ''') await self.con.query(''' CONFIGURE SESSION SET default_transaction_access_mode := 'ReadWrite'; ''') await self.assert_read_only_and_default( "cannot execute.*RepeatableRead", default='ReadWrite', ) finally: await self.con.query(''' CONFIGURE SESSION RESET default_transaction_access_mode; ''') await self.con.query(''' CONFIGURE SESSION RESET default_transaction_isolation; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) await self.con.query(
test_server_proto_tx_25
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_26(self): # Test that default_transaction_access_mode is respected await self.con.query(''' CONFIGURE SESSION SET default_transaction_access_mode := 'ReadOnly'; ''') try: await self.assert_tx_isolation_and_default('Serializable') await self.assert_read_only_and_default('cannot execute.*ReadOnly') finally: await self.con.query(''' CONFIGURE SESSION RESET default_transaction_access_mode; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) try: await self.assert_tx_isolation_and_default('Serializable') await self.assert_read_only_and_default('cannot execute.*ReadOnly') finally: await self.con.query(
test_server_proto_tx_26
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_27(self): # Test that START TRANSACTION respects the default isolation try: await self.con.query(''' CONFIGURE SESSION SET default_transaction_isolation := 'RepeatableRead'; ''') await self.con.query(''' START TRANSACTION; ''') await self.assert_tx_isolation_and_default('RepeatableRead') finally: await self.con.query(f''' ROLLBACK; ''') await self.con.query(''' CONFIGURE SESSION RESET default_transaction_isolation; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) await self.con.query(
test_server_proto_tx_27
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_28(self): # Test that non-serializable START TRANSACTION enforces read-only try: await self.con.query(''' CONFIGURE SESSION SET default_transaction_isolation := 'RepeatableRead'; ''') await self.con.query(''' START TRANSACTION; ''') await self.assert_read_only_and_default( 'read-only transaction', default='ReadWrite' ) finally: await self.con.query(f''' ROLLBACK; ''') await self.con.query(''' CONFIGURE SESSION RESET default_transaction_isolation; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) await self.con.query(
test_server_proto_tx_28
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_29(self): # Test that START TRANSACTION respects default read-only try: await self.con.query(''' CONFIGURE SESSION SET default_transaction_access_mode:= 'ReadOnly'; ''') await self.con.query(''' START TRANSACTION; ''') await self.assert_tx_isolation_and_default('Serializable') await self.assert_read_only_and_default('read-only transaction') finally: await self.con.query(f''' ROLLBACK; ''') await self.con.query(''' CONFIGURE SESSION RESET default_transaction_access_mode; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) await self.con.query(
test_server_proto_tx_29
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_30(self): # Test that non-serializable START TRANSACTION conflicts read-write try: await self.con.query(''' CONFIGURE SESSION SET default_transaction_isolation := 'RepeatableRead'; ''') with self.assertRaisesRegex( edgedb.TransactionError, 'only supported in read-only transactions', ): await self.con.query(''' START TRANSACTION READ WRITE; ''') finally: await self.con.query(f''' ROLLBACK; ''') await self.con.query(''' CONFIGURE SESSION RESET default_transaction_isolation; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) with self.assertRaisesRegex( edgedb.TransactionError, 'only supported in read-only transactions', ): await self.con.query(
test_server_proto_tx_30
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_tx_31(self): # Test that non-serializable START TRANSACTION works fine with the # default read-only try: await self.con.query(''' CONFIGURE SESSION SET default_transaction_access_mode:= 'ReadOnly'; ''') await self.con.query(''' START TRANSACTION ISOLATION REPEATABLE READ; ''') await self.assert_tx_isolation_and_default( 'RepeatableRead', default='Serializable' ) await self.assert_read_only_and_default('read-only transaction') finally: await self.con.query(f''' ROLLBACK; ''') await self.con.query(''' CONFIGURE SESSION RESET default_transaction_access_mode; ''') self.assertEqual( await self.con.query('SELECT 42'), [42])
) await self.con.query(
test_server_proto_tx_31
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_ddlprop_01(self): if not self.has_create_role: self.skipTest('create role is not supported by the backend') conargs = self.get_connect_args() await self.con.execute(''' CREATE TYPE Test { CREATE PROPERTY foo -> int16; }; INSERT Test { foo := 123 }; ''') self.assertEqual( await self.con.query_single('SELECT Test.foo LIMIT 1'), 123 ) server_args = self.get_adjacent_server_args() async with tb.start_edgedb_server(**server_args) as sd: con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database=self.get_database_name(), ) try: self.assertEqual( await con2.query_single('SELECT Test.foo LIMIT 1'), 123 ) await self.con.execute(''' CREATE TYPE Test2 { CREATE PROPERTY foo -> str; }; INSERT Test2 { foo := 'text' }; ''') self.assertEqual( await self.con.query_single('SELECT Test2.foo LIMIT 1'), 'text' ) # Give some time for the other server to re-introspect the # schema: the first attempt of querying Test2 might fail. # We'll give it generous 30 seconds to accomodate slow CI. async for tr in self.try_until_succeeds( ignore=edgedb.InvalidReferenceError, timeout=30, ): async with tr: self.assertEqual( await con2.query_single( 'SELECT Test2.foo LIMIT 1', ), 'text', ) finally: await con2.aclose() # Other tests mutate global DDL, hence try a few times. async for tr in self.try_until_succeeds( ignore=edgedb.TransactionSerializationError ): async with tr: await self.con.execute(''' CREATE SUPERUSER ROLE ddlprop01 { SET password := 'aaaa'; } ''') # Give some time for the other server to receive the # updated roles notification and re-fetch them. # We'll give it generous 5 seconds to accomodate slow CI. async for tr in self.try_until_succeeds( ignore=edgedb.AuthenticationError ): async with tr: con3 = await sd.connect( user='ddlprop01', password='aaaa', database=self.get_database_name(), ) try: self.assertEqual( await con3.query_single('SELECT 42'), 42 ) finally: await con3.aclose() # Other tests mutate global DDL, hence try a few times. async for tr in self.try_until_succeeds( ignore=edgedb.TransactionSerializationError ): async with tr: await self.con.execute(''' DROP ROLE ddlprop01; ''')
) self.assertEqual( await self.con.query_single('SELECT Test.foo LIMIT 1'), 123 ) server_args = self.get_adjacent_server_args() async with tb.start_edgedb_server(**server_args) as sd: con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database=self.get_database_name(), ) try: self.assertEqual( await con2.query_single('SELECT Test.foo LIMIT 1'), 123 ) await self.con.execute(
test_server_proto_ddlprop_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_adjacent_database_propagation(self): if not self.has_create_database: self.skipTest('create database is not supported by the backend') conargs = self.get_connect_args() server_args = self.get_adjacent_server_args() async with tb.start_edgedb_server(**server_args) as sd: # Run twice to make sure there is no lingering accessibility state for _ in range(2): await self.con.execute(''' CREATE DATABASE test_db_prop; ''') # Make sure the adjacent server picks up on the new db async for tr in self.try_until_succeeds( ignore=edgedb.UnknownDatabaseError, timeout=30, ): async with tr: con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database="test_db_prop", ) await con2.query("select 1") await con2.aclose() await tb.drop_db(self.con, 'test_db_prop') # Wait until the drop message hit the adjacent server, or the # next create may make the db inaccessible, see also #5081 with self.assertRaises(edgedb.UnknownDatabaseError): while True: async for tr in self.try_until_succeeds( ignore=edgedb.AccessError, timeout=30, ): async with tr: con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database="test_db_prop", ) await con2.aclose() # Now, recreate the DB and try the other way around con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database=self.get_database_name(), ) await con2.execute(''' CREATE DATABASE test_db_prop; ''') # Accessible from the adjacent server con3 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database="test_db_prop", ) await con3.query("select 1") await con3.aclose() async for tr in self.try_until_succeeds( ignore=edgedb.UnknownDatabaseError, timeout=30, ): async with tr: con1 = await self.connect(database="test_db_prop") await con1.query("select 1") await con1.aclose() await tb.drop_db(con2, 'test_db_prop') await con2.aclose()
) # Make sure the adjacent server picks up on the new db async for tr in self.try_until_succeeds( ignore=edgedb.UnknownDatabaseError, timeout=30, ): async with tr: con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database="test_db_prop", ) await con2.query("select 1") await con2.aclose() await tb.drop_db(self.con, 'test_db_prop') # Wait until the drop message hit the adjacent server, or the # next create may make the db inaccessible, see also #5081 with self.assertRaises(edgedb.UnknownDatabaseError): while True: async for tr in self.try_until_succeeds( ignore=edgedb.AccessError, timeout=30, ): async with tr: con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database="test_db_prop", ) await con2.aclose() # Now, recreate the DB and try the other way around con2 = await sd.connect( user=conargs.get('user'), password=conargs.get('password'), database=self.get_database_name(), ) await con2.execute(
test_server_adjacent_database_propagation
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_01(self): typename = 'CacheInv_01' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; INSERT {typename} {{ prop1 := 'aaa' }}; ''') query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::int64; }}; INSERT {typename} {{ prop1 := 123 }}; ''') for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set([123])) finally: await con2.aclose()
) query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f
test_server_proto_query_cache_invalidate_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_02(self): typename = 'CacheInv_02' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.query(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; ''') await con2.query(f''' INSERT {typename} {{ prop1 := 'aaa' }}; ''') query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.query(f''' DELETE (SELECT {typename}); ''') await con2.query(f''' ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ''') await con2.query(f''' ALTER TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::int64; }}; ''') await con2.query(f''' INSERT {typename} {{ prop1 := 123 }}; ''') for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set([123])) finally: await con2.aclose()
) await con2.query(f
test_server_proto_query_cache_invalidate_02
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_03(self): typename = 'CacheInv_03' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> array<std::str>; }}; INSERT {typename} {{ prop1 := ['a', 'aa'] }}; ''') query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set([['a', 'aa']])) await con2.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> array<std::int64>; }}; INSERT {typename} {{ prop1 := [1, 23] }}; ''') for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set([[1, 23]])) finally: await con2.aclose()
) query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set([['a', 'aa']])) await con2.execute(f
test_server_proto_query_cache_invalidate_03
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_04(self): typename = 'CacheInv_04' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; INSERT {typename} {{ prop1 := 'aaa' }}; ''') query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED MULTI PROPERTY prop1 -> std::str; }}; INSERT {typename} {{ prop1 := {{'bbb', 'ccc'}} }}; ''') for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['bbb', 'ccc'])) finally: await con2.aclose()
) query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f
test_server_proto_query_cache_invalidate_04
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_05(self): typename = 'CacheInv_05' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; CREATE TYPE Other{typename} {{ CREATE REQUIRED PROPERTY prop2 -> std::str; }}; INSERT {typename} {{ prop1 := 'aaa' }}; INSERT Other{typename} {{ prop2 := 'bbb' }}; ''') query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED LINK prop1 -> Other{typename}; }}; INSERT {typename} {{ prop1 := (SELECT Other{typename} LIMIT 1) }}; ''') other = await con1.query(f'SELECT Other{typename}') for _ in range(5): self.assertEqual( [x.id for x in await con1.query(query)], [x.id for x in other], ) finally: await con2.aclose()
) query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f
test_server_proto_query_cache_invalidate_05
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_06(self): typename = 'CacheInv_06' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE Foo{typename}; CREATE TYPE Bar{typename}; CREATE TYPE {typename} {{ CREATE REQUIRED LINK link1 -> Foo{typename}; }}; INSERT Foo{typename}; INSERT Bar{typename}; INSERT {typename} {{ link1 := (SELECT Foo{typename} LIMIT 1) }}; ''') foo = await con1.query(f'SELECT Foo{typename}') bar = await con1.query(f'SELECT Bar{typename}') query = f'SELECT {typename}.link1' for _ in range(5): self.assertEqual( [x.id for x in await con1.query(query)], [x.id for x in foo], ) await con2.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP LINK link1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED LINK link1 -> Bar{typename}; }}; INSERT {typename} {{ link1 := (SELECT Bar{typename} LIMIT 1) }}; ''') for _ in range(5): self.assertEqual( [x.id for x in await con1.query(query)], [x.id for x in bar], ) finally: await con2.aclose()
) foo = await con1.query(f'SELECT Foo{typename}') bar = await con1.query(f'SELECT Bar{typename}') query = f'SELECT {typename}.link1' for _ in range(5): self.assertEqual( [x.id for x in await con1.query(query)], [x.id for x in foo], ) await con2.execute(f
test_server_proto_query_cache_invalidate_06
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_07(self): typename = 'CacheInv_07' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE Foo{typename}; CREATE ABSTRACT LINK link1 {{ CREATE PROPERTY prop1 -> std::str; }}; CREATE TYPE {typename} {{ CREATE REQUIRED LINK link1 EXTENDING link1 -> Foo{typename}; }}; INSERT Foo{typename}; INSERT {typename} {{ link1 := ( SELECT assert_single(Foo{typename}) {{@prop1 := 'aaa'}} ) }}; ''') query = f'SELECT {typename}.link1@prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f''' DELETE (SELECT {typename}); ALTER ABSTRACT LINK link1 {{ DROP PROPERTY prop1; }}; ALTER ABSTRACT LINK link1 {{ CREATE PROPERTY prop1 -> std::int64; }}; INSERT {typename} {{ link1 := ( (SELECT Foo{typename} LIMIT 1) {{@prop1 := 123}} ) }}; ''') for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set([123])) finally: await con2.aclose()
) query = f'SELECT {typename}.link1@prop1' for _ in range(5): self.assertEqual( await con1.query(query), edgedb.Set(['aaa'])) await con2.execute(f
test_server_proto_query_cache_invalidate_07
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_09(self): typename = 'CacheInv_09' await self.con.query('START TRANSACTION') try: await self.con.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; INSERT {typename} {{ prop1 := 'aaa' }}; ''') query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await self.con.query(query), edgedb.Set(['aaa'])) await self.con.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::int64; }}; INSERT {typename} {{ prop1 := 123 }}; ''') for _ in range(5): self.assertEqual( await self.con.query(query), edgedb.Set([123])) finally: await self.con.query('ROLLBACK')
) query = f'SELECT {typename}.prop1' for _ in range(5): self.assertEqual( await self.con.query(query), edgedb.Set(['aaa'])) await self.con.execute(f
test_server_proto_query_cache_invalidate_09
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_10(self): typename = 'CacheInv_10' con1 = self.con con2 = await self.connect(database=con1.dbname) try: await con2.execute(f''' CREATE TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::str; }}; INSERT {typename} {{ prop1 := 'aaa' }}; ''') sleep = 3 query = ( f"# EDGEDB_TEST_COMPILER_SLEEP = {sleep}\n" f"SELECT {typename}.prop1" ) task = self.loop.create_task(con1.query(query)) start = time.monotonic() await con2.execute(f''' DELETE (SELECT {typename}); ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; ALTER TYPE {typename} {{ CREATE REQUIRED PROPERTY prop1 -> std::int64; }}; INSERT {typename} {{ prop1 := 123 }}; ''') if time.monotonic() - start > sleep: self.skipTest("The host is too slow for this test.") # If this happens too much, consider increasing the sleep time # ISE is NOT the right expected result - a proper EdgeDB error is. # FIXME in https://github.com/edgedb/edgedb/issues/6820 with self.assertRaisesRegex( edgedb.errors.InternalServerError, "column .* does not exist", ): await task self.assertEqual( await con1.query(query), edgedb.Set([123]), ) finally: await con2.aclose()
) sleep = 3 query = ( f"# EDGEDB_TEST_COMPILER_SLEEP = {sleep}\n" f"SELECT {typename}.prop1" ) task = self.loop.create_task(con1.query(query)) start = time.monotonic() await con2.execute(f
test_server_proto_query_cache_invalidate_10
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_query_cache_invalidate_11(self): typename = 'CacheInv_11' await self.con.execute(f""" CREATE TYPE {typename} {{ CREATE PROPERTY prop1 -> std::int64; }}; INSERT {typename} {{ prop1 := 42 }}; """) class Rollback(Exception): pass # Cache SELECT 123 so that we don't lock the _query_cache table later await self.con.query('SELECT 123') with self.assertRaises(Rollback): async with self.con.transaction(): # make sure the transaction is started await self.con.query('SELECT 123') # DDL in another connection con2 = await self.connect(database=self.con.dbname) try: await con2.execute(f""" ALTER TYPE {typename} {{ DROP PROPERTY prop1; }}; """) finally: await con2.aclose() # This compiles fine with the schema in the transaction, and # the compile result is cached with an outdated version. # However, the execution fails because the column is already # dropped outside the transaction. # FIXME: ISE is not an ideal error as for user experience here with self.assertRaisesRegex( edgedb.InternalServerError, "column.*does not exist" ): await self.con.query(f'SELECT {typename}.prop1') raise Rollback # Should recompile with latest schema, instead of reusing a wrong cache with self.assertRaisesRegex( edgedb.InvalidReferenceError, "has no link or property 'prop1'" ): await self.con.query(f'SELECT {typename}.prop1')
) class Rollback(Exception): pass # Cache SELECT 123 so that we don't lock the _query_cache table later await self.con.query('SELECT 123') with self.assertRaises(Rollback): async with self.con.transaction(): # make sure the transaction is started await self.con.query('SELECT 123') # DDL in another connection con2 = await self.connect(database=self.con.dbname) try: await con2.execute(f
test_server_proto_query_cache_invalidate_11
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_01(self): async with self._run_and_rollback(): await self.con.execute(''' CREATE SCALAR TYPE tid_prop_01 EXTENDING str; ''') result = await self.con.query_single(''' select 1; SELECT (<array<tid_prop_01>>$input)[1] ''', input=['a', 'b']) self.assertEqual(result, 'b')
) result = await self.con.query_single(
test_server_proto_backend_tid_propagation_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_02(self): try: await self.con.execute(''' CREATE SCALAR TYPE tid_prop_02 EXTENDING str; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_02>>$input)[1] ''', input=['a', 'b']) self.assertEqual(result, 'b') finally: # Retry for https://github.com/edgedb/edgedb/issues/7553 async for tr in self.try_until_succeeds( ignore_regexp="cannot drop type .* " "because other objects depend on it", ): async with tr: await self.con.execute(''' DROP SCALAR TYPE tid_prop_02; ''')
) result = await self.con.query_single(
test_server_proto_backend_tid_propagation_02
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_03(self): try: await self.con.execute(''' START MIGRATION TO { module default { scalar type tid_prop_03 extending str; } }; POPULATE MIGRATION; COMMIT MIGRATION; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_03>>$input)[1] ''', input=['A', 'B']) self.assertEqual(result, 'B') finally: # Retry for https://github.com/edgedb/edgedb/issues/7553 async for tr in self.try_until_succeeds( ignore_regexp="cannot drop type .* " "because other objects depend on it", ): async with tr: await self.con.execute(''' DROP SCALAR TYPE tid_prop_03; ''')
) result = await self.con.query_single(
test_server_proto_backend_tid_propagation_03
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_04(self): try: await self.con.query('START TRANSACTION;') await self.con.execute(f''' CREATE SCALAR TYPE tid_prop_04 EXTENDING str; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_04>>$input)[1] ''', input=['A', 'B']) self.assertEqual(result, 'B') finally: await self.con.query('ROLLBACK')
) result = await self.con.query_single(
test_server_proto_backend_tid_propagation_04
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_05(self): try: await self.con.query('START TRANSACTION') await self.con.query('DECLARE SAVEPOINT s1') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_051 EXTENDING str; ''') await self.con.query('ROLLBACK TO SAVEPOINT s1') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_051 EXTENDING str; CREATE SCALAR TYPE tid_prop_052 EXTENDING str; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_052>>$input)[1] ''', input=['A', 'C']) self.assertEqual(result, 'C') finally: await self.con.query('ROLLBACK')
) await self.con.query('ROLLBACK TO SAVEPOINT s1') await self.con.execute(
test_server_proto_backend_tid_propagation_05
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_06(self): async with self._run_and_rollback(): await self.con.query(''' CREATE SCALAR TYPE tid_prop_06 EXTENDING str; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_06>>$input)[1] ''', input=['a', 'b']) self.assertEqual(result, 'b')
) result = await self.con.query_single(
test_server_proto_backend_tid_propagation_06
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_07(self): try: await self.con.query(''' CREATE SCALAR TYPE tid_prop_07 EXTENDING str; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_07>>$input)[1] ''', input=['a', 'b']) self.assertEqual(result, 'b') finally: # Retry for https://github.com/edgedb/edgedb/issues/7553 async for tr in self.try_until_succeeds( ignore_regexp="cannot drop type .* " "because other objects depend on it", ): async with tr: await self.con.execute(''' DROP SCALAR TYPE tid_prop_07; ''')
) result = await self.con.query_single(
test_server_proto_backend_tid_propagation_07
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_08(self): try: await self.con.query('START TRANSACTION') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_081 EXTENDING str; ''') await self.con.query('COMMIT') await self.con.query('START TRANSACTION') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_082 EXTENDING str; ''') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_083 EXTENDING str; ''') result = await self.con.query_single(''' SELECT (<array<tid_prop_081>>$input)[0] ''', input=['A', 'C']) self.assertEqual(result, 'A') result = await self.con.query_single(''' SELECT (<array<tid_prop_082>>$input)[1] ''', input=['A', 'C']) self.assertEqual(result, 'C') result = await self.con.query_single(''' SELECT (<array<tid_prop_083>>$input)[1] ''', input=['A', 'Z']) self.assertEqual(result, 'Z') finally: await self.con.query('ROLLBACK') # Retry for https://github.com/edgedb/edgedb/issues/7553 async for tr in self.try_until_succeeds( ignore_regexp="cannot drop type .* " "because other objects depend on it", ): async with tr: await self.con.execute(''' DROP SCALAR TYPE tid_prop_081; ''')
) await self.con.query('COMMIT') await self.con.query('START TRANSACTION') await self.con.execute(
test_server_proto_backend_tid_propagation_08
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_backend_tid_propagation_09(self): try: await self.con.query('START TRANSACTION') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_091 EXTENDING str; ''') await self.con.query('COMMIT') await self.con.query('START TRANSACTION') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_092 EXTENDING str; ''') await self.con.execute(''' CREATE SCALAR TYPE tid_prop_093 EXTENDING str; ''') await self.con.query('COMMIT') result = await self.con.query_single(''' SELECT (<array<tid_prop_091>>$input)[0] ''', input=['A', 'C']) self.assertEqual(result, 'A') result = await self.con.query_single(''' SELECT (<array<tid_prop_092>>$input)[1] ''', input=['A', 'C']) self.assertEqual(result, 'C') result = await self.con.query_single(''' SELECT (<array<tid_prop_093>>$input)[1] ''', input=['A', 'Z']) self.assertEqual(result, 'Z') finally: # Retry for https://github.com/edgedb/edgedb/issues/7553 async for tr in self.try_until_succeeds( ignore_regexp="cannot drop type .* " "because other objects depend on it", ): async with tr: await self.con.execute(''' DROP SCALAR TYPE tid_prop_091; DROP SCALAR TYPE tid_prop_092; DROP SCALAR TYPE tid_prop_093; ''')
) await self.con.query('COMMIT') await self.con.query('START TRANSACTION') await self.con.execute(
test_server_proto_backend_tid_propagation_09
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_server_proto_fetch_limit_01(self): try: await self.con.execute(''' CREATE TYPE FL_A { CREATE PROPERTY n -> int64; }; CREATE TYPE FL_B { CREATE PROPERTY n -> int64; CREATE MULTI LINK a -> FL_A; }; FOR i IN {1, 2, 3, 4, 5} UNION ( INSERT FL_A { n := i } ); FOR i IN {1, 2, 3, 4, 5} UNION ( INSERT FL_B { n := i, a := FL_A, } ); ''') result = await self.con._fetchall( r""" SELECT FL_B { id, __type__, a, } ORDER BY .n """, __limit__=2 ) self.assertEqual(len(result), 2) self.assertEqual(len(result[0].a), 2) result = await self.con._fetchall( r""" SELECT FL_B { a ORDER BY .n, a_arr := array_agg(.a) } ORDER BY .n """, __limit__=2 ) self.assertEqual(len(result), 2) self.assertEqual(len(result[0].a), 2) self.assertEqual(len(result[0].a_arr), 2) # Check that things are not cached improperly. result = await self.con._fetchall( r""" SELECT FL_B { a ORDER BY .n, a_arr := array_agg(.a) } ORDER BY .n """, __limit__=3 ) self.assertEqual(len(result), 3) self.assertEqual(len(result[0].a), 3) self.assertEqual(len(result[0].a_arr), 3) # Check that explicit LIMIT is not overridden result = await self.con._fetchall( r""" SELECT FL_B { a ORDER BY .n LIMIT 3, a_arr := array_agg((SELECT .a LIMIT 3)), a_count := count(.a), a_comp := (SELECT .a LIMIT 3), } ORDER BY .n LIMIT 3 """, __limit__=4 ) self.assertEqual(len(result), 3) self.assertEqual(len(result[0].a), 3) self.assertEqual(len(result[0].a_arr), 3) self.assertEqual(len(result[0].a_comp), 3) self.assertEqual(result[0].a_count, 5) # Check that implicit limit does not break inline aliases. result = await self.con._fetchall( r""" WITH a := {11, 12, 13} SELECT _ := {9, 1, 13} FILTER _ IN a; """, __limit__=1 ) self.assertEqual(result, edgedb.Set([13])) # Check that things cast to JSON don't get limited. result = await self.con._fetchall( r""" WITH a := {11, 12, 13} SELECT <json>array_agg(a); """, __limit__=1 ) self.assertEqual(result, edgedb.Set(['[11, 12, 13]'])) # Check that non-array_agg calls don't get limited. result = await self.con._fetchall( r""" WITH a := {11, 12, 13} SELECT max(a); """, __limit__=1 ) self.assertEqual(result, edgedb.Set([13])) finally: await self.con.execute(''' DROP TYPE FL_B; DROP TYPE FL_A; ''')
) result = await self.con._fetchall( r
test_server_proto_fetch_limit_01
python
geldata/gel
tests/test_server_proto.py
https://github.com/geldata/gel/blob/master/tests/test_server_proto.py
Apache-2.0
async def test_edgeql_select_computable_18(self): async with self._run_and_rollback(): await self.con.execute( ''' INSERT Publication { title := 'aaa' } ''' ) await self.assert_query_result( r""" SELECT Publication { title, title1, title2, title3, title4, title5, title6, } FILTER .title = 'aaa' """, [{ 'title': 'aaa', 'title1': 'aaa', 'title2': 'aaa', 'title3': 'aaa', 'title4': 'aaa', 'title5': ['aaa'], 'title6': ['aaa'], }] )
INSERT Publication { title := 'aaa' }
test_edgeql_select_computable_18
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_computable_32(self): await self.assert_query_result( r""" SELECT _ := (User {x := .name}.x, (SELECT User.name)) ORDER BY _; """, [ ['Elvis', 'Elvis'], ['Yury', 'Yury'], ] ) await self.assert_query_result( r""" SELECT _ := ((SELECT User.name), User {x := .name}.x) ORDER BY _; """, [ ['Elvis', 'Elvis'], ['Yury', 'Yury'], ] ) await self.assert_query_result( r""" SELECT _ := ((SELECT User.name), (User {x := .name},).0.x) ORDER BY _; """, [ ['Elvis', 'Elvis'], ['Yury', 'Yury'], ] )
, [ ['Elvis', 'Elvis'], ['Yury', 'Yury'], ] ) await self.assert_query_result( r
test_edgeql_select_computable_32
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_computable_33(self): await self.assert_query_result( r""" SELECT User {name, todo_ids := .todo.id} FILTER .name = 'Elvis'; """, [ {'name': 'Elvis', 'todo_ids': [str, str]}, ] ) await self.assert_query_result( r""" WITH Z := (SELECT User { asdf := (SELECT .todo ORDER BY .number LIMIT 1)}) SELECT Z {name, asdf_id := .asdf.id} FILTER .name = 'Elvis'; """, [ {'name': 'Elvis', 'asdf_id': str}, ] )
, [ {'name': 'Elvis', 'todo_ids': [str, str]}, ] ) await self.assert_query_result( r
test_edgeql_select_computable_33
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_match_01(self): await self.assert_query_result( r""" SELECT Issue {number} FILTER Issue.name LIKE '%edgedb' ORDER BY Issue.number; """, [], ) await self.assert_query_result( r""" SELECT Issue {number} FILTER Issue.name LIKE '%EdgeDB' ORDER BY Issue.number; """, [{'number': '1'}], ) await self.assert_query_result( r""" SELECT Issue {number} FILTER Issue.name LIKE '%Edge%' ORDER BY Issue.number; """, [{'number': '1'}, {'number': '2'}], )
, [], ) await self.assert_query_result( r
test_edgeql_select_match_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0