How to use describe_rule method in localstack

Best Python code snippet using localstack_python

quiz_2.py

Source:quiz_2.py Github

copy

Full Screen

...6 "rule_nb" is supposed to be an integer between 0 and 15.7 '''8 values = [int(d) for d in f'{rule_nb:04b}']9 return {(p // 2, p % 2): values[p] for p in range(4)}10def describe_rule(rule_nb):11 '''12 "rule_nb" is supposed to be an integer between 0 and 15.13 >>> describe_rule(4)14 The rule encoded by 4 is: {(0, 0): 0, (0, 1): 1, (1, 0): 0, (1, 1): 0}15 <BLANKLINE>16 After 0 followed by 0, we draw 017 After 0 followed by 1, we draw 118 After 1 followed by 0, we draw 019 After 1 followed by 1, we draw 020 >>> describe_rule(0)21 The rule encoded by 0 is: {(0, 0): 0, (0, 1): 0, (1, 0): 0, (1, 1): 0}22 <BLANKLINE>23 After 0 followed by 0, we draw 024 After 0 followed by 1, we draw 025 After 1 followed by 0, we draw 026 After 1 followed by 1, we draw 027 >>> describe_rule(5)28 The rule encoded by 5 is: {(0, 0): 0, (0, 1): 1, (1, 0): 0, (1, 1): 1}29 <BLANKLINE>30 After 0 followed by 0, we draw 031 After 0 followed by 1, we draw 132 After 1 followed by 0, we draw 033 After 1 followed by 1, we draw 134 >>> describe_rule(7)35 The rule encoded by 7 is: {(0, 0): 0, (0, 1): 1, (1, 0): 1, (1, 1): 1}36 <BLANKLINE>37 After 0 followed by 0, we draw 038 After 0 followed by 1, we draw 139 After 1 followed by 0, we draw 140 After 1 followed by 1, we draw 141 >>> describe_rule(10)42 The rule encoded by 10 is: {(0, 0): 1, (0, 1): 0, (1, 0): 1, (1, 1): 0}43 <BLANKLINE>44 After 0 followed by 0, we draw 145 After 0 followed by 1, we draw 046 After 1 followed by 0, we draw 147 After 1 followed by 1, we draw 048 >>> describe_rule(15)49 The rule encoded by 15 is: {(0, 0): 1, (0, 1): 1, (1, 0): 1, (1, 1): 1}50 <BLANKLINE>51 After 0 followed by 0, we draw 152 After 0 followed by 1, we draw 153 After 1 followed by 0, we draw 154 After 1 followed by 1, we draw 155 '''56 rule = rule_encoded_by(rule_nb)57 print('The rule encoded by', rule_nb, 'is: ', rule)58 print()59 for i in rule.items():60 print(f'After {i[0][0]} followed by {i[0][1]}, we draw {i[1]}')61def draw_line(rule_nb, first, second, length):62 '''...

Full Screen

Full Screen

constraints.py

Source:constraints.py Github

copy

Full Screen

...55 Serialize a description of this constraint. Sub-classes should 56 override `describe_rule` rather than this method.57 '''58 return ' '.join((59 'CONSTRAINT', self.name, self.describe_rule()60 ))61 def describe_rule(self):62 '''Return a serialized description of this consraint rule.'''63 raise NotImplementedError()64 def serialize(self, values=None, name_policy=None):65 '''Serialize a reference to this constraint.'''66 return self.name67class CheckConstraint(Constraint):68 '''A generic `CHECK` constraint on a column or table.'''69 def __init__(self, error_message, condition_policy, name=None):70 '''71 Create a new check constraint. This should generally be done while 72 defining the attribute map of a model within it's decorator.73 ::condition_policy A callable that will at some point be passed the74 host of this constraint to yeild a flag-like `Node`.75 ::name The name of this constraint. If none is supplied, one will be76 automatically generated.77 '''78 super().__init__('check', error_message)79 self.condition_policy = condition_policy80 self.name = name81 def describe_rule(self):82 '''Serialize the policy-specified check for this constraint.'''83 from .tables import Table84 # Resolve the policy and assert it's result is valid.85 if isinstance(self.host, Table):86 condition = nodeify(self.condition_policy(self.host.model_cls))87 else:88 condition = nodeify(self.condition_policy(self.host))89 if not issubclass(type(condition), MFlag):90 raise InvalidSchema((91 'Check constraint %s has non flag-like condition'92 )%self.name)93 94 # Create and return the serialization. This is vulnerable to95 # injection, but only from the caller itself.96 values = list()97 sql = condition.serialize(values)98 if not isinstance(condition, Unique):99 sql = ' '.join(('CHECK (', sql, ')'))100 return sql%(*("'%s'"%v for v in values),)101class PrimaryKeyConstraint(Constraint):102 '''A primary key constraint on a column.'''103 def __init__(self):104 super().__init__('pk')105 def describe_rule(self):106 return 'PRIMARY KEY'107class ForeignKeyConstraint(Constraint):108 '''A foreign key constraint on a column.'''109 def __init__(self, target):110 super().__init__('fk')111 self.target = target112 def describe_rule(self):113 return 'REFERENCES %s (%s)'%(114 self.target.table.name,115 self.target.name116 )117class NotNullConstraint(Constraint):118 '''A `NOT NULL` constraint on a column.'''119 def __init__(self, error_message='Required'):120 super().__init__('existance', error_message)121 def precheck_violation(self, model, value):122 return value is None123 def validator_info(self):124 return None125 126 def describe_rule(self):127 return ' '.join((128 'CHECK (', self.host.serialize(), 'IS NOT NULL)'129 ))130class UniquenessConstraint(Constraint):131 '''A `UNIQUE` constraint on a column.'''132 def __init__(self, error_message='Must be unique'):133 super().__init__('uniqueness', error_message)134 135 def describe_rule(self):136 return 'UNIQUE'137class RangeConstraint(Constraint):138 '''A range constraint.'''139 def __init__(self, error_message, min_value=None, max_value=None):140 super().__init__('range', error_message)141 self.max_value, self.min_value = max_value, min_value142 def precheck_violation(self, model, value):143 return not ((self.max_value is None or value < self.max_value) and \144 (self.min_value is None or value >= self.min_value))145 def describe_rule(self):146 values = list()147 rule = True148 if self.max_value is not None:149 rule &= (self.host < self.max_value)150 if self.min_value is not None:151 rule &= (self.host >= self.min_value)152 sql = rule.serialize(values)153 return ' '.join((154 'CHECK (', sql%tuple(values), ')'155 ))156 def validator_info(self):157 return {158 'max': self.max_value,159 'min': self.min_value160 }161class RegexConstraint(Constraint):162 '''A regular expression constraint.'''163 def __init__(self, error_message, regex, ignore_case=False, invert=False):164 super().__init__('format', error_message)165 self.regex = regex166 self.ignore_case, self.invert = ignore_case, invert167 def precheck_violation(self, model, value):168 return (value is not None) and (bool(re.match(self.regex, value)) == self.invert)169 170 def describe_rule(self):171 opr = '~'172 if self.ignore_case:173 opr = ''.join((opr, '*'))174 if self.invert:175 opr = ''.join(('!', opr))176 177 return ' '.join((178 'CHECK (', 179 self.host.name, opr, 180 ''.join(("'", self.regex.replace("'", "\'"), "'")),181 ')'182 ))183 184 def validator_info(self):...

Full Screen

Full Screen

quiz2_test.py

Source:quiz2_test.py Github

copy

Full Screen

...3# @Time : 2019-03-03 22:574# @Author : ZD Liu5from quiz_2 import *6def quiz2_test():7 describe_rule(3)8 describe_rule(4)9 describe_rule(11)10 describe_rule(14)11 describe_rule('')12 describe_rule(0)13 describe_rule('a')14 print(draw_line(3, 0, 0, 1))15 print(draw_line(3, 0, 0, 1))16 print(draw_line(3, 0, 0, 1))17 print(draw_line(3, 1, 0, 5))18 print(draw_line(4, 1, 0, 9))19 print(draw_line(4, 0, 1, 13))20 print(draw_line(11,1,0,16))21 print(draw_line(11, 1, 1, 19))22 print(draw_line(14, 0, 0,21))23 print(draw_line(15, 0,0,22))24 print(draw_line(4, 0, 1, 13))25 print(999)26 print(draw_line(-4, 0, 1, 13))27 print(draw_line(4, -1, 1, 13))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful