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_object_as_lprop_02(self):
"""
type Tgt;
type Tgt2;
type Src {
multi tgts: Tgt {
}
};
type Src2 extending Src {
overloaded multi tgts: Tgt {
lprop: Tgt2;
}
};
""" | type Tgt;
type Tgt2;
type Src {
multi tgts: Tgt {
}
};
type Src2 extending Src {
overloaded multi tgts: Tgt {
lprop: Tgt2;
}
}; | test_schema_object_as_lprop_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_func_optional_variadic_01(self):
"""
function foo(variadic bar: optional int64) -> array<int64>
using (assert_exists(bar));
""" | function foo(variadic bar: optional int64) -> array<int64>
using (assert_exists(bar)); | test_schema_func_optional_variadic_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_global_01(self):
"""
global two_things: TwoThings;
scalar type TwoThings extending enum<One, Two>;
""" | global two_things: TwoThings;
scalar type TwoThings extending enum<One, Two>; | test_schema_global_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_hard_sorting_01(self):
# This is hard to sort properly because we don't understand the types.
# From #4683.
"""
global current_user_id -> uuid;
global current_user := (
select User filter .id = global current_user_id
);
global current_user_role := (
(global current_user).role.slug
);
type Role {
property slug -> str;
}
type User {
required link role -> Role;
}
""" | global current_user_id -> uuid;
global current_user := (
select User filter .id = global current_user_id
);
global current_user_role := (
(global current_user).role.slug
);
type Role {
property slug -> str;
}
type User {
required link role -> Role;
} | test_schema_hard_sorting_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_hard_sorting_02(self):
# This is hard to sort properly because we don't understand the types.
# From #5163
"""
type Branch;
type CO2DataPoint{
required link datapoint -> DataPoint;
link branch := .datapoint.data_entry.branch;
}
type DataPoint{
required link data_entry := assert_exists(
.<data_points[is DataEntry]);
}
type DataEntry{
required link branch -> Branch;
multi link data_points -> DataPoint;
}
""" | type Branch;
type CO2DataPoint{
required link datapoint -> DataPoint;
link branch := .datapoint.data_entry.branch;
}
type DataPoint{
required link data_entry := assert_exists(
.<data_points[is DataEntry]);
}
type DataEntry{
required link branch -> Branch;
multi link data_points -> DataPoint;
} | test_schema_hard_sorting_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_hard_sorting_03(self):
# This is hard to sort properly because we don't understand the types.
"""
type A {
property foo := assert_exists(B).bar;
};
type B {
property bar := 1;
};
""" | type A {
property foo := assert_exists(B).bar;
};
type B {
property bar := 1;
}; | test_schema_hard_sorting_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_hard_sorting_04(self):
# This is hard to sort properly because we don't understand the types.
"""
type A {
property foo := (
with Z := assert_exists(B) select Z.bar);
};
type B {
property bar := 1;
};
""" | type A {
property foo := (
with Z := assert_exists(B) select Z.bar);
};
type B {
property bar := 1;
}; | test_schema_hard_sorting_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_hard_sorting_05(self):
"""
type T {
multi as: A;
multi bs: B;
sections := (
select (.as union .bs)
filter .index > 0
);
}
abstract type I {
required index: int16;
}
type A extending I;
type B extending I;
""" | type T {
multi as: A;
multi bs: B;
sections := (
select (.as union .bs)
filter .index > 0
);
}
abstract type I {
required index: int16;
}
type A extending I;
type B extending I; | test_schema_hard_sorting_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_refs_01(self):
schema = self.load_schema("""
type Object1;
type Object2 {
link foo -> Object1
};
type Object3 extending Object1;
type Object4 extending Object1;
type Object5 {
link bar -> Object2
};
type Object6 extending Object4;
""")
Obj1 = schema.get('test::Object1')
Obj2 = schema.get('test::Object2')
Obj3 = schema.get('test::Object3')
Obj4 = schema.get('test::Object4')
Obj5 = schema.get('test::Object5')
Obj6 = schema.get('test::Object6')
obj1_id = Obj1.getptr(schema, s_name.UnqualName('id'))
obj1_type = Obj1.getptr(schema, s_name.UnqualName('__type__'))
obj1_type_source = obj1_type.getptr(
schema, s_name.UnqualName('source'))
obj2_type = Obj2.getptr(schema, s_name.UnqualName('__type__'))
foo = Obj2.getptr(schema, s_name.UnqualName('foo'))
foo_target = foo.getptr(schema, s_name.UnqualName('target'))
bar = Obj5.getptr(schema, s_name.UnqualName('bar'))
self.assertEqual(
schema.get_referrers(Obj1),
frozenset({
foo, # Object 1 is a Object2.foo target
foo_target, # and also a target of its @target property
Obj3, # It is also in Object3's bases and ancestors
Obj4, # Likewise for Object4
Obj6, # Object6 through its ancestors
obj1_id, # Inherited id property
obj1_type, # Inherited __type__ link
obj1_type_source, # and its @source property
})
)
self.assertEqual(
schema.get_referrers(Obj1, scls_type=s_objtypes.ObjectType),
{
Obj3, # It is also in Object3's bases and ancestors
Obj4, # Likewise for Object4
Obj6, # Object6 through its ancestors
}
)
self.assertEqual(
schema.get_referrers(Obj2, scls_type=s_links.Link),
{
foo, # Obj2 is foo's source
bar, # Obj2 is bar's target
obj2_type, # Iherited Obj2.__type__ link
}
)
self.assertEqual(
schema.get_referrers(Obj2, scls_type=s_links.Link,
field_name='target'),
{
bar, # Obj2 is bar's target
}
)
schema = self.run_ddl(schema, '''
ALTER TYPE test::Object4 DROP EXTENDING test::Object1;
''')
self.assertEqual(
schema.get_referrers(Obj1),
frozenset({
foo, # Object 1 is a Object2.foo target
foo_target, # and also a target of its @target property
Obj3, # It is also in Object3's bases and ancestors
obj1_id, # Inherited id property
obj1_type, # Inherited __type__ link
obj1_type_source, # and its @source property
})
)
schema = self.run_ddl(schema, '''
ALTER TYPE test::Object3 DROP EXTENDING test::Object1;
''')
self.assertEqual(
schema.get_referrers(Obj1),
frozenset({
foo, # Object 1 is a Object2.foo target
foo_target, # and also a target of its @target property
obj1_id, # Inherited id property
obj1_type, # Inherited __type__ link
obj1_type_source, # and its @source property
})
)
schema = self.run_ddl(schema, '''
CREATE FUNCTION
test::my_contains(arr: array<anytype>, val: anytype) -> bool {
SET volatility := 'Immutable';
USING (
SELECT contains(arr, val)
);
};
CREATE ABSTRACT CONSTRAINT
test::my_one_of(one_of: array<anytype>) {
USING (
SELECT (
test::my_contains(one_of, __subject__),
).0
);
};
CREATE SCALAR TYPE test::my_scalar_t extending str {
CREATE CONSTRAINT test::my_one_of(['foo', 'bar']);
};
''')
my_scalar_t = schema.get('test::my_scalar_t')
constr = my_scalar_t.get_constraints(schema).objects(schema)[0]
my_contains = schema.get_functions('test::my_contains')[0]
self.assertEqual(
schema.get_referrers(my_contains),
frozenset({
constr,
})
)
self.assertEqual(
schema.get_referrers(Obj1),
frozenset({
foo, # Object 1 is a Object2.foo target
foo_target, # and also a target of its @target property
obj1_id, # Inherited id property
obj1_type, # Inherited __type__ link
obj1_type_source, # and its @source property
})
) | )
Obj1 = schema.get('test::Object1')
Obj2 = schema.get('test::Object2')
Obj3 = schema.get('test::Object3')
Obj4 = schema.get('test::Object4')
Obj5 = schema.get('test::Object5')
Obj6 = schema.get('test::Object6')
obj1_id = Obj1.getptr(schema, s_name.UnqualName('id'))
obj1_type = Obj1.getptr(schema, s_name.UnqualName('__type__'))
obj1_type_source = obj1_type.getptr(
schema, s_name.UnqualName('source'))
obj2_type = Obj2.getptr(schema, s_name.UnqualName('__type__'))
foo = Obj2.getptr(schema, s_name.UnqualName('foo'))
foo_target = foo.getptr(schema, s_name.UnqualName('target'))
bar = Obj5.getptr(schema, s_name.UnqualName('bar'))
self.assertEqual(
schema.get_referrers(Obj1),
frozenset({
foo, # Object 1 is a Object2.foo target
foo_target, # and also a target of its @target property
Obj3, # It is also in Object3's bases and ancestors
Obj4, # Likewise for Object4
Obj6, # Object6 through its ancestors
obj1_id, # Inherited id property
obj1_type, # Inherited __type__ link
obj1_type_source, # and its @source property
})
)
self.assertEqual(
schema.get_referrers(Obj1, scls_type=s_objtypes.ObjectType),
{
Obj3, # It is also in Object3's bases and ancestors
Obj4, # Likewise for Object4
Obj6, # Object6 through its ancestors
}
)
self.assertEqual(
schema.get_referrers(Obj2, scls_type=s_links.Link),
{
foo, # Obj2 is foo's source
bar, # Obj2 is bar's target
obj2_type, # Iherited Obj2.__type__ link
}
)
self.assertEqual(
schema.get_referrers(Obj2, scls_type=s_links.Link,
field_name='target'),
{
bar, # Obj2 is bar's target
}
)
schema = self.run_ddl(schema, | test_schema_refs_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_refs_04(self):
with self.assertRaisesRegex(
errors.InvalidReferenceError,
"__subject__ cannot be used in this expression",
):
self.load_schema(
"""
type User3 {
required property nick: str;
required property name: str {
default := (select __subject__.nick);
};
}
"""
) | type User3 {
required property nick: str;
required property name: str {
default := (select __subject__.nick);
};
} | test_schema_refs_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_constraint_inheritance_05(self):
"""
abstract constraint aaa extending std::max_len_value;
""" | abstract constraint aaa extending std::max_len_value; | test_schema_constraint_inheritance_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_constraint_inheritance_06(self):
"""
abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint bbb(min: std::int64)
extending std::min_len_value;
abstract constraint zzz(max: std::int64)
extending aaa, bbb;
""" | abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint bbb(min: std::int64)
extending std::min_len_value;
abstract constraint zzz(max: std::int64)
extending aaa, bbb; | test_schema_constraint_inheritance_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_constraint_inheritance_07(self):
"""
abstract constraint aaa(max: std::int64, foo: str)
extending std::max_len_value;
abstract constraint zzz(max: std::int64)
extending aaa;
""" | abstract constraint aaa(max: std::int64, foo: str)
extending std::max_len_value;
abstract constraint zzz(max: std::int64)
extending aaa; | test_schema_constraint_inheritance_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_constraint_inheritance_08(self):
"""
abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(max: std::int64)
extending aaa;
""" | abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(max: std::int64)
extending aaa; | test_schema_constraint_inheritance_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_constraint_inheritance_09(self):
"""
abstract constraint aaa(max: std::int64, foo: str)
extending std::max_len_value;
abstract constraint zzz(max: std::str)
extending aaa;
""" | abstract constraint aaa(max: std::int64, foo: str)
extending std::max_len_value;
abstract constraint zzz(max: std::str)
extending aaa; | test_schema_constraint_inheritance_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_constraint_inheritance_10(self):
"""
abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(min: std::str)
extending aaa;
""" | abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(min: std::str)
extending aaa; | test_schema_constraint_inheritance_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_constraint_inheritance_11(self):
"""
abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(max: std::str)
extending aaa;
""" | abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(max: std::str)
extending aaa; | test_schema_constraint_inheritance_11 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_inheritance_12(self):
"""
abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(max: anyscalar)
extending aaa;
""" | abstract constraint aaa(max: std::int64)
extending std::max_len_value;
abstract constraint zzz(max: anyscalar)
extending aaa; | test_schema_constraint_inheritance_12 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_inheritance_13(self):
"""
type A {
property name -> str {
constraint exclusive;
}
}
type B extending A {
overloaded property name -> str {
delegated constraint exclusive;
}
}
""" | type A {
property name -> str {
constraint exclusive;
}
}
type B extending A {
overloaded property name -> str {
delegated constraint exclusive;
}
} | test_schema_constraint_inheritance_13 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_rewrite_missing_required_01(self):
"""
type Project {
required name: str;
required owner: User;
}
type User {
link default_project: Project {
rewrite insert using (
insert Project {
owner := __subject__,
}
)
};
}
""" | type Project {
required name: str;
required owner: User;
}
type User {
link default_project: Project {
rewrite insert using (
insert Project {
owner := __subject__,
}
)
};
} | test_schema_rewrite_missing_required_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_rewrite_order_01(self):
"""
type EventSession extending Timed {
lastSeen: datetime {
rewrite update using (
__old__.foo
)
}
lastSeen2: datetime {
rewrite insert using (
__subject__.foo
)
}
}
abstract type Timed {
required foo: datetime {
default := datetime_current();
}
}
""" | type EventSession extending Timed {
lastSeen: datetime {
rewrite update using (
__old__.foo
)
}
lastSeen2: datetime {
rewrite insert using (
__subject__.foo
)
}
}
abstract type Timed {
required foo: datetime {
default := datetime_current();
}
} | test_schema_rewrite_order_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_rewrite_order_02(self):
# One of the properties is going to reference the other property
# before it is created in its rewrite via __specified__.
# Ensure that this gets ordered correctly.
"""
type User {
property foo -> bool {
rewrite insert using (__specified__.bar);
};
property bar -> bool {
rewrite insert using (__specified__.foo);
};
};
""" | type User {
property foo -> bool {
rewrite insert using (__specified__.bar);
};
property bar -> bool {
rewrite insert using (__specified__.foo);
};
}; | test_schema_rewrite_order_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_scalar_order_01(self):
# Make sure scalar types account for base types when tracing SDL
# dependencies.
"""
scalar type two extending one;
scalar type one extending str;
""" | scalar type two extending one;
scalar type one extending str; | test_schema_scalar_order_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_trigger_order_01(self):
"""
type Feed extending Entity {
trigger sync_trigger_on_update after update for each when (
__old__.field ?= __new__.field
)
do (1)
}
abstract type Entity {
field: str;
}
""" | type Feed extending Entity {
trigger sync_trigger_on_update after update for each when (
__old__.field ?= __new__.field
)
do (1)
}
abstract type Entity {
field: str;
} | test_schema_trigger_order_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_property_cardinality_alter_01(self):
schema = self.load_schema('''
type Foo {
single property foo1 -> str;
single property bar1 := .foo1 ++ '!';
single property foo2 -> str;
property bar2 := .foo2 ++ '!';
}
''')
with self.assertRaisesRegex(
errors.SchemaDefinitionError,
"cannot convert property 'foo1' of object type 'test::Foo' to "
"'multi' cardinality because this affects expression of "
"property 'bar1' of object type 'test::Foo'"
):
self.run_ddl(schema, '''
ALTER TYPE Foo ALTER PROPERTY foo1 SET MULTI
''', default_module='test')
# Altering foo2 is OK, because the computable bar2 was declared
# without explicit cardinality.
self.run_ddl(schema, '''
ALTER TYPE Foo ALTER PROPERTY foo2 SET MULTI
''', default_module='test') | )
with self.assertRaisesRegex(
errors.SchemaDefinitionError,
"cannot convert property 'foo1' of object type 'test::Foo' to "
"'multi' cardinality because this affects expression of "
"property 'bar1' of object type 'test::Foo'"
):
self.run_ddl(schema, | test_schema_property_cardinality_alter_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_property_cardinality_alter_02(self):
schema = self.load_schema('''
type Foo {
single property foo1 -> str;
}
type Bar extending Foo;
''')
with self.assertRaisesRegex(
errors.SchemaDefinitionError,
"cannot redefine the cardinality of property 'foo1' of "
"object type 'test::Bar'.*"
):
self.run_ddl(schema, '''
ALTER TYPE Bar ALTER PROPERTY foo1 SET MULTI
''', default_module='test') | )
with self.assertRaisesRegex(
errors.SchemaDefinitionError,
"cannot redefine the cardinality of property 'foo1' of "
"object type 'test::Bar'.*"
):
self.run_ddl(schema, | test_schema_property_cardinality_alter_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_property_cardinality_alter_03(self):
schema = self.load_schema('''
type Foo {
single property foo1 -> str;
}
type Bar extending Foo;
''')
schema = self.run_ddl(schema, '''
ALTER TYPE Foo ALTER PROPERTY foo1 SET MULTI
''', default_module='test')
Bar = schema.get('test::Bar', type=s_objtypes.ObjectType)
foo1 = Bar.getptr(schema, s_name.UnqualName('foo1'))
self.assertEqual(str(foo1.get_cardinality(schema)), 'Many') | )
schema = self.run_ddl(schema, | test_schema_property_cardinality_alter_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_ref_diamond_inheritance(self):
schema = tb._load_std_schema()
schema = self.run_ddl(schema, '''
CREATE MODULE default;
CREATE TYPE default::A;
CREATE TYPE default::B EXTENDING A;
CREATE TYPE default::C EXTENDING B, A;
''')
orig_get_children = type(schema).get_children
def stable_get_children(self, scls):
children = orig_get_children(self, scls)
return list(sorted(children, key=lambda obj: obj.get_name(schema)))
type(schema).get_children = stable_get_children
try:
schema = self.run_ddl(schema, '''
ALTER TYPE default::A CREATE PROPERTY foo -> str;
''')
finally:
type(schema).get_children = orig_get_children | )
orig_get_children = type(schema).get_children
def stable_get_children(self, scls):
children = orig_get_children(self, scls)
return list(sorted(children, key=lambda obj: obj.get_name(schema)))
type(schema).get_children = stable_get_children
try:
schema = self.run_ddl(schema, | test_schema_ref_diamond_inheritance | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_object_verbosename(self):
schema = self.load_schema("""
abstract inheritable annotation attr;
abstract link lnk_1;
abstract property prop_1;
type Object1 {
annotation attr := 'inherit me';
property foo -> std::str {
annotation attr := 'propprop';
constraint max_len_value(10)
}
link bar -> Object {
constraint exclusive;
annotation attr := 'bbb';
property bar_prop -> std::str {
annotation attr := 'aaa';
constraint max_len_value(10);
}
}
index on (.foo)
};
""")
schema = self.run_ddl(schema, '''
CREATE FUNCTION test::foo (a: int64) -> int64
USING ( SELECT a );
''')
self.assertEqual(
schema.get('test::attr').get_verbosename(schema),
"abstract annotation 'test::attr'",
)
self.assertEqual(
schema.get('test::lnk_1').get_verbosename(schema),
"abstract link 'test::lnk_1'",
)
self.assertEqual(
schema.get('test::prop_1').get_verbosename(schema),
"abstract property 'test::prop_1'",
)
self.assertEqual(
schema.get('std::max_len_value').get_verbosename(schema),
"abstract constraint 'std::max_len_value'",
)
fn = list(schema.get_functions('std::json_typeof'))[0]
self.assertEqual(
fn.get_verbosename(schema),
"function 'std::json_typeof(json: std::json)'",
)
fn_param = fn.get_params(schema).get_by_name(schema, 'json')
self.assertEqual(
fn_param.get_verbosename(schema, with_parent=True),
"parameter 'json' of function 'std::json_typeof(json: std::json)'",
)
op = list(schema.get_operators('std::AND'))[0]
self.assertEqual(
op.get_verbosename(schema),
'operator "std::bool AND std::bool"',
)
obj = schema.get('test::Object1')
self.assertEqual(
obj.get_verbosename(schema),
"object type 'test::Object1'",
)
self.assertEqual(
obj.get_annotations(schema).get(
schema, s_name.QualName('test', 'attr')).get_verbosename(
schema, with_parent=True),
"annotation 'test::attr' of object type 'test::Object1'",
)
foo_prop = obj.get_pointers(schema).get(
schema, s_name.UnqualName('foo'))
self.assertEqual(
foo_prop.get_verbosename(schema, with_parent=True),
"property 'foo' of object type 'test::Object1'",
)
self.assertEqual(
foo_prop.get_annotations(schema).get(
schema, s_name.QualName('test', 'attr')).get_verbosename(
schema, with_parent=True),
"annotation 'test::attr' of property 'foo' of "
"object type 'test::Object1'",
)
self.assertEqual(
next(iter(foo_prop.get_constraints(
schema).objects(schema))).get_verbosename(
schema, with_parent=True),
"constraint 'std::max_len_value' of property 'foo' of "
"object type 'test::Object1'",
)
bar_link = obj.get_pointers(schema).get(
schema, s_name.UnqualName('bar'))
self.assertEqual(
bar_link.get_verbosename(schema, with_parent=True),
"link 'bar' of object type 'test::Object1'",
)
bar_link_prop = bar_link.get_pointers(schema).get(
schema, s_name.UnqualName('bar_prop'))
self.assertEqual(
bar_link_prop.get_annotations(schema).get(
schema, s_name.QualName('test', 'attr')).get_verbosename(
schema, with_parent=True),
"annotation 'test::attr' of property 'bar_prop' of "
"link 'bar' of object type 'test::Object1'",
)
self.assertEqual(
next(iter(bar_link_prop.get_constraints(
schema).objects(schema))).get_verbosename(
schema, with_parent=True),
"constraint 'std::max_len_value' of property 'bar_prop' of "
"link 'bar' of object type 'test::Object1'",
)
self.assertEqual(
next(iter(obj.get_indexes(
schema).objects(schema))).get_verbosename(
schema, with_parent=True),
"index of object type 'test::Object1'",
) | )
schema = self.run_ddl(schema, | test_schema_object_verbosename | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_ancestor_propagation_on_sdl_migration(self):
schema = self.load_schema("""
type A;
type B extending A;
type C extending B;
""")
BaseObject = schema.get('std::BaseObject')
Object = schema.get('std::Object')
A = schema.get('test::A')
B = schema.get('test::B')
C = schema.get('test::C')
std_link = schema.get('std::link')
BaseObject__type__ = BaseObject.getptr(
schema, s_name.UnqualName('__type__'))
Object__type__ = Object.getptr(
schema, s_name.UnqualName('__type__'))
A__type__ = A.getptr(schema, s_name.UnqualName('__type__'))
B__type__ = B.getptr(schema, s_name.UnqualName('__type__'))
C__type__ = C.getptr(schema, s_name.UnqualName('__type__'))
self.assertEqual(
C__type__.get_ancestors(schema).objects(schema),
(
B__type__,
A__type__,
Object__type__,
BaseObject__type__,
std_link,
)
)
schema = self.run_ddl(schema, """
START MIGRATION TO {
module test {
type A;
type B;
type C extending B;
}
};
POPULATE MIGRATION;
COMMIT MIGRATION;
""")
self.assertEqual(
C__type__.get_ancestors(schema).objects(schema),
(
B__type__,
Object__type__,
BaseObject__type__,
std_link,
)
) | )
BaseObject = schema.get('std::BaseObject')
Object = schema.get('std::Object')
A = schema.get('test::A')
B = schema.get('test::B')
C = schema.get('test::C')
std_link = schema.get('std::link')
BaseObject__type__ = BaseObject.getptr(
schema, s_name.UnqualName('__type__'))
Object__type__ = Object.getptr(
schema, s_name.UnqualName('__type__'))
A__type__ = A.getptr(schema, s_name.UnqualName('__type__'))
B__type__ = B.getptr(schema, s_name.UnqualName('__type__'))
C__type__ = C.getptr(schema, s_name.UnqualName('__type__'))
self.assertEqual(
C__type__.get_ancestors(schema).objects(schema),
(
B__type__,
A__type__,
Object__type__,
BaseObject__type__,
std_link,
)
)
schema = self.run_ddl(schema, | test_schema_ancestor_propagation_on_sdl_migration | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_ast_contects_01(self):
schema = self.load_schema("")
schema = self.run_ddl(schema, """
create type test::Foo {
create property asdf := 1 + 2 + 3
};
""")
obj = schema.get('test::Foo')
asdf = obj.getptr(schema, s_name.UnqualName('asdf'))
expr_ast = asdf.get_expr(schema).parse()
self.assertEqual(
expr_ast.span.name,
f'<{asdf.id} expr>'
)
schema = self.run_ddl(schema, """
alter type test::Foo {
create property x -> str { set default := "test" };
}
""")
x = obj.getptr(schema, s_name.UnqualName('x'))
default_ast = x.get_default(schema).parse()
self.assertEqual(
default_ast.span.name,
f'<{x.id} default>'
) | )
obj = schema.get('test::Foo')
asdf = obj.getptr(schema, s_name.UnqualName('asdf'))
expr_ast = asdf.get_expr(schema).parse()
self.assertEqual(
expr_ast.span.name,
f'<{asdf.id} expr>'
)
schema = self.run_ddl(schema, | test_schema_ast_contects_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_backlink_01(self):
"""
type Bar {
link foo -> Foo;
link f := .<bar[IS Foo];
}
type Foo {
link bar := .<foo[IS Bar];
}
""" | type Bar {
link foo -> Foo;
link f := .<bar[IS Foo];
}
type Foo {
link bar := .<foo[IS Bar];
} | test_schema_backlink_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_backlink_02(self):
"""
type Bar {
link foo -> Foo;
link f := .<bar;
}
type Foo {
link bar := .<foo;
}
""" | type Bar {
link foo -> Foo;
link f := .<bar;
}
type Foo {
link bar := .<foo;
} | test_schema_backlink_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_backlink_03(self):
"""
alias B := Bar {
f := .<bar[IS Foo]
};
type Bar {
link foo -> Foo;
}
type Foo {
link bar := .<foo[IS Bar];
}
""" | alias B := Bar {
f := .<bar[IS Foo]
};
type Bar {
link foo -> Foo;
}
type Foo {
link bar := .<foo[IS Bar];
} | test_schema_backlink_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_backlink_04(self):
"""
function foo() -> uuid using (
Bar.<bar[IS Foo].id
);
type Bar {
link foo -> Foo;
}
type Foo {
link bar := .<foo[IS Bar];
}
""" | function foo() -> uuid using (
Bar.<bar[IS Foo].id
);
type Bar {
link foo -> Foo;
}
type Foo {
link bar := .<foo[IS Bar];
} | test_schema_backlink_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_recursive_01(self):
schema = self.load_schema(r'''
type Foo {
link next -> Foo;
property val := 1;
}
''', modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"property 'val' of object type 'default::Foo' "
"is defined recursively"
):
self.run_ddl(schema, '''
ALTER TYPE default::Foo
ALTER PROPERTY val USING (1 + (.next.val ?? 0));
''') | , modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"property 'val' of object type 'default::Foo' "
"is defined recursively"
):
self.run_ddl(schema, | test_schema_recursive_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_recursive_02(self):
schema = self.load_schema(r'''
type Foo {
link next -> Bar;
property val := 1;
}
type Bar {
link next -> Foo;
property val := 1;
}
''', modname='default')
self.run_ddl(schema, '''
ALTER TYPE default::Foo
ALTER PROPERTY val USING (1 + (.next.val ?? 0));
''')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"definition dependency cycle between "
"property 'val' of object type 'default::Bar' and "
"property 'val' of object type 'default::Foo'"
):
self.run_ddl(schema, '''
ALTER TYPE default::Bar
ALTER PROPERTY val USING (1 + (.next.val ?? 0));
# ALTER PROPERTY val USING ('bad');
''') | , modname='default')
self.run_ddl(schema, | test_schema_recursive_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_recursive_03(self):
schema = self.load_schema(r'''
function foo(v: int64) -> int64 using (
1 + v
);
''', modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
r"function 'default::foo\(v:.+int64\)' "
r"is defined recursively"
):
self.run_ddl(schema, '''
ALTER FUNCTION foo(v: int64) USING (
0 IF v < 0 ELSE 1 + foo(v -1)
);
''')
# Make sure unrelated functions with similar prefix
# aren't matched erroneously (#3115)
schema = self.load_schema(r'''
function len_strings(words: str) -> int64 using (
len(words)
);
''', modname='default') | , modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
r"function 'default::foo\(v:.+int64\)' "
r"is defined recursively"
):
self.run_ddl(schema, | test_schema_recursive_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_recursive_04(self):
schema = self.load_schema(r'''
function foo(v: int64) -> int64 using (
1 + v
);
function bar(v: int64) -> int64 using (
0 IF v < 0 ELSE 1 + foo(v -1)
);
''', modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
r"definition dependency cycle between "
r"function 'default::bar\(v:.+int64\)' and "
r"function 'default::foo\(v:.+int64\)'"
):
self.run_ddl(schema, '''
ALTER FUNCTION foo(v: int64) USING (
0 IF v < 0 ELSE 1 + bar(v -1)
);
''') | , modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
r"definition dependency cycle between "
r"function 'default::bar\(v:.+int64\)' and "
r"function 'default::foo\(v:.+int64\)'"
):
self.run_ddl(schema, | test_schema_recursive_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_recursive_05(self):
schema = self.load_schema(r'''
type Foo {
property val := foo(1);
}
function foo(v: int64) -> int64 using (
1 + v
);
''', modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
r"definition dependency cycle between "
r"function 'default::foo\(v:.+int64\)' and "
r"property 'val' of object type 'default::Foo'"
):
self.run_ddl(schema, r'''
ALTER FUNCTION foo(v: int64) USING (
# This is very broken now
assert_exists(1 + (SELECT Foo LIMIT 1).val)
);
''') | , modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
r"definition dependency cycle between "
r"function 'default::foo\(v:.+int64\)' and "
r"property 'val' of object type 'default::Foo'"
):
self.run_ddl(schema, r | test_schema_recursive_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_recursive_06(self):
schema = self.load_schema(r'''
type Foo {
property val := 1;
}
function foo(v: int64) -> optional int64 using (
1 + (SELECT Foo LIMIT 1).val
);
''', modname='default')
with self.assertRaisesRegex(
errors.SchemaDefinitionError,
r"cannot alter property 'val' of object type 'default::Foo' "
r"because this affects body expression of "
r"function 'default::foo\(v:.+int64\)'"
):
self.run_ddl(schema, r'''
ALTER TYPE Foo {
# This is very broken now
ALTER PROPERTY val USING (foo(1));
};
''') | , modname='default')
with self.assertRaisesRegex(
errors.SchemaDefinitionError,
r"cannot alter property 'val' of object type 'default::Foo' "
r"because this affects body expression of "
r"function 'default::foo\(v:.+int64\)'"
):
self.run_ddl(schema, r | test_schema_recursive_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_recursive_07(self):
schema = self.load_schema(r'''
type Foo {
property val -> int64;
}
alias FooAlias0 := Foo {
comp := .val + (SELECT FooAlias1 LIMIT 1).comp
};
alias FooAlias1 := Foo {
comp := .val + 1
};
''', modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"definition dependency cycle between "
"alias 'default::FooAlias1' and alias 'default::FooAlias0'"
):
self.run_ddl(schema, r'''
ALTER ALIAS FooAlias1 USING (
Foo {
comp := .val + (SELECT FooAlias0 LIMIT 1).comp
}
);
''') | , modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"definition dependency cycle between "
"alias 'default::FooAlias1' and alias 'default::FooAlias0'"
):
self.run_ddl(schema, r | test_schema_recursive_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_recursive_08(self):
schema = self.load_schema(r'''
type Foo;
type Bar extending Foo;
''', modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"'default::Foo' is defined recursively"
):
self.run_ddl(schema, r'''
ALTER TYPE Foo EXTENDING Bar;
''') | , modname='default')
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"'default::Foo' is defined recursively"
):
self.run_ddl(schema, r | test_schema_recursive_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_computed_01(self):
# Issue #3499
"""
type Version {
multi link fields -> Field {
property position -> int32 {
default := 0;
}
}
multi link sections :=
(select .ordered_fields filter .type = 'section');
multi link ordered_fields :=
(select .fields order by @position);
}
type Field {
required property type -> str;
multi link versions := .<fields[is Version];
}
""" | type Version {
multi link fields -> Field {
property position -> int32 {
default := 0;
}
}
multi link sections :=
(select .ordered_fields filter .type = 'section');
multi link ordered_fields :=
(select .fields order by @position);
}
type Field {
required property type -> str;
multi link versions := .<fields[is Version];
} | test_schema_computed_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_computed_02(self):
# Issue #3499
"""
type Version {
multi link fields -> Field {
property position -> int32 {
default := 0;
}
}
multi link ordered_fields :=
(select .fields order by @position);
multi link sections :=
(select .ordered_fields filter .type = 'section');
}
type Field {
required property type -> str;
multi link versions := .<fields[is Version];
}
""" | type Version {
multi link fields -> Field {
property position -> int32 {
default := 0;
}
}
multi link ordered_fields :=
(select .fields order by @position);
multi link sections :=
(select .ordered_fields filter .type = 'section');
}
type Field {
required property type -> str;
multi link versions := .<fields[is Version];
} | test_schema_computed_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_computed_03(self):
# Issue #3499
"""
type Version {
multi link ordered_fields :=
(select .fields order by @position);
multi link sections :=
(select .ordered_fields filter .type = 'section');
multi link fields -> Field {
property position -> int32 {
default := 0;
}
}
}
type Field {
required property type -> str;
multi link versions := .<fields[is Version];
}
""" | type Version {
multi link ordered_fields :=
(select .fields order by @position);
multi link sections :=
(select .ordered_fields filter .type = 'section');
multi link fields -> Field {
property position -> int32 {
default := 0;
}
}
}
type Field {
required property type -> str;
multi link versions := .<fields[is Version];
} | test_schema_computed_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_computed_04(self):
"""
type User {
required property name -> str;
multi link likedPosts := .<author[is PostLike].post;
}
type Post {
required property content -> str;
}
abstract type ALike {
required link author -> User;
}
type PostLike extending ALike {
required link post -> Post;
}
""" | type User {
required property name -> str;
multi link likedPosts := .<author[is PostLike].post;
}
type Post {
required property content -> str;
}
abstract type ALike {
required link author -> User;
}
type PostLike extending ALike {
required link post -> Post;
} | test_schema_computed_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_computed_05(self):
"""
type User {
required property name -> str;
property val_e := {'alice', 'billie'} except .name;
property val_i := {'alice', 'billie'} intersect .name;
}
""" | type User {
required property name -> str;
property val_e := {'alice', 'billie'} except .name;
property val_i := {'alice', 'billie'} intersect .name;
} | test_schema_computed_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_alias_01(self):
"""
type User {
required property name -> str;
}
alias val_e := {'alice', 'billie'} except User.name;
alias val_i := {'alice', 'billie'} intersect User.name;
""" | type User {
required property name -> str;
}
alias val_e := {'alice', 'billie'} except User.name;
alias val_i := {'alice', 'billie'} intersect User.name; | test_schema_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_range_01(self):
"""
scalar type Age extending int64;
type Y {
property age_requirement -> range<Age>
}
""" | scalar type Age extending int64;
type Y {
property age_requirement -> range<Age>
} | test_schema_range_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_constraint_non_singleton_01(self):
"""
type ConstraintNonSingletonTest {
property has_bad_constraint -> str {
constraint expression on (
distinct __subject__ = __subject__
)
}
}
""" | type ConstraintNonSingletonTest {
property has_bad_constraint -> str {
constraint expression on (
distinct __subject__ = __subject__
)
}
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_02(self):
"""
type ConstraintNonSingletonTest {
property has_bad_constraint -> str {
constraint exclusive on (
distinct __subject__
)
}
}
""" | type ConstraintNonSingletonTest {
property has_bad_constraint -> str {
constraint exclusive on (
distinct __subject__
)
}
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_03(self):
"""
type ConstraintNonSingletonTest {
property has_bad_constraint -> str;
constraint exclusive on (distinct .has_bad_constraint);
}
""" | type ConstraintNonSingletonTest {
property has_bad_constraint -> str;
constraint exclusive on (distinct .has_bad_constraint);
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_04(self):
"""
type ConstraintNonSingletonTest {
property has_bad_constraint -> str;
constraint exclusive on (.has_bad_constraint) except (
distinct __subject__ = __subject__
);
}
""" | type ConstraintNonSingletonTest {
property has_bad_constraint -> str;
constraint exclusive on (.has_bad_constraint) except (
distinct __subject__ = __subject__
);
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_05(self):
"""
abstract constraint bad_constraint {
using (distinct __subject__ = __subject__);
}
""" | abstract constraint bad_constraint {
using (distinct __subject__ = __subject__);
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_06(self):
"""
abstract constraint bad_constraint {
using (count(__subject__) <= 2);
}
""" | abstract constraint bad_constraint {
using (count(__subject__) <= 2);
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_07(self):
"""
type Foo;
type ConstraintNonSingletonTest {
link has_bad_constraint -> Foo {
constraint expression on (
count(__subject__) <= 2
)
}
}
""" | type Foo;
type ConstraintNonSingletonTest {
link has_bad_constraint -> Foo {
constraint expression on (
count(__subject__) <= 2
)
}
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_08(self):
"""
type Foo;
type ConstraintNonSingletonTest {
multi link has_bad_constraint -> Foo {
constraint expression on (
count(__subject__) <= 2
)
}
}
""" | type Foo;
type ConstraintNonSingletonTest {
multi link has_bad_constraint -> Foo {
constraint expression on (
count(__subject__) <= 2
)
}
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_09(self):
"""
type Foo;
type ConstraintNonSingletonTest {
link has_bad_constraint -> Foo {
constraint expression on (
distinct __subject__ = __subject__
)
}
}
""" | type Foo;
type ConstraintNonSingletonTest {
link has_bad_constraint -> Foo {
constraint expression on (
distinct __subject__ = __subject__
)
}
} | test_schema_constraint_non_singleton_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_constraint_non_singleton_10(self):
"""
type Foo;
type ConstraintNonSingletonTest {
multi link has_bad_constraint -> Foo {
constraint expression on (
distinct __subject__ = __subject__
)
}
}
""" | type Foo;
type ConstraintNonSingletonTest {
multi link has_bad_constraint -> Foo {
constraint expression on (
distinct __subject__ = __subject__
)
}
} | test_schema_constraint_non_singleton_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_constraint_singleton_01a(self):
# `IN` allowed in singleton
"""
type X {
property a -> int64 {
constraint expression on (
__subject__ in {1}
);
}
};
""" | type X {
property a -> int64 {
constraint expression on (
__subject__ in {1}
);
}
}; | test_schema_constraint_singleton_01a | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_01b(self):
"""
type X {
multi property a -> int64 {
constraint expression on (
__subject__ in {1}
);
}
};
""" | type X {
multi property a -> int64 {
constraint expression on (
__subject__ in {1}
);
}
}; | test_schema_constraint_singleton_01b | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_02a(self):
# `NOT IN` allowed in singleton
"""
type X {
property a -> int64 {
constraint expression on (
__subject__ not in {1}
);
}
};
""" | type X {
property a -> int64 {
constraint expression on (
__subject__ not in {1}
);
}
}; | test_schema_constraint_singleton_02a | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_02b(self):
"""
type X {
multi property a -> int64 {
constraint expression on (
__subject__ not in {1}
);
}
};
""" | type X {
multi property a -> int64 {
constraint expression on (
__subject__ not in {1}
);
}
}; | test_schema_constraint_singleton_02b | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_03a(self):
# `EXISTS` allowed in singleton
"""
type X {
property a -> int64 {
constraint expression on (
exists(__subject__)
);
}
};
""" | type X {
property a -> int64 {
constraint expression on (
exists(__subject__)
);
}
}; | test_schema_constraint_singleton_03a | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_03b(self):
"""
type Foo;
type ConstraintNonSingletonTest {
multi link has_bad_constraint -> Foo {
constraint expression on (
exists(__subject__)
)
}
}
""" | type Foo;
type ConstraintNonSingletonTest {
multi link has_bad_constraint -> Foo {
constraint expression on (
exists(__subject__)
)
}
} | test_schema_constraint_singleton_03b | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_04a(self):
# `??` allowed in singleton
"""
type X {
property a -> int64 {
constraint expression on (
__subject__ ?? 1 = 0
);
}
};
""" | type X {
property a -> int64 {
constraint expression on (
__subject__ ?? 1 = 0
);
}
}; | test_schema_constraint_singleton_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_constraint_singleton_04b(self):
"""
type X {
multi property a -> int64 {
constraint expression on (
__subject__ ?? 1 = 0
);
}
};
""" | type X {
multi property a -> int64 {
constraint expression on (
__subject__ ?? 1 = 0
);
}
}; | test_schema_constraint_singleton_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_constraint_singleton_05a(self):
# `IF` allowed in singleton
"""
type X {
property a -> tuple<bool, int64> {
constraint expression on (
__subject__.1 < 0
if __subject__.0 else
__subject__.1 >= 0
);
}
};
""" | type X {
property a -> tuple<bool, int64> {
constraint expression on (
__subject__.1 < 0
if __subject__.0 else
__subject__.1 >= 0
);
}
}; | test_schema_constraint_singleton_05a | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_constraint_singleton_05b(self):
"""
type X {
multi property a -> tuple<bool, int64> {
constraint expression on (
__subject__.1 < 0
if __subject__.0 else
__subject__.1 >= 0
);
}
};
""" | type X {
multi property a -> tuple<bool, int64> {
constraint expression on (
__subject__.1 < 0
if __subject__.0 else
__subject__.1 >= 0
);
}
}; | test_schema_constraint_singleton_05b | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_index_non_singleton_01(self):
"""
type IndexNonSingletonTest {
property has_bad_index -> str;
index on (distinct .has_bad_index)
}
""" | type IndexNonSingletonTest {
property has_bad_index -> str;
index on (distinct .has_bad_index)
} | test_schema_index_non_singleton_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_index_non_singleton_02(self):
"""
type IndexNonSingletonTest {
property has_bad_index -> str;
index on (count(.has_bad_index))
}
""" | type IndexNonSingletonTest {
property has_bad_index -> str;
index on (count(.has_bad_index))
} | test_schema_index_non_singleton_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_incompatible_union_01(self):
"""
type X {
property a -> int64;
}
type Y {
property a -> str;
}
type Z {
link xy -> X | Y;
}
""" | type X {
property a -> int64;
}
type Y {
property a -> str;
}
type Z {
link xy -> X | Y;
} | test_schema_incompatible_union_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_incompatible_union_02(self):
"""
type A;
type X {
property a -> int64;
}
type Y {
link a -> A;
}
type Z {
link xy -> X | Y;
}
""" | type A;
type X {
property a -> int64;
}
type Y {
link a -> A;
}
type Z {
link xy -> X | Y;
} | test_schema_incompatible_union_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_incompatible_union_03(self):
"""
type A;
type X {
link a -> A {
b -> int64
};
}
type Y {
link a -> A {
b -> str
}
}
type Z {
link xy -> X | Y;
}
""" | type A;
type X {
link a -> A {
b -> int64
};
}
type Y {
link a -> A {
b -> str
}
}
type Z {
link xy -> X | Y;
} | test_schema_incompatible_union_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_query_parameter_01(self):
"""
type Foo { foo := <int64>$0 }
""" | type Foo { foo := <int64>$0 } | test_schema_query_parameter_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_query_parameter_02(self):
"""
global foo := <int64>$0
""" | global foo := <int64>$0 | test_schema_query_parameter_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_unknown_typename_01(self):
"""
type A;
type B {
link a -> A;
property x := <C>.a;
}
""" | type A;
type B {
link a -> A;
property x := <C>.a;
} | test_schema_unknown_typename_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_unknown_typename_02(self):
"""
type A;
type B {
link a -> A;
property x := .a is C;
}
""" | type A;
type B {
link a -> A;
property x := .a is C;
} | test_schema_unknown_typename_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_unknown_typename_03(self):
"""
type A;
type B {
link a -> A;
property x := .a is null;
}
""" | type A;
type B {
link a -> A;
property x := .a is null;
} | test_schema_unknown_typename_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_unknown_typename_04(self):
"""
type A;
type B {
link a -> A;
property x := .a is NONE;
}
""" | type A;
type B {
link a -> A;
property x := .a is NONE;
} | test_schema_unknown_typename_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_unknown_typename_05(self):
"""
type B {
property x := (introspect C).name;
}
""" | type B {
property x := (introspect C).name;
} | test_schema_unknown_typename_05 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def _assert_migration_consistency(
self,
schema_text: str,
explicit_modules: bool = False,
) -> s_schema.Schema:
if explicit_modules:
migration_text = f'''
START MIGRATION TO {{
{schema_text}
}};
POPULATE MIGRATION;
COMMIT MIGRATION;
'''
else:
migration_text = f'''
START MIGRATION TO {{
module default {{
{schema_text}
}}
}};
POPULATE MIGRATION;
COMMIT MIGRATION;
'''
baseline_schema = self.run_ddl(self.schema, migration_text)
migration = baseline_schema.get_last_migration()
assert migration is not None
ddl_text = migration.get_script(baseline_schema)
try:
test_schema = self.run_ddl(self.schema, ddl_text)
except errors.EdgeDBError as e:
self.fail(markup.dumps(e))
diff = s_ddl.delta_schemas(test_schema, baseline_schema)
if list(diff.get_subcommands()):
self.fail(
f'unexpected difference in schema produced by\n'
f'COMMIT MIGRATION and DDL obtained from GET MIGRATION:\n'
f'{markup.dumps(diff)}\n'
f'DDL text was:\n{ddl_text}'
)
# Now, dump the final schema into DDL and SDL and see if
# reapplying those representations produces in the same
# schema. This tests the codepath used by DESCRIBE command as
# well and validates that DESCRIBE is producing valid grammar.
ddl_text = s_ddl.ddl_text_from_schema(baseline_schema)
sdl_text = s_ddl.sdl_text_from_schema(baseline_schema)
try:
ddl_schema = self.run_ddl(self.std_schema, ddl_text)
sdl_schema = self.run_ddl(
self.std_schema,
f'''
START MIGRATION TO {{ {sdl_text} }};
POPULATE MIGRATION;
COMMIT MIGRATION;
''',
)
except errors.EdgeDBError as e:
self.fail(markup.dumps(e))
diff = s_ddl.delta_schemas(ddl_schema, baseline_schema)
if list(diff.get_subcommands()):
self.fail(
f'unexpected difference in schema produced by\n'
f'COMMIT MIGRATION and DDL obtained from dumping the schema:\n'
f'{markup.dumps(diff)}\n'
f'DDL text was:\n{ddl_text}'
)
diff = s_ddl.delta_schemas(sdl_schema, baseline_schema)
if list(diff.get_subcommands()):
self.fail(
f'unexpected difference in schema produced by\n'
f'COMMIT MIGRATION and SDL obtained from dumping the schema:\n'
f'{markup.dumps(diff)}\n'
f'SDL text was:\n{sdl_text}'
)
return baseline_schema | else:
migration_text = f | _assert_migration_consistency | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_01(self):
self._assert_migration_equivalence([r"""
type Base;
""", r"""
type Base {
property name -> str;
}
""", r"""
type Base {
property name -> str;
}
type Derived extending Base {
overloaded required property name -> str;
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_02(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
type Derived extending Base {
overloaded required property foo -> str;
}
""", r"""
type Base {
# rename 'foo'
property foo2 -> str;
}
type Derived extending Base {
overloaded required property foo2 -> str;
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_03(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
type Derived extending Base {
overloaded required property foo -> str;
}
""", r"""
type Base;
# drop 'foo'
type Derived extending Base {
# completely different property
property foo2 -> str;
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_04(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
type Derived extending Base;
type Further extending Derived {
overloaded required property foo -> str;
}
""", r"""
type Base;
# drop 'foo'
type Derived extending Base;
type Further extending Derived {
# completely different property
property foo2 -> str;
};
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_05(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
type Derived extending Base {
overloaded required property foo -> str;
}
""", r"""
type Base;
# drop foo
type Derived extending Base {
# no longer inherited property 'foo'
property foo -> str;
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_06(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> int64;
}
type Derived extending Base {
overloaded required property foo -> int64;
}
""", r"""
type Base {
# change property type
property foo -> int32;
}
type Derived extending Base {
overloaded required property foo -> int32;
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_07(self):
self._assert_migration_equivalence([r"""
type Child;
type Base {
link bar -> Child;
}
""", r"""
type Child;
type Base {
required link bar -> Child {
# add a constraint
constraint exclusive;
}
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_08(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
""", r"""
type Base {
required property foo -> str {
# add a constraint
constraint max_len_value(10);
}
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_09(self):
self._assert_migration_equivalence([r"""
scalar type constraint_length extending str {
constraint max_len_value(10);
}
""", r"""
scalar type constraint_length extending str {
constraint max_len_value(10);
# add a constraint
constraint min_len_value(5);
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_10(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
""", r"""
type Child;
type Base {
# change property to link with same name
link foo -> Child;
}
"""]) | , r | test_schema_migrations_equivalence_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_migrations_equivalence_11(self):
self._assert_migration_equivalence([r"""
type Base {
property foo -> str;
}
""", r"""
type Child;
type Base {
# change property to link with same name
link foo -> Child {
# add a constraint
constraint exclusive;
}
}
"""]) | , r | test_schema_migrations_equivalence_11 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_12(self):
self._assert_migration_equivalence([r"""
type Child;
type Base {
property foo -> str {
constraint exclusive;
}
link bar -> Child {
constraint exclusive;
}
}
""", r"""
type Child;
type Base {
# drop constraints
property foo -> str;
link bar -> Child;
}
"""]) | , r | test_schema_migrations_equivalence_12 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_13(self):
self._assert_migration_equivalence([r"""
type Child;
type Base {
link bar -> Child;
}
type Derived extending Base {
overloaded required link bar -> Child;
}
""", r"""
type Child;
type Base;
# drop 'bar'
type Derived extending Base {
# no longer inherit link 'bar'
link bar -> Child;
}
"""]) | , r | test_schema_migrations_equivalence_13 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_14(self):
self._assert_migration_equivalence([r"""
type Base;
type Derived extending Base {
property foo -> str;
}
""", r"""
type Base {
# move the property earlier in the inheritance
property foo -> str;
}
type Derived extending Base {
overloaded required property foo -> str;
}
"""]) | , r | test_schema_migrations_equivalence_14 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_15(self):
self._assert_migration_equivalence([r"""
type Child;
type Base;
type Derived extending Base {
link bar -> Child;
}
""", r"""
type Child;
type Base {
# move the link earlier in the inheritance
link bar -> Child;
}
type Derived extending Base;
"""]) | , r | test_schema_migrations_equivalence_15 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_16(self):
self._assert_migration_equivalence([r"""
type Child;
type Base;
type Derived extending Base {
link bar -> Child;
}
""", r"""
type Child;
type Base {
# move the link earlier in the inheritance
link bar -> Child;
}
type Derived extending Base;
""", r"""
type Child;
type Base {
link bar -> Child;
}
type Derived extending Base {
# also make the link 'required'
overloaded required link bar -> Child;
}
"""]) | , r | test_schema_migrations_equivalence_16 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_migrations_equivalence_17(self):
self._assert_migration_equivalence([r"""
type Base {
property name := 'computable'
}
""", r"""
type Base {
# change a property from a computable to regular
property name -> str
}
"""]) | , r | test_schema_migrations_equivalence_17 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.