Best Python code snippet using avocado_python
test_sort_json_policy_dict.py
Source: test_sort_json_policy_dict.py
1# (c) 2022 Red Hat Inc.2#3# This file is part of Ansible4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)5from __future__ import (absolute_import, division, print_function)6__metaclass__ = type7from ansible_collections.amazon.aws.plugins.module_utils.policy import sort_json_policy_dict8def test_nothing_to_sort():9 simple_dict = {'key1': 'a'}10 nested_dict = {'key1': {'key2': 'a'}}11 very_nested_dict = {'key1': {'key2': {'key3': 'a'}}}12 assert sort_json_policy_dict(simple_dict) == simple_dict13 assert sort_json_policy_dict(nested_dict) == nested_dict14 assert sort_json_policy_dict(very_nested_dict) == very_nested_dict15def test_basic_sort():16 simple_dict = {'key1': [1, 2, 3, 4], 'key2': [9, 8, 7, 6]}17 sorted_dict = {'key1': [1, 2, 3, 4], 'key2': [6, 7, 8, 9]}18 assert sort_json_policy_dict(simple_dict) == sorted_dict19 assert sort_json_policy_dict(sorted_dict) == sorted_dict20 simple_dict = {'key1': ["a", "b", "c", "d"], 'key2': ["z", "y", "x", "w"]}21 sorted_dict = {'key1': ["a", "b", "c", "d"], 'key2': ["w", "x", "y", "z"]}22 assert sort_json_policy_dict(sorted_dict) == sorted_dict23def test_nested_list_sort():24 nested_dict = {'key1': {'key2': [9, 8, 7, 6]}}25 sorted_dict = {'key1': {'key2': [6, 7, 8, 9]}}26 assert sort_json_policy_dict(nested_dict) == sorted_dict27 assert sort_json_policy_dict(sorted_dict) == sorted_dict28 nested_dict = {'key1': {'key2': ["z", "y", "x", "w"]}}29 sorted_dict = {'key1': {'key2': ["w", "x", "y", "z"]}}30 assert sort_json_policy_dict(nested_dict) == sorted_dict31 assert sort_json_policy_dict(sorted_dict) == sorted_dict32def test_nested_dict_list_sort():33 nested_dict = {'key1': {'key2': {'key3': [9, 8, 7, 6]}}}34 sorted_dict = {'key1': {'key2': {'key3': [6, 7, 8, 9]}}}35 assert sort_json_policy_dict(nested_dict) == sorted_dict36 assert sort_json_policy_dict(sorted_dict) == sorted_dict37 nested_dict = {'key1': {'key2': {'key3': ["z", "y", "x", "w"]}}}38 sorted_dict = {'key1': {'key2': {'key3': ["w", "x", "y", "z"]}}}39 assert sort_json_policy_dict(nested_dict) == sorted_dict40 assert sort_json_policy_dict(sorted_dict) == sorted_dict41def test_list_of_dict_sort():42 nested_dict = {'key1': [{'key2': [4, 3, 2, 1]}, {'key3': [9, 8, 7, 6]}]}43 sorted_dict = {'key1': [{'key2': [1, 2, 3, 4]}, {'key3': [6, 7, 8, 9]}]}44 assert sort_json_policy_dict(nested_dict) == sorted_dict45 assert sort_json_policy_dict(sorted_dict) == sorted_dict46def test_list_of_list_sort():47 nested_dict = {'key1': [[4, 3, 2, 1], [9, 8, 7, 6]]}48 sorted_dict = {'key1': [[1, 2, 3, 4], [6, 7, 8, 9]]}49 assert sort_json_policy_dict(nested_dict) == sorted_dict...
test_sorted_dict.py
Source: test_sorted_dict.py
1import unittest2from contradict.sorted_dict import SortedDict3class TestSortedDict(unittest.TestCase):4 def test_get_set(self):5 sorted_dict = SortedDict()6 sorted_dict.set('A', 12)7 sorted_dict.set('B', 13)8 sorted_dict.set('C', 15)9 self.assertEqual(sorted_dict.get('B'), 13)10 def test_items(self):11 sorted_dict = SortedDict()12 sorted_dict.set('A', 12)13 sorted_dict.set('B', 13)14 sorted_dict.set('C', 15)15 res = []16 for k, v in sorted_dict.items():17 res.append((k, v))18 self.assertEqual(res[0], ('A', 12))19 def test_keys(self):20 sorted_dict = SortedDict()21 sorted_dict.set('A', 12)22 sorted_dict.set('B', 13)23 sorted_dict.set('C', 15)24 res = []25 for k in sorted_dict.keys():26 res.append(k)27 self.assertEqual(res[0], 'A')28 def test_values(self):29 sorted_dict = SortedDict()30 sorted_dict.set('A', 12)31 sorted_dict.set('B', 13)32 sorted_dict.set('C', 15)33 res = []34 for v in sorted_dict.values():35 res.append(v)36 self.assertEqual(res[0], 12)37 def test_items_reverse(self):38 sorted_dict = SortedDict()39 sorted_dict.set('A', 12)40 sorted_dict.set('B', 13)41 sorted_dict.set('C', 15)42 res = []43 for k, v in sorted_dict.items(reverse=True):44 res.append((k, v))45 self.assertEqual(res[0], ('C', 15))46 def test_keys_reverse(self):47 sorted_dict = SortedDict()48 sorted_dict.set('A', 12)49 sorted_dict.set('B', 13)50 sorted_dict.set('C', 15)51 res = []52 for k in sorted_dict.keys(reverse=True):53 res.append(k)54 self.assertEqual(res[0], 'C')55 def test_values_reverse(self):56 sorted_dict = SortedDict()57 sorted_dict.set('A', 12)58 sorted_dict.set('B', 13)59 sorted_dict.set('C', 15)60 res = []61 for v in sorted_dict.values(reverse=True):62 res.append(v)...
49_group_anagrams.py
Source: 49_group_anagrams.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# @Time : 2022/1/27 11:25 ä¸å4# @Author : xinming5# @File : 49_group_anagrams.py6from typing import List7class Solution:8 def groupAnagrams(self, strs: List[str]) -> List[List[str]]:9 out=[]10 sorted_dict={}11 for i in strs:12 ch_list = sorted(i)13 keys="".join(ch_list)14 if keys not in sorted_dict.keys():15 sorted_dict[keys]=[]16 sorted_dict[keys].append(i)17 for k, v in sorted_dict.items():18 out.append(v)19 # list(sorted_dict.values()) æ´å ç®æ´ã20 return out21if __name__=='__main__':22 strs = ["eat", "tea", "tan", "ate", "nat", "bat"]23 out = Solution().groupAnagrams(strs)...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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!!