Best Python code snippet using tavern
table_view.py
Source:table_view.py
...46 return data47 @classmethod48 def get_default_table_view(cls, table: Table):49 return cls(table, AutoMarshaller())50 def _generate_items(self, paginator: Paginator):51 for item in paginator:52 yield self._postprocess_read_item(item)53 def _map_exp_values(self, values):54 return {55 k: self.marshaller.pack_attribute(v) for k, v in values.items()56 }57 def query(self, exp: Expression, index: str = None):58 kwargs = {59 "key_condition_exp": exp.expression,60 "attr_names": exp.attr_name_args,61 "attr_values": self._map_exp_values(exp.attr_value_args)62 }63 if index is not None:64 kwargs["index"] = index65 paginator = QueryPaginator(66 self.table,67 kwargs,68 self.page_length,69 self.preload70 )71 return self._generate_items(paginator)72 def scan(self, filter_exp: Expression = None):73 kwargs = {}74 if filter_exp is not None:75 kwargs = {76 "filter_exp": filter_exp.expression,77 "attr_names": filter_exp.attr_name_args,78 "attr_values": self._map_exp_values(filter_exp.attr_value_args)79 }80 paginator = ScanPaginator(81 self.table,82 kwargs,83 self.page_length,84 self.preload85 )86 return self._generate_items(paginator)87 def _get_primary_key_selector(self, value, sort=False):88 primary_key = self.table.definition.primary_key89 key_name = primary_key.partition_key90 if sort:91 assert primary_key.is_sortable92 key_name = primary_key.sort_key93 key_type = self.table.definition.attributes[key_name]94 return {key_name: self.marshaller.pack_attribute(value, key_type)}95 def _build_key_args(self, partition_key, sort_key):96 key_args = self._get_primary_key_selector(partition_key)97 if sort_key is not None:98 key_args.update(self._get_primary_key_selector(sort_key, True))99 return key_args100 def get_item(self, partition_key, sort_key=None):...
Grid.py
Source:Grid.py
...12 self.item_number: int = item_number13 self.cells: List[List[Cell]] = []14 self._generate_grid()15 self._generate_rocks()16 self._generate_items()17 def get_random_cell(self) -> Cell:18 return self.cells[randint(0, self.height - 1)][randint(0, self.width - 1)]19 def _generate_items(self):20 item_count = 021 while self.item_number != item_count:22 cell = self.get_random_cell()23 if not cell.player and not cell.field_type == FieldTypes.ROCK:24 cell.item = 125 item_count = item_count + 126 def _generate_grid(self):27 for y in range(self.height):28 self.cells.append([])29 for x in range(self.width):30 self.cells[y].append(Cell())31 def _generate_rocks(self, pct=0.3):32 for i in range(int(self.height * self.width * pct) // 2):33 x = randint(1, self.width - 1)...
post.py
Source:post.py
...11 return {'title': self.title, 'context': self.context}12 @staticmethod13 def _word():14 return ''.join(sample(ascii_lowercase, randint(1, len(ascii_lowercase))))15 def _generate_items(self, func):16 items_count = randint(self.min_items, self.max_items)17 return ' '.join(func() for _ in range(items_count))18 def _sentence(self):19 return f'{(self._generate_items(self._word)).capitalize()}.'20 def _text(self):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!