How to use compare_dicts method in Sure

Best Python code snippet using sure_python

test_orders.py

Source:test_orders.py Github

copy

Full Screen

...15# with this program. If not, see <https://www.gnu.org/licenses/>.16# ==============================================================================17""" Test order conversion. """18from diplomacy.integration.webdiplomacy_net.orders import Order19def compare_dicts(dict_1, dict_2):20 """ Checks if two dictionaries are equal """21 keys_1 = set(dict_1.keys()) - {'convoyPath'}22 keys_2 = set(dict_2.keys()) - {'convoyPath'}23 if keys_1 != keys_2:24 return False25 for key in keys_1:26 if dict_1[key] != dict_2[key]:27 return False28 return True29def test_hold_army_001():30 """ Tests hold army """31 raw_order = 'A PAR H'32 order_str = 'A PAR H'33 order_dict = {'terrID': 47,34 'unitType': 'Army',35 'type': 'Hold',36 'toTerrID': '',37 'fromTerrID': '',38 'viaConvoy': ''}39 order_from_string = Order(raw_order)40 order_from_dict = Order(order_dict)41 # Validating42 assert order_from_string.to_string() == order_str43 assert compare_dicts(order_from_string.to_dict(), order_dict)44 assert order_from_dict.to_string() == order_str45 assert compare_dicts(order_from_dict.to_dict(), order_dict)46def test_hold_army_002():47 """ Tests hold army """48 raw_order = 'A ABC H'49 order_str = ''50 order_dict = {}51 order_from_string = Order(raw_order)52 order_from_dict = Order(order_dict)53 # Validating54 assert order_from_string.to_string() == order_str55 assert compare_dicts(order_from_string.to_dict(), order_dict)56 assert order_from_dict.to_string() == order_str57 assert compare_dicts(order_from_dict.to_dict(), order_dict)58def test_hold_fleet_001():59 """ Tests hold fleet """60 raw_order = 'F LON H'61 order_str = 'F LON H'62 order_dict = {'terrID': 6,63 'unitType': 'Fleet',64 'type': 'Hold',65 'toTerrID': '',66 'fromTerrID': '',67 'viaConvoy': ''}68 order_from_string = Order(raw_order)69 order_from_dict = Order(order_dict)70 # Validating71 assert order_from_string.to_string() == order_str72 assert compare_dicts(order_from_string.to_dict(), order_dict)73 assert order_from_dict.to_string() == order_str74 assert compare_dicts(order_from_dict.to_dict(), order_dict)75def test_move_army_001():76 """ Tests move army """77 raw_order = 'A YOR - LON'78 order_str = 'A YOR - LON'79 order_dict = {'terrID': 4,80 'unitType': 'Army',81 'type': 'Move',82 'toTerrID': 6,83 'fromTerrID': '',84 'viaConvoy': 'No'}85 order_from_string = Order(raw_order)86 order_from_dict = Order(order_dict)87 # Validating88 assert order_from_string.to_string() == order_str89 assert compare_dicts(order_from_string.to_dict(), order_dict)90 assert order_from_dict.to_string() == order_str91 assert compare_dicts(order_from_dict.to_dict(), order_dict)92def test_move_army_002():93 """ Tests move army """94 raw_order = 'A PAR - LON VIA'95 order_str = 'A PAR - LON VIA'96 order_dict = {'terrID': 47,97 'unitType': 'Army',98 'type': 'Move',99 'toTerrID': 6,100 'fromTerrID': '',101 'viaConvoy': 'Yes'}102 order_from_string = Order(raw_order)103 order_from_dict = Order(order_dict)104 # Validating105 assert order_from_string.to_string() == order_str106 assert compare_dicts(order_from_string.to_dict(), order_dict)107 assert order_from_dict.to_string() == order_str108 assert compare_dicts(order_from_dict.to_dict(), order_dict)109def test_move_fleet_001():110 """ Tests move fleet """111 raw_order = 'F BRE - MAO'112 order_str = 'F BRE - MAO'113 order_dict = {'terrID': 46,114 'unitType': 'Fleet',115 'type': 'Move',116 'toTerrID': 61,117 'fromTerrID': '',118 'viaConvoy': 'No'}119 order_from_string = Order(raw_order)120 order_from_dict = Order(order_dict)121 # Validating122 assert order_from_string.to_string() == order_str123 assert compare_dicts(order_from_string.to_dict(), order_dict)124 assert order_from_dict.to_string() == order_str125 assert compare_dicts(order_from_dict.to_dict(), order_dict)126def test_support_hold_001():127 """ Tests for support hold """128 raw_order = 'A PAR S F BRE'129 order_str = 'A PAR S BRE'130 order_dict = {'terrID': 47,131 'unitType': 'Army',132 'type': 'Support hold',133 'toTerrID': 46,134 'fromTerrID': '',135 'viaConvoy': ''}136 order_from_string = Order(raw_order)137 order_from_dict = Order(order_dict)138 # Validating139 assert order_from_string.to_string() == order_str140 assert compare_dicts(order_from_string.to_dict(), order_dict)141 assert order_from_dict.to_string() == order_str142 assert compare_dicts(order_from_dict.to_dict(), order_dict)143def test_support_hold_002():144 """ Tests for support hold """145 raw_order = 'F MAO S F BRE'146 order_str = 'F MAO S BRE'147 order_dict = {'terrID': 61,148 'unitType': 'Fleet',149 'type': 'Support hold',150 'toTerrID': 46,151 'fromTerrID': '',152 'viaConvoy': ''}153 order_from_string = Order(raw_order)154 order_from_dict = Order(order_dict)155 # Validating156 assert order_from_string.to_string() == order_str157 assert compare_dicts(order_from_string.to_dict(), order_dict)158 assert order_from_dict.to_string() == order_str159 assert compare_dicts(order_from_dict.to_dict(), order_dict)160def test_support_move_001():161 """ Tests support move """162 raw_order = 'A PAR S F MAO - BRE'163 order_str = 'A PAR S MAO - BRE'164 order_dict = {'terrID': 47,165 'unitType': 'Army',166 'type': 'Support move',167 'toTerrID': 46,168 'fromTerrID': 61,169 'viaConvoy': ''}170 order_from_string = Order(raw_order)171 order_from_dict = Order(order_dict)172 # Validating173 assert order_from_string.to_string() == order_str174 assert compare_dicts(order_from_string.to_dict(), order_dict)175 assert order_from_dict.to_string() == order_str176 assert compare_dicts(order_from_dict.to_dict(), order_dict)177def test_support_move_002():178 """ Tests support move """179 raw_order = 'F MAO S A PAR - BRE'180 order_str = 'F MAO S PAR - BRE'181 order_dict = {'terrID': 61,182 'unitType': 'Fleet',183 'type': 'Support move',184 'toTerrID': 46,185 'fromTerrID': 47,186 'viaConvoy': ''}187 order_from_string = Order(raw_order)188 order_from_dict = Order(order_dict)189 # Validating190 assert order_from_string.to_string() == order_str191 assert compare_dicts(order_from_string.to_dict(), order_dict)192 assert order_from_dict.to_string() == order_str193 assert compare_dicts(order_from_dict.to_dict(), order_dict)194def test_convoy_001():195 """ Tests convoy """196 raw_order = 'F MAO C A PAR - LON'197 order_str = 'F MAO C A PAR - LON'198 order_dict = {'terrID': 61,199 'unitType': 'Fleet',200 'type': 'Convoy',201 'toTerrID': 6,202 'fromTerrID': 47,203 'viaConvoy': ''}204 order_from_string = Order(raw_order)205 order_from_dict = Order(order_dict)206 # Validating207 assert order_from_string.to_string() == order_str208 assert compare_dicts(order_from_string.to_dict(), order_dict)209 assert order_from_dict.to_string() == order_str210 assert compare_dicts(order_from_dict.to_dict(), order_dict)211def test_retreat_army_001():212 """ Tests retreat army """213 raw_order = 'A PAR R LON'214 order_str = 'A PAR R LON'215 order_dict = {'terrID': 47,216 'unitType': 'Army',217 'type': 'Retreat',218 'toTerrID': 6,219 'fromTerrID': '',220 'viaConvoy': ''}221 order_from_string = Order(raw_order)222 order_from_dict = Order(order_dict)223 # Validating224 assert order_from_string.to_string() == order_str225 assert compare_dicts(order_from_string.to_dict(), order_dict)226 assert order_from_dict.to_string() == order_str227 assert compare_dicts(order_from_dict.to_dict(), order_dict)228def test_retreat_army_002():229 """ Tests retreat army """230 raw_order = 'A PAR - LON'231 order_str = 'A PAR R LON'232 order_dict = {'terrID': 47,233 'unitType': 'Army',234 'type': 'Retreat',235 'toTerrID': 6,236 'fromTerrID': '',237 'viaConvoy': ''}238 order_from_string = Order(raw_order, phase_type='R')239 order_from_dict = Order(order_dict, phase_type='R')240 # Validating241 assert order_from_string.to_string() == order_str242 assert compare_dicts(order_from_string.to_dict(), order_dict)243 assert order_from_dict.to_string() == order_str244 assert compare_dicts(order_from_dict.to_dict(), order_dict)245def test_retreat_fleet_001():246 """ Tests retreat fleet """247 raw_order = 'F BRE R SPA/SC'248 order_str = 'F BRE R SPA/SC'249 order_dict = {'terrID': 46,250 'unitType': 'Fleet',251 'type': 'Retreat',252 'toTerrID': 77,253 'fromTerrID': '',254 'viaConvoy': ''}255 order_from_string = Order(raw_order)256 order_from_dict = Order(order_dict)257 # Validating258 assert order_from_string.to_string() == order_str259 assert compare_dicts(order_from_string.to_dict(), order_dict)260 assert order_from_dict.to_string() == order_str261 assert compare_dicts(order_from_dict.to_dict(), order_dict)262def test_disband_army_001():263 """ Tests disband army """264 raw_order = 'A PAR D'265 order_str = 'A PAR D'266 order_dict = {'terrID': 47,267 'unitType': 'Army',268 'type': 'Disband',269 'toTerrID': '',270 'fromTerrID': '',271 'viaConvoy': ''}272 order_from_string = Order(raw_order, phase_type='R')273 order_from_dict = Order(order_dict, phase_type='R')274 # Validating275 assert order_from_string.to_string() == order_str276 assert compare_dicts(order_from_string.to_dict(), order_dict)277 assert order_from_dict.to_string() == order_str278 assert compare_dicts(order_from_dict.to_dict(), order_dict)279def test_disband_fleet_001():280 """ Tests disband fleet """281 raw_order = 'F BRE D'282 order_str = 'F BRE D'283 order_dict = {'terrID': 46,284 'unitType': 'Fleet',285 'type': 'Disband',286 'toTerrID': '',287 'fromTerrID': '',288 'viaConvoy': ''}289 order_from_string = Order(raw_order, phase_type='R')290 order_from_dict = Order(order_dict, phase_type='R')291 # Validating292 assert order_from_string.to_string() == order_str293 assert compare_dicts(order_from_string.to_dict(), order_dict)294 assert order_from_dict.to_string() == order_str295 assert compare_dicts(order_from_dict.to_dict(), order_dict)296def test_disband_fleet_coast_001():297 """ Tests disband fleet (retreats phase) """298 raw_order = 'F SPA/NC D'299 order_str = 'F SPA/NC D'300 order_dict = {'terrID': 76,301 'unitType': 'Fleet',302 'type': 'Disband',303 'toTerrID': '',304 'fromTerrID': '',305 'viaConvoy': ''}306 order_from_string = Order(raw_order, phase_type='R')307 order_from_dict = Order(order_dict, phase_type='R')308 # Validating309 assert order_from_string.to_string() == order_str310 assert compare_dicts(order_from_string.to_dict(), order_dict)311 assert order_from_dict.to_string() == order_str312 assert compare_dicts(order_from_dict.to_dict(), order_dict)313def test_disband_fleet_coast_002():314 """ Tests disband fleet (adjustment phase)"""315 raw_order = 'F SPA/NC D'316 order_str = 'F SPA D'317 order_dict = {'terrID': 8,318 'unitType': 'Fleet',319 'type': 'Destroy',320 'toTerrID': 8,321 'fromTerrID': '',322 'viaConvoy': ''}323 order_from_string = Order(raw_order, phase_type='A')324 order_from_dict = Order(order_dict, phase_type='A')325 # Validating326 assert order_from_string.to_string() == order_str327 assert compare_dicts(order_from_string.to_dict(), order_dict)328 assert order_from_dict.to_string() == order_str329 assert compare_dicts(order_from_dict.to_dict(), order_dict)330def test_build_army_001():331 """ Tests build army """332 raw_order = 'A PAR B'333 order_str = 'A PAR B'334 order_dict = {'terrID': 47,335 'unitType': 'Army',336 'type': 'Build Army',337 'toTerrID': 47,338 'fromTerrID': '',339 'viaConvoy': ''}340 order_from_string = Order(raw_order)341 order_from_dict = Order(order_dict)342 # Validating343 assert order_from_string.to_string() == order_str344 assert compare_dicts(order_from_string.to_dict(), order_dict)345 assert order_from_dict.to_string() == order_str346 assert compare_dicts(order_from_dict.to_dict(), order_dict)347def test_build_fleet_001():348 """ Tests build fleet """349 raw_order = 'F BRE B'350 order_str = 'F BRE B'351 order_dict = {'terrID': 46,352 'unitType': 'Fleet',353 'type': 'Build Fleet',354 'toTerrID': 46,355 'fromTerrID': '',356 'viaConvoy': ''}357 order_from_string = Order(raw_order)358 order_from_dict = Order(order_dict)359 # Validating360 assert order_from_string.to_string() == order_str361 assert compare_dicts(order_from_string.to_dict(), order_dict)362 assert order_from_dict.to_string() == order_str363 assert compare_dicts(order_from_dict.to_dict(), order_dict)364def test_disband_army_002():365 """ Tests disband army """366 raw_order = 'A PAR D'367 order_str = 'A PAR D'368 order_dict = {'terrID': 47,369 'unitType': 'Army',370 'type': 'Destroy',371 'toTerrID': 47,372 'fromTerrID': '',373 'viaConvoy': ''}374 order_from_string = Order(raw_order, phase_type='A')375 order_from_dict = Order(order_dict, phase_type='A')376 # Validating377 assert order_from_string.to_string() == order_str378 assert compare_dicts(order_from_string.to_dict(), order_dict)379 assert order_from_dict.to_string() == order_str380 assert compare_dicts(order_from_dict.to_dict(), order_dict)381def test_disband_fleet_002():382 """ Tests disband fleet """383 raw_order = 'F BRE D'384 order_str = 'F BRE D'385 order_dict = {'terrID': 46,386 'unitType': 'Fleet',387 'type': 'Destroy',388 'toTerrID': 46,389 'fromTerrID': '',390 'viaConvoy': ''}391 order_from_string = Order(raw_order, phase_type='A')392 order_from_dict = Order(order_dict, phase_type='A')393 # Validating394 assert order_from_string.to_string() == order_str395 assert compare_dicts(order_from_string.to_dict(), order_dict)396 assert order_from_dict.to_string() == order_str...

