def step_impl(context: Context, var: str, type_label: str, key_type: str, key_value: str): context.put( var, next((owner for owner in context.tx().concepts().get_attribute_type( key_type).as_string().as_remote(context.tx()).get( key_value).as_remote(context.tx()).get_owners() if owner.get_type().get_label() == Label.of(type_label)), None))
def step_impl(context: Context, root_label: RootLabel, type_label: str): role_labels = [parse_label(s) for s in parse_list(context.table)] actuals = [ t.get_label() for t in context.get_thing_type( root_label, type_label).as_remote(context.tx()).get_plays() ] for role_label in role_labels: assert_that(role_label, not_(is_in(actuals)))
def step_impl(context: Context, root_label: RootLabel, type_label: str): attribute_labels = [parse_label(s) for s in parse_list(context.table)] actuals = [ t.get_label() for t in context.get_thing_type( root_label, type_label).as_remote(context.tx()).get_owns() ] for attribute_label in attribute_labels: assert_that(actuals, not_(has_item(attribute_label)))
def step_impl(context: Context, root_label: RootLabel, type_label: str): sub_labels = [parse_label(s) for s in parse_list(context.table)] actuals = [ t.get_label() for t in context.get_thing_type( root_label, type_label).as_remote(context.tx()).get_subtypes() ] for sub_label in sub_labels: assert_that(actuals, has_item(sub_label))
def get_actual_related_role_players_scoped_labels(context: Context, relation_label: str, role_label: str): return [ r.get_label() for r in context.tx().concepts().get_relation_type( relation_label).as_remote(context.tx()).get_relates( role_label).as_remote(context.tx()).get_players() ]
def step_impl(context: Context, relation_label: str, role_label: str, super_role: str): try: context.tx().concepts().get_relation_type(relation_label).as_remote( context.tx()).set_relates(role_label, overridden_label=super_role) assert False except GraknClientException: pass
def before_scenario(context: Context, scenario): for tag in IGNORE_TAGS: if tag in scenario.effective_tags: scenario.skip("tagged with @" + tag) return environment_base.before_scenario(context, scenario) context.session_options = TypeDBOptions.core().set_infer(True) context.transaction_options = TypeDBOptions.core().set_infer(True)
def step_impl(context: Context, type_label: str): owner_labels = parse_list(context.table) attribute_type = context.tx().concepts().get_attribute_type(type_label) actuals = list( map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(only_key=False))) for owner_label in owner_labels: assert_that(actuals, not_(has_item(owner_label)))
def step_impl(context: Context, root_label: RootLabel, type_label: str, is_abstract): is_abstract = parse_bool(is_abstract) thing_type = context.get_thing_type(root_label, type_label) if is_abstract: thing_type.as_remote(context.tx()).set_abstract() else: thing_type.as_remote(context.tx()).unset_abstract()
def step_impl(context: Context, root_label: RootLabel, type_label: str, att_type_label: str, overridden_label: str): attribute_type = context.tx().concepts().get_attribute_type(att_type_label) overridden_type = context.tx().concepts().get_attribute_type( overridden_label) context.get_thing_type(root_label, type_label).as_remote(context.tx()).set_owns( attribute_type, overridden_type)
def step_impl(context: Context): sub_labels = [parse_label(s) for s in parse_list(context.table)] actuals = [ t.get_label() for t in context.tx().concepts().get_root_thing_type().as_remote( context.tx()).get_subtypes() ] for sub_label in sub_labels: assert_that(sub_label, not_(is_in(actuals)))
def step_impl(context: Context, root_label: RootLabel, type_label: str, att_type_label: str): attribute_type = context.tx().concepts().get_attribute_type(att_type_label) try: context.get_thing_type(root_label, type_label).as_remote( context.tx()).set_owns(attribute_type) assert False except GraknClientException: pass
def step_impl(context: Context, root_label: RootLabel, type_label: str): attribute_labels = parse_list(context.table) actuals = list( map( lambda t: t.get_label(), context.get_thing_type(root_label, type_label).as_remote( context.tx()).get_owns())) for attribute_label in attribute_labels: assert_that(attribute_label, not_(is_in(actuals)))
def step_impl(context: Context, root_label: RootLabel, type_label: str): role_labels = parse_list(context.table) actuals = list( map( lambda t: t.get_scoped_label(), context.get_thing_type(root_label, type_label).as_remote( context.tx()).get_plays())) for role_label in role_labels: assert_that(role_label, not_(is_in(actuals)))
def step_impl(context: Context, root_label: RootLabel, type_label: str): sub_labels = parse_list(context.table) actuals = list( map( lambda t: t.get_label(), context.get_thing_type(root_label, type_label).as_remote( context.tx()).get_subtypes())) for sub_label in sub_labels: assert_that(sub_label, is_in(actuals))
def step_impl(context: Context): super_labels = parse_list(context.table) actuals = list( map( lambda t: t.get_label(), context.tx().concepts().get_root_thing_type().as_remote( context.tx()).get_subtypes())) for super_label in super_labels: assert_that(super_label, not_(is_in(actuals)))
def _get_thing_type_impl(context: Context, root_label: RootLabel, type_label: str): if root_label == RootLabel.ENTITY: return context.tx().concepts().get_entity_type(type_label) elif root_label == RootLabel.ATTRIBUTE: return context.tx().concepts().get_attribute_type(type_label) elif root_label == RootLabel.RELATION: return context.tx().concepts().get_relation_type(type_label) else: raise ValueError("Unrecognised value")
def step_impl(context: Context, var: str): players = parse_dict(context.table) relation = context.get(var).as_relation() players_by_role_type = relation.as_remote( context.tx()).get_players_by_role_type() for (role_label, var2) in players.items(): assert_that( players_by_role_type.get(relation.get_type().as_remote( context.tx()).get_relates(role_label)), not_(has_item(context.get(parse_var(var2)))))
def step_impl(context: Context, relation_label: str, role_label: str, super_scope: str, super_label: str): supertype = context.tx().concepts().get_relation_type( super_scope).as_remote(context.tx()).get_relates(super_label) assert_that( supertype, is_(context.tx().concepts().get_relation_type( relation_label).as_remote( context.tx()).get_relates(role_label).as_remote( context.tx()).get_supertype()))
def adding_player_throws_exception(context: Context, var1: str, role_label: str, var2: str): relation = context.get(var1).as_relation() try: relation.as_remote(context.tx()).add_player( relation.get_type().as_remote( context.tx()).get_relates(role_label), context.get(var2)) assert False except TypeDBClientException: pass
def step_impl(context: Context, root_label: RootLabel, type_label: str, scope: str, role_label: str): role_type = context.tx().concepts().get_relation_type(scope).as_remote( context.tx()).get_relates(role_label) try: context.get_thing_type(root_label, type_label).as_remote( context.tx()).unset_plays(role_type) assert False except GraknClientException: pass
def step_impl(context: Context, root_label: RootLabel, type_label: str, role_label: Label): role_type = context.tx().concepts().get_relation_type( role_label.scope()).as_remote(context.tx()).get_relates( role_label.name()) try: context.get_thing_type(root_label, type_label).as_remote( context.tx()).set_plays(role_type) assert False except TypeDBClientException: pass
def matches(self, context: Context, concept: ConceptSubtype): if not concept.is_thing(): return False keys = [key for key in concept.as_remote(context.tx()).get_has(only_key=True)] for key in keys: if key.as_remote(context.tx()).get_type().get_label() == self.type_label: return self.check(key) return False
def step_impl(context: Context, root_label: RootLabel, type_label: str, att_type_label: str, overridden_label: str): attribute_type = context.tx().concepts().get_attribute_type(att_type_label) overridden_type = context.tx().concepts().get_attribute_type( overridden_label) try: context.get_thing_type(root_label, type_label).as_remote( context.tx()).set_owns(attribute_type, overridden_type, is_key=True) assert False except TypeDBClientException: pass
def for_each_session_open_transaction_of_type(context: Context, transaction_types: List[TransactionType]): for session in context.sessions: transactions = [] for transaction_type in transaction_types: transaction = session.transaction(transaction_type, context.transaction_options) transactions.append(transaction) context.sessions_to_transactions[session] = transactions
def before_all(context: Context): environment_base.before_all(context) root_ca_path = os.environ["ROOT_CA"] credential = TypeDBCredential("admin", "password", root_ca_path) context.client = TypeDB.cluster_client( addresses=["127.0.0.1:" + context.config.userdata["port"]], credential=credential)
def step_impl(context: Context): types = list(map(parse_transaction_type, parse_list(context.table))) assert_that(len(types), is_(less_than_or_equal_to(context.THREAD_POOL_SIZE))) with ThreadPoolExecutor(max_workers=context.THREAD_POOL_SIZE) as executor: for session in context.sessions: context.sessions_to_transactions_parallel[session] = [] for type_ in types: context.sessions_to_transactions_parallel[session].append(executor.submit(partial(session.transaction, type_)))
def step_impl(context: Context, type_label: str, value_type: str): sub_labels = parse_list(context.table) attribute_type = attribute_type_as_value_type(context, type_label, parse_value_type(value_type)) actuals = list( map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_subtypes())) for sub_label in sub_labels: assert_that(sub_label, is_in(actuals))
def step_impl(context: Context, var: str, type_label: str, key_type: str, key_value: str): key = context.tx().concepts().get_attribute_type( key_type).as_string().as_remote(context.tx()).put(key_value) relation = context.tx().concepts().get_relation_type(type_label).as_remote( context.tx()).create() relation.as_remote(context.tx()).set_has(key) context.put(var, relation)
def matches(self, context: Context, concept: ConceptSubtype): if not concept.is_attribute(): return False attribute = concept if self.type_label != attribute.as_remote(context.tx()).get_type().get_label(): return False return self.check(attribute)