Full Screen

Full Screen

compare_utils_test.py

Source:compare_utils_test.py Github

copy

Full Screen

...8__version__ = "0.1"9__copyright__ = "Copyright(c) 2017, Cisco Systems, Inc."10__status__ = "alpha"11def _transformation_f(data: dict):12 """Example transformation function for compare_dicts()"""13 data['test_key'] = 'test'14 return data15class TestCompareDicts(unittest.TestCase):16 """Class is a Test Suit for compare_dicts() function"""17 def setUp(self):18 self.one_level_dict = dict(19 key1='value1',20 key2='value2',21 key3='value3',22 key4='value4'23 )24 self.dict_with_nested = dict(25 key1='value1',26 key2=['value2', 'value3'],27 key5=dict(28 key6='value4',29 key7=dict(30 key8='value5'31 )32 )33 )34 def test_one_dict_empty(self):35 """One of the given dicts is empty"""36 self.assertFalse(compare_dicts(self.one_level_dict, {}))37 self.assertFalse(compare_dicts({}, self.one_level_dict))38 self.assertTrue(compare_dicts({}, {}))39 def test_one_level_dicts(self):40 """Tests with flat dicts"""41 # UseCase 0: dicts are duplicates42 second_dict = self.one_level_dict.copy()43 self.assertTrue(compare_dicts(self.one_level_dict, second_dict))44 # UseCase 1: second dictionary created independently45 second_dict = dict(46 key3='value3',47 key1='value1',48 key2='value2',49 key4='value4'50 )51 self.assertTrue(compare_dicts(self.one_level_dict, second_dict))52 # UseCase 2: second dictionary has extra key53 second_dict['key5'] = 'value5'54 self.assertFalse(compare_dicts(self.one_level_dict, second_dict))55 # Remove extra key56 second_dict.pop('key5')57 self.assertTrue(compare_dicts(self.one_level_dict, second_dict))58 # UseCase 3: second dictionary has different value(-s)59 second_dict['key1'] = 'test'60 second_dict['key4'] = 'test'61 self.assertFalse(compare_dicts(self.one_level_dict, second_dict))62 # Roll back correct values63 second_dict['key1'] = self.one_level_dict['key1']64 second_dict['key4'] = self.one_level_dict['key4']65 self.assertTrue(compare_dicts(self.one_level_dict, second_dict))66 # UseCase 4: passing a transformation function to compare_dicts()67 self.assertTrue(compare_dicts(self.one_level_dict, second_dict, _transformation_f))68 def test_complex_dicts(self):69 """Tests with complex dicts (dicts values can be lists or nested dicts)"""70 # UseCase 0: dicts are duplicates71 second_dict = self.dict_with_nested.copy()72 self.assertTrue(compare_dicts(self.dict_with_nested, second_dict))73 # UseCase 1: second dictionary created independently74 second_dict = dict(75 key1='value1',76 key5=dict(77 key7=dict(78 key8='value5'79 ),80 key6='value4'81 ),82 key2=['value2', 'value3']83 )84 self.assertTrue(compare_dicts(self.dict_with_nested, second_dict))85 # UseCase 2: second dictionary has extra key86 second_dict['test'] = 'test'87 self.assertFalse(compare_dicts(self.dict_with_nested, second_dict))88 # Remove extra key89 second_dict.pop('test')90 self.assertTrue(compare_dicts(self.dict_with_nested, second_dict))91 # UseCase 3: second dictionary has a different value (first level)92 second_dict['key1'] = 'test'93 self.assertFalse(compare_dicts(self.dict_with_nested, second_dict))94 # Roll back correct value95 second_dict['key1'] = self.dict_with_nested['key1']96 self.assertTrue(compare_dicts(self.dict_with_nested, second_dict))97 # UseCase 4: second dictnary has a different value (nested dict value)98 second_dict['key5']['key6'] = 'test'99 self.assertFalse(compare_dicts(self.dict_with_nested, second_dict))100 # Rolla back correct value101 second_dict['key5']['key6'] = self.dict_with_nested['key5']['key6']102 self.assertTrue(compare_dicts(self.dict_with_nested, second_dict))103class TestDefaultFullCompare(unittest.TestCase):104 """Class is a Test Suit for singledispatched function default_full_compare() function"""105 def setUp(self):106 self.expected_dict = dict(107 uuid='value1', # excluded from comparison by default108 key1='value2',109 key2=dict(110 key3='value3',111 key4=True112 ),113 key5=['value5', 'value6'],114 key6=[115 dict(116 key7='value7',...

Full Screen

Full Screen

bibrank_citation_indexer_regression_tests.py

Source:bibrank_citation_indexer_regression_tests.py Github

copy

Full Screen

...33EXPECTED_DICTS = {34 'refs': {77: [95], 79: [78], 80: [94], 82: [81], 83: [81], 85: [77, 84], 86: [77, 95], 87: [81], 88: [84], 89: [81], 91: [78, 79, 84], 92: [74, 91], 96: [18]},35 'cites': {18: [96], 74: [92], 77: [85, 86], 78: [79, 91], 79: [91], 81: [82, 83, 87, 89], 84: [85, 88, 91], 91: [92], 94: [80], 95: [77, 86]},36}37def compare_dicts(tester, dic, expected):38 # Clean out empty sets39 for k, v in dic.items():40 if not v:41 del dic[k]42 dic = dict([(k, sorted(list(v))) for k, v in dic.iteritems()])43 tester.assertEqual(dic, expected)44def remove_from_dicts(dicts, recid):45 for recid in dicts['cites'].keys():46 try:47 dicts['cites'][recid].remove(recid)48 dicts['cites_weight'] -= 149 except ValueError:50 pass51 else:52 if not dicts['cites'][recid]:53 del dicts['cites'][recid]54 del dicts['cites_weight'][recid]55 for recid in dicts['refs'].keys():56 try:57 dicts['refs'][recid].remove(recid)58 except ValueError:59 pass60 else:61 if not dicts['refs'][recid]:62 del dicts['refs'][recid]63class TestCitationIndexer(InvenioTestCase):64 """Testing citation indexer."""65 def setUp(self):66 logger = logging.getLogger()67 for handler in logger.handlers:68 logger.removeHandler(handler)69 formatter = logging.Formatter('%(asctime)s --> %(message)s', '%Y-%m-%d %H:%M:%S')70 stdout_logger = logging.StreamHandler(sys.stdout)71 stdout_logger.setFormatter(formatter)72 # stdout_logger.setLevel(logging.DEBUG)73 stdout_logger.setLevel(logging.CRITICAL)74 stderr_logger = logging.StreamHandler(sys.stderr)75 stderr_logger.setFormatter(formatter)76 # stderr_logger.setLevel(logging.WARNING)77 stderr_logger.setLevel(logging.CRITICAL)78 logger.addHandler(stderr_logger)79 logger.addHandler(stdout_logger)80 logger.setLevel(logging.INFO)81 def test_basic(self):82 from invenio.bibrank_citation_indexer import process_chunk83 cites, refs = process_chunk(range(1, 100), CONFIG)84 compare_dicts(self, cites, EXPECTED_DICTS['cites'])85 compare_dicts(self, refs, EXPECTED_DICTS['refs'])86 def test_adding_record(self):87 "tests adding a record"88 from invenio.bibrank_citation_indexer import process_chunk89 cites, refs = process_chunk([92], CONFIG)90 expected_cites = {}91 compare_dicts(self, cites, expected_cites)92 expected_refs = {92: [74, 91]}93 compare_dicts(self, refs, expected_refs)94 def test_catchup(self):95 "tests adding a record (with catchup)"96 from invenio.bibrank_citation_indexer import process_chunk97 cites, refs = process_chunk([95], CONFIG)98 expected_cites = {95: [77, 86]}99 compare_dicts(self, cites, expected_cites)100 expected_refs = {}101 compare_dicts(self, refs, expected_refs)102 def test_db_adding_and_removing_records(self):103 from invenio.bibrank_citation_searcher import get_cited_by104 from invenio.bibrank_citation_indexer import store_dicts105 store_dicts([42222],106 refs={42222: set([43333])},107 cites={42222: set([40000, 40001])})108 cited_by_42222 = get_cited_by(42222)109 cited_by_43333 = get_cited_by(43333)110 store_dicts([42222],111 refs={42222: set()},112 cites={42222: set()})113 self.assertEqual(cited_by_42222, set([40000, 40001]))114 self.assertEqual(cited_by_43333, set([42222]))115 self.assertEqual(get_cited_by(42222), set())...

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 Sure 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