Best Python code snippet using molotov_python
convert_main.py
Source:convert_main.py
...589 for i in range(10):590 with glb.db_connect() as conn:591 with conn.cursor(as_dict=True) as cursor:592 cursor.execute("SELECT * FROM zhanbao_tbl WHERE id=4274 order by id asc")593 row = cursor.fetchone()594 while row:595 b1_snapshot = tracemalloc.take_snapshot()596 try:597 print('worker_no:'+ row['worker_no']+"\t"+ str(row['id']) +" "+ str(tracemalloc.get_traced_memory()))598 files_template_exec(row['id'],json.loads(row['config_txt']),row['worker_no'],glb.config['UPLOAD_FOLDER'] ,wx_queue=glb.msg_queue) 599 print("====================================")600 print('worker_no:'+ row['worker_no']+"\t"+ str(row['id']) +" "+ str(tracemalloc.get_traced_memory()))601 print("====================================")602 snapshot2 = tracemalloc.take_snapshot()603 top_stats = snapshot2.compare_to(b1_snapshot, 'lineno')604 for stat in top_stats[:10]:605 print(stat)606 print("====================================")607 except Exception as e:608 print(e)609 row = cursor.fetchone()610 gc.collect() 611 objgraph.show_most_common_types(limit=5) 612 ### æå°åºå¯¹è±¡æ°ç®æå¤ç 50 个类åä¿¡æ¯ 613 gc.collect() ...
test_utils.py
Source:test_utils.py
1# -*- coding: utf-8 -*-2from datetime import datetime3import sys4from unittest import mock5import pytest6from awxkit import utils7from awxkit import exceptions as exc8@pytest.mark.parametrize('inp, out',9 [[True, True],10 [False, False],11 [1, True],12 [0, False],13 [1.0, True],14 [0.0, False],15 ['TrUe', True],16 ['FalSe', False],17 ['yEs', True],18 ['No', False],19 ['oN', True],20 ['oFf', False],21 ['asdf', True],22 ['0', False],23 ['', False],24 [{1: 1}, True],25 [{}, False],26 [(0,), True],27 [(), False],28 [[1], True],29 [[], False]])30def test_to_bool(inp, out):31 assert utils.to_bool(inp) == out32@pytest.mark.parametrize('inp, out',33 [["{}", {}],34 ["{'null': null}", {"null": None}],35 ["{'bool': true}", {"bool": True}],36 ["{'bool': false}", {"bool": False}],37 ["{'int': 0}", {"int": 0}],38 ["{'float': 1.0}", {"float": 1.0}],39 ["{'str': 'abc'}", {"str": "abc"}],40 ["{'obj': {}}", {"obj": {}}],41 ["{'list': []}", {"list": []}],42 ["---", None],43 ["---\n'null': null", {'null': None}],44 ["---\n'bool': true", {'bool': True}],45 ["---\n'bool': false", {'bool': False}],46 ["---\n'int': 0", {'int': 0}],47 ["---\n'float': 1.0", {'float': 1.0}],48 ["---\n'string': 'abc'", {'string': 'abc'}],49 ["---\n'obj': {}", {'obj': {}}],50 ["---\n'list': []", {'list': []}],51 ["", None],52 ["'null': null", {'null': None}],53 ["'bool': true", {'bool': True}],54 ["'bool': false", {'bool': False}],55 ["'int': 0", {'int': 0}],56 ["'float': 1.0", {'float': 1.0}],57 ["'string': 'abc'", {'string': 'abc'}],58 ["'obj': {}", {'obj': {}}],59 ["'list': []", {'list': []}]])60def test_load_valid_json_or_yaml(inp, out):61 assert utils.load_json_or_yaml(inp) == out62@pytest.mark.parametrize('inp', [True, False, 0, 1.0, {}, [], None])63def test_load_invalid_json_or_yaml(inp):64 with pytest.raises(TypeError):65 utils.load_json_or_yaml(inp)66@pytest.mark.parametrize('non_ascii', [True, False])67@pytest.mark.skipif(68 sys.version_info < (3, 6),69 reason='this is only intended to be used in py3, not the CLI'70)71def test_random_titles_are_unicode(non_ascii):72 assert isinstance(utils.random_title(non_ascii=non_ascii), str)73@pytest.mark.parametrize('non_ascii', [True, False])74@pytest.mark.skipif(75 sys.version_info < (3, 6),76 reason='this is only intended to be used in py3, not the CLI'77)78def test_random_titles_generates_correct_characters(non_ascii):79 title = utils.random_title(non_ascii=non_ascii)80 if non_ascii:81 with pytest.raises(UnicodeEncodeError):82 title.encode('ascii')83 title.encode('utf-8')84 else:85 title.encode('ascii')86 title.encode('utf-8')87@pytest.mark.parametrize('inp, out',88 [['ClassNameShouldChange', 'class_name_should_change'],89 ['classnameshouldntchange', 'classnameshouldntchange'],90 ['Classspacingshouldntchange', 'classspacingshouldntchange'],91 ['Class1Name2Should3Change', 'class_1_name_2_should_3_change'],92 ['Class123name234should345change456', 'class_123_name_234_should_345_change_456']])93def test_class_name_to_kw_arg(inp, out):94 assert utils.class_name_to_kw_arg(inp) == out95@pytest.mark.parametrize('first, second, expected',96 [['/api/v2/resources/', '/api/v2/resources/', True],97 ['/api/v2/resources/', '/api/v2/resources/?test=ignored', True],98 ['/api/v2/resources/?one=ignored', '/api/v2/resources/?two=ignored', True],99 ['http://one.com', 'http://one.com', True],100 ['http://one.com', 'http://www.one.com', True],101 ['http://one.com', 'http://one.com?test=ignored', True],102 ['http://one.com', 'http://www.one.com?test=ignored', True],103 ['http://one.com', 'https://one.com', False],104 ['http://one.com', 'https://one.com?test=ignored', False]])105def test_are_same_endpoint(first, second, expected):106 assert utils.are_same_endpoint(first, second) == expected107@pytest.mark.parametrize('endpoint, expected',108 [['/api/v2/resources/', 'v2'],109 ['/api/v2000/resources/', 'v2000'],110 ['/api/', 'common']])111def test_version_from_endpoint(endpoint, expected):112 assert utils.version_from_endpoint(endpoint) == expected113class OneClass:114 pass115class TwoClass:116 pass117class ThreeClass:118 pass119class FourClass(ThreeClass):120 pass121def test_filter_by_class_with_subclass_class():122 filtered = utils.filter_by_class((OneClass, OneClass), (FourClass, ThreeClass))123 assert filtered == [OneClass, FourClass]124def test_filter_by_class_with_subclass_instance():125 one = OneClass()126 four = FourClass()127 filtered = utils.filter_by_class((one, OneClass), (four, ThreeClass))128 assert filtered == [one, four]129def test_filter_by_class_no_arg_tuples():130 three = ThreeClass()131 filtered = utils.filter_by_class((True, OneClass), (False, TwoClass), (three, ThreeClass))132 assert filtered == [OneClass, None, three]133def test_filter_by_class_with_arg_tuples_containing_class():134 one = OneClass()135 three = (ThreeClass, dict(one=1, two=2))136 filtered = utils.filter_by_class((one, OneClass), (False, TwoClass), (three, ThreeClass))137 assert filtered == [one, None, three]138def test_filter_by_class_with_arg_tuples_containing_subclass():139 one = OneClass()140 three = (FourClass, dict(one=1, two=2))141 filtered = utils.filter_by_class((one, OneClass), (False, TwoClass), (three, ThreeClass))142 assert filtered == [one, None, three]143@pytest.mark.parametrize('truthy', (True, 123, 'yes'))144def test_filter_by_class_with_arg_tuples_containing_truthy(truthy):145 one = OneClass()146 three = (truthy, dict(one=1, two=2))147 filtered = utils.filter_by_class((one, OneClass), (False, TwoClass), (three, ThreeClass))148 assert filtered == [one, None, (ThreeClass, dict(one=1, two=2))]149@pytest.mark.parametrize('date_string,now,expected', [150 ('2017-12-20T00:00:01.5Z', datetime(2017, 12, 20, 0, 0, 2, 750000), 1.25),151 ('2017-12-20T00:00:01.5Z', datetime(2017, 12, 20, 0, 0, 1, 500000), 0.00),152 ('2017-12-20T00:00:01.5Z', datetime(2017, 12, 20, 0, 0, 0, 500000), -1.00),153])154def test_seconds_since_date_string(date_string, now, expected):155 with mock.patch('awxkit.utils.utcnow', return_value=now):156 assert utils.seconds_since_date_string(date_string) == expected157class RecordingCallback(object):158 def __init__(self, value=True):159 self.call_count = 0160 self.value = value161 def __call__(self):162 self.call_count += 1163 return self.value164def test_suppress():165 callback = RecordingCallback()166 with utils.suppress(ZeroDivisionError, IndexError):167 raise ZeroDivisionError168 callback()169 raise IndexError170 raise KeyError171 assert callback.call_count == 0172 with utils.suppress(ZeroDivisionError, IndexError):173 raise IndexError174 callback()175 raise ZeroDivisionError176 raise KeyError177 assert callback.call_count == 0178 with pytest.raises(KeyError):179 with utils.suppress(ZeroDivisionError, IndexError):180 raise KeyError181 callback()182 raise ZeroDivisionError183 raise IndexError184 assert callback.call_count == 0185class TestPollUntil(object):186 @pytest.mark.parametrize('timeout', [0, 0.0, -0.5, -1, -9999999])187 def test_callback_called_once_for_non_positive_timeout(self, timeout):188 with mock.patch('awxkit.utils.logged_sleep') as sleep:189 callback = RecordingCallback()190 utils.poll_until(callback, timeout=timeout)191 assert not sleep.called192 assert callback.call_count == 1193 def test_exc_raised_on_timeout(self):194 with mock.patch('awxkit.utils.logged_sleep'):195 with pytest.raises(exc.WaitUntilTimeout):196 utils.poll_until(lambda: False, timeout=0)197 @pytest.mark.parametrize('callback_value', [{'hello': 1}, 'foo', True])198 def test_non_falsey_callback_value_is_returned(self, callback_value):199 with mock.patch('awxkit.utils.logged_sleep'):200 assert utils.poll_until(lambda: callback_value) == callback_value201class TestPseudoNamespace(object):202 def test_set_item_check_item(self):203 pn = utils.PseudoNamespace()204 pn['key'] = 'value'205 assert pn['key'] == 'value'206 def test_set_item_check_attr(self):207 pn = utils.PseudoNamespace()208 pn['key'] = 'value'209 assert pn.key == 'value'210 def test_set_attr_check_item(self):211 pn = utils.PseudoNamespace()212 pn.key = 'value'213 assert pn['key'] == 'value'214 def test_set_attr_check_attr(self):215 pn = utils.PseudoNamespace()216 pn.key = 'value'217 assert pn.key == 'value'218 def test_auto_dicts_cast(self):219 pn = utils.PseudoNamespace()220 pn.one = dict()221 pn.one.two = dict(three=3)222 assert pn.one.two.three == 3223 assert pn == dict(one=dict(two=dict(three=3)))224 def test_auto_list_of_dicts_cast(self):225 pn = utils.PseudoNamespace()226 pn.one = [dict(two=2), dict(three=3)]227 assert pn.one[0].two == 2228 assert pn == dict(one=[dict(two=2), dict(three=3)])229 def test_auto_tuple_of_dicts_cast(self):230 pn = utils.PseudoNamespace()231 pn.one = (dict(two=2), dict(three=3))232 assert pn.one[0].two == 2233 assert pn == dict(one=(dict(two=2), dict(three=3)))234 def test_instantiation_via_dict(self):235 pn = utils.PseudoNamespace(dict(one=1, two=2, three=3))236 assert pn.one == 1237 assert pn == dict(one=1, two=2, three=3)238 assert len(pn.keys()) == 3239 def test_instantiation_via_kwargs(self):240 pn = utils.PseudoNamespace(one=1, two=2, three=3)241 assert pn.one == 1242 assert pn == dict(one=1, two=2, three=3)243 assert len(pn.keys()) == 3244 def test_instantiation_via_dict_and_kwargs(self):245 pn = utils.PseudoNamespace(dict(one=1, two=2, three=3), four=4, five=5)246 assert pn.one == 1247 assert pn.four == 4248 assert pn == dict(one=1, two=2, three=3, four=4, five=5)249 assert len(pn.keys()) == 5250 def test_instantiation_via_nested_dict(self):251 pn = utils.PseudoNamespace(dict(one=1, two=2), three=dict(four=4, five=dict(six=6)))252 assert pn.one == 1253 assert pn.three.four == 4254 assert pn.three.five.six == 6255 assert pn == dict(one=1, two=2, three=dict(four=4, five=dict(six=6)))256 def test_instantiation_via_nested_dict_with_list(self):257 pn = utils.PseudoNamespace(dict(one=[dict(two=2), dict(three=3)]))258 assert pn.one[0].two == 2259 assert pn.one[1].three == 3260 assert pn == dict(one=[dict(two=2), dict(three=3)])261 def test_instantiation_via_nested_dict_with_lists(self):262 pn = utils.PseudoNamespace(dict(one=[dict(two=2),263 dict(three=dict(four=4,264 five=[dict(six=6),265 dict(seven=7)]))]))266 assert pn.one[1].three.five[1].seven == 7267 def test_instantiation_via_nested_dict_with_tuple(self):268 pn = utils.PseudoNamespace(dict(one=(dict(two=2), dict(three=3))))269 assert pn.one[0].two == 2270 assert pn.one[1].three == 3271 assert pn == dict(one=(dict(two=2), dict(three=3)))272 def test_instantiation_via_nested_dict_with_tuples(self):273 pn = utils.PseudoNamespace(dict(one=(dict(two=2),274 dict(three=dict(four=4,275 five=(dict(six=6),276 dict(seven=7)))))))277 assert pn.one[1].three.five[1].seven == 7278 def test_update_with_nested_dict(self):279 pn = utils.PseudoNamespace()280 pn.update(dict(one=1, two=2, three=3), four=4, five=5)281 assert pn.one == 1282 assert pn.four == 4283 assert pn == dict(one=1, two=2, three=3, four=4, five=5)284 assert len(pn.keys()) == 5285 def test_update_with_nested_dict_with_lists(self):286 pn = utils.PseudoNamespace()287 pn.update(dict(one=[dict(two=2),288 dict(three=dict(four=4,289 five=[dict(six=6),290 dict(seven=7)]))]))291 assert pn.one[1].three.five[1].seven == 7292 def test_update_with_nested_dict_with_tuples(self):293 pn = utils.PseudoNamespace()294 pn.update(dict(one=(dict(two=2),295 dict(three=dict(four=4,296 five=(dict(six=6),297 dict(seven=7)))))))298 assert pn.one[1].three.five[1].seven == 7299class TestUpdatePayload(object):300 def test_empty_payload(self):301 fields = ('one', 'two', 'three', 'four')302 kwargs = dict(two=2, four=4)303 payload = {}304 utils.update_payload(payload, fields, kwargs)305 assert payload == kwargs306 def test_untouched_payload(self):307 fields = ('not', 'in', 'kwargs')308 kwargs = dict(one=1, two=2)309 payload = dict(three=3, four=4)310 utils.update_payload(payload, fields, kwargs)311 assert payload == dict(three=3, four=4)312 def test_overwritten_payload(self):313 fields = ('one', 'two')314 kwargs = dict(one=1, two=2)315 payload = dict(one='one', two='two')316 utils.update_payload(payload, fields, kwargs)317 assert payload == kwargs318 def test_falsy_kwargs(self):319 fields = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight')320 kwargs = dict(one=False, two=(), three='', four=None, five=0, six={}, seven=set(), eight=[])321 payload = {}322 utils.update_payload(payload, fields, kwargs)323 assert payload == kwargs324 def test_not_provided_strips_payload(self):325 fields = ('one', 'two')326 kwargs = dict(one=utils.not_provided)327 payload = dict(one=1, two=2)328 utils.update_payload(payload, fields, kwargs)329 assert payload == dict(two=2)330def test_to_ical():331 now = datetime.utcnow()332 ical_datetime = utils.to_ical(now)333 date = str(now.date()).replace('-', '')334 time = str(now.time()).split('.')[0].replace(':', '')...
test_registry.py
Source:test_registry.py
1import pytest2from awxkit.api.registry import URLRegistry3class One(object):4 pass5class Two(object):6 pass7@pytest.fixture8def reg():9 return URLRegistry()10def test_url_pattern(reg):11 desired = r'^/some/resources/\d+/(\?.*)*$'12 assert reg.url_pattern(r'/some/resources/\d+/').pattern == desired13def test_methodless_get_from_empty_registry(reg):14 assert reg.get('nonexistent') is None15def test_method_get_from_empty_registry(reg):16 assert reg.get('nonexistent', 'method') is None17def test_methodless_setdefault_methodless_get(reg):18 reg.setdefault(One)19 assert reg.get('some_path') is One20def test_methodless_setdefault_method_get(reg):21 reg.setdefault(One)22 assert reg.get('some_path', 'method') is One23def test_method_setdefault_methodless_get(reg):24 reg.setdefault('method', One)25 assert reg.get('some_path') is None26def test_method_setdefault_matching_method_get(reg):27 reg.setdefault('method', One)28 assert reg.get('some_path', 'method') is One29def test_method_setdefault_nonmatching_method_get(reg):30 reg.setdefault('method', One)31 assert reg.get('some_path', 'nonexistent') is None32def test_multimethod_setdefault_matching_method_get(reg):33 reg.setdefault(('method_one', 'method_two'), One)34 assert reg.get('some_path', 'method_one') is One35 assert reg.get('some_path', 'method_two') is One36def test_multimethod_setdefault_nonmatching_method_get(reg):37 reg.setdefault(('method_one', 'method_two'), One)38 assert reg.get('some_path') is None39 assert reg.get('some_path', 'nonexistent') is None40def test_wildcard_setdefault_methodless_get(reg):41 reg.setdefault('.*', One)42 assert reg.get('some_path') is One43def test_wildcard_setdefault_method_get(reg):44 reg.setdefault('.*', One)45 assert reg.get('some_path', 'method') is One46def test_regex_method_setdefaults_over_wildcard_method_get(reg):47 reg.setdefault('.*', One)48 reg.setdefault('reg.*ex', Two)49 for _ in range(1000):50 assert reg.get('some_path', 'regex') is Two51def test_methodless_registration_with_matching_path_methodless_get(reg):52 reg.register('some_path', One)53 assert reg.get('some_path') is One54def test_methodless_registraion_with_nonmatching_path_methodless_get(reg):55 reg.register('some_path', One)56 assert reg.get('nonexistent') is None57def test_methodless_registration_with_matching_path_nonmatching_method_get(reg):58 reg.register('some_path', One)59 assert reg.get('some_path', 'method') is None60def test_method_registration_with_matching_path_matching_method_get(reg):61 reg.register('some_path', 'method', One)62 assert reg.get('some_path', 'method') is One63def test_method_registration_with_matching_path_nonmatching_method_get(reg):64 reg.register('some_path', 'method_one', One)65 assert reg.get('some_path', 'method_two') is None66def test_multimethod_registration_with_matching_path_matching_method_get(reg):67 reg.register('some_path', ('method_one', 'method_two'), One)68 assert reg.get('some_path', 'method_one') is One69 assert reg.get('some_path', 'method_two') is One70def test_multimethod_registration_with_path_matching_method_get(reg):71 reg.register('some_path', ('method_one', 'method_two'), One)72 assert reg.get('some_path', 'method_three') is None73def test_multipath_methodless_registration_with_matching_path_methodless_get(reg):74 reg.register(('some_path_one', 'some_path_two'), One)75 assert reg.get('some_path_one') is One76 assert reg.get('some_path_two') is One77def test_multipath_methodless_registration_with_matching_path_nonmatching_method_get(reg):78 reg.register(('some_path_one', 'some_path_two'), One)79 assert reg.get('some_path_one', 'method') is None80 assert reg.get('some_path_two', 'method') is None81def test_multipath_method_registration_with_matching_path_matching_method_get(reg):82 reg.register((('some_path_one', 'method_one'), ('some_path_two', 'method_two')), One)83 assert reg.get('some_path_one', 'method_one') is One84 assert reg.get('some_path_two', 'method_two') is One85def test_multipath_partial_method_registration_with_matching_path_matching_method_get(reg):86 reg.register(('some_path_one', ('some_path_two', 'method')), One)87 assert reg.get('some_path_one') is One88 assert reg.get('some_path_two', 'method') is One89def test_wildcard_method_registration_with_methodless_get(reg):90 reg.register('some_path', '.*', One)91 assert reg.get('some_path') is One92def test_wildcard_method_registration_with_method_get(reg):93 reg.register('some_path', '.*', One)94 assert reg.get('some_path', 'method') is One95def test_wildcard_and_specific_method_registration_acts_as_default(reg):96 reg.register('some_path', 'method_one', Two)97 reg.register('some_path', '.*', One)98 reg.register('some_path', 'method_two', Two)99 for _ in range(1000): # eliminate overt randomness100 assert reg.get('some_path', 'nonexistent') is One101 assert reg.get('some_path', 'method_one') is Two102 assert reg.get('some_path', 'method_two') is Two103@pytest.mark.parametrize('method', ('method', '.*'))104def test_multiple_method_registrations_disallowed_for_single_path_single_registration(reg, method):105 with pytest.raises(TypeError) as e:106 reg.register((('some_path', method), ('some_path', method)), One)107 assert str(e.value) == ('"{0.pattern}" already has registered method "{1}"'108 .format(reg.url_pattern('some_path'), method))109@pytest.mark.parametrize('method', ('method', '.*'))110def test_multiple_method_registrations_disallowed_for_single_path_multiple_registrations(reg, method):111 reg.register('some_path', method, One)112 with pytest.raises(TypeError) as e:113 reg.register('some_path', method, One)114 assert str(e.value) == ('"{0.pattern}" already has registered method "{1}"'115 .format(reg.url_pattern('some_path'), method))116def test_paths_can_be_patterns(reg):117 reg.register('.*pattern.*', One)118 assert reg.get('XYZpattern123') is One119def test_mixed_form_single_registration(reg):120 reg.register([('some_path_one', 'method_one'),121 'some_path_two',122 ('some_path_three', ('method_two', 'method_three')),123 'some_path_four', 'some_path_five'], One)124 assert reg.get('some_path_one', 'method_one') is One125 assert reg.get('some_path_one') is None126 assert reg.get('some_path_one', 'nonexistent') is None127 assert reg.get('some_path_two') is One128 assert reg.get('some_path_two', 'nonexistent') is None129 assert reg.get('some_path_three', 'method_two') is One130 assert reg.get('some_path_three', 'method_three') is One131 assert reg.get('some_path_three') is None132 assert reg.get('some_path_three', 'nonexistent') is None133 assert reg.get('some_path_four') is One134 assert reg.get('some_path_four', 'nonexistent') is None135 assert reg.get('some_path_five') is One136 assert reg.get('some_path_five', 'nonexistent') is None137def test_mixed_form_single_registration_with_methodless_default(reg):138 reg.setdefault(One)139 reg.register([('some_path_one', 'method_one'),140 'some_path_two',141 ('some_path_three', ('method_two', 'method_three')),142 'some_path_four', 'some_path_five'], Two)143 assert reg.get('some_path_one', 'method_one') is Two144 assert reg.get('some_path_one') is One145 assert reg.get('some_path_one', 'nonexistent') is One146 assert reg.get('some_path_two') is Two147 assert reg.get('some_path_two', 'nonexistent') is One148 assert reg.get('some_path_three', 'method_two') is Two149 assert reg.get('some_path_three', 'method_three') is Two150 assert reg.get('some_path_three') is One151 assert reg.get('some_path_three', 'nonexistent') is One152 assert reg.get('some_path_four') is Two153 assert reg.get('some_path_four', 'nonexistent') is One154 assert reg.get('some_path_five') is Two155 assert reg.get('some_path_five', 'nonexistent') is One156def test_mixed_form_single_registration_with_method_default(reg):157 reg.setdefault('existent', One)158 reg.register([('some_path_one', 'method_one'),159 'some_path_two',160 ('some_path_three', ('method_two', 'method_three')),161 'some_path_four', 'some_path_five'], Two)162 assert reg.get('some_path_one', 'method_one') is Two163 assert reg.get('some_path_one') is None164 assert reg.get('some_path_one', 'existent') is One165 assert reg.get('some_path_one', 'nonexistent') is None166 assert reg.get('some_path_two') is Two167 assert reg.get('some_path_two', 'existent') is One168 assert reg.get('some_path_two', 'nonexistent') is None169 assert reg.get('some_path_three', 'method_two') is Two170 assert reg.get('some_path_three', 'method_three') is Two171 assert reg.get('some_path_three') is None172 assert reg.get('some_path_three', 'existent') is One173 assert reg.get('some_path_three', 'nonexistent') is None174 assert reg.get('some_path_four') is Two175 assert reg.get('some_path_four', 'existent') is One176 assert reg.get('some_path_four', 'nonexistent') is None177 assert reg.get('some_path_five') is Two178 assert reg.get('some_path_five', 'existent') is One...
animationLogic.js
Source:animationLogic.js
1//ÐозвÑаÑÐ°ÐµÑ ÑÑÑÐ¾ÐºÑ Ð°Ð½Ð¸Ð¼Ð°Ñий полÑÑеннÑÑ Ð¸Ð· Ñого ÑÑо дали2export let shiftRowGetAnimationOnePhase = (row) => {3 let thisAnimeRow = {4 one: 0, two: 0, three: 0, four: 05 }6 let variant= {7 ax000 : ((row.one !== 0) && (row.two === 0) && (row.four === 0) && (row.three === 0)),8 a0000 : ((row.one === 0) && (row.two === 0) && (row.four === 0) && (row.three === 0)),9 a000x : ((row.one === 0) && (row.two === 0) && (row.four !== 0) && (row.three === 0)),10 a0x00 : ((row.two !== 0) && (row.one === 0) && (row.three === 0) && (row.four === 0)),11 axx00 : ((row.one !== 0) && (row.two !== 0) && (row.four === 0) && (row.three === 0)),12 ax00x : ((row.one !== 0) && (row.four !== 0) && (row.two === 0) && (row.three === 0)),13 a00x0 : ((row.three !== 0) && (row.one === 0) && (row.two === 0) && (row.four === 0)),14 ax0x0 : ((row.one !== 0) && (row.two === 0) && (row.three !== 0) && (row.four === 0)),15 axxx0 : ((row.one !== 0) && (row.two !== 0) && (row.three !== 0) && (row.four === 0)),16 axx0x : ((row.one !== 0) && (row.two !== 0) && (row.four !== 0) && (row.three === 0)),17 ax0xx : ((row.one !== 0) && (row.three !== 0) && (row.four !== 0) && (row.two === 0)),18 a00xx : (((row.one === 0) && (row.two === 0) && (row.three !== 0) && (row.four !== 0))),19 a0x0x : ((row.one === 0) && (row.two !== 0) && (row.three === 0) && (row.four !== 0)),20 a0xx0 : ((row.one === 0) && (row.two !== 0) && (row.three !== 0) && (row.four === 0)),21 a0xxx : ((row.one === 0) && (row.two !== 0) && (row.three !== 0) && (row.four !== 0)),22 axxxx : ((row.one !== 0) && (row.two !== 0) && (row.three !== 0) && (row.four !== 0))23 }24 let correspondenceObject={25 a0000: {one: 0, two: 0, three: 0, four: 0},26 ax000: {one: 3, two: 0, three: 0, four: 0},27 a000x: {one: 0, two: 0, three: 0, four: 0},28 a0x00: {one: 0, two: 2, three: 0, four: 0},29 axx00: (row.one === row.two)?{one: 3, two: 2, three: 0, four: 0}:{one: 2, two: 2, three: 0, four: 0},30 ax00x: (row.one === row.four)?{one: 3, two: 0, three: 0, four: 0}:{one: 2, two: 0, three: 0, four: 0},31 a00x0: {one: 0, two: 0, three: 1, four: 0} ,32 ax0x0: (row.one === row.three)?{one: 3, two: 0, three: 1, four: 0}:{one: 2, two: 0, three: 1, four: 0},33 axxx0: (row.two === row.three)?{one: 2, two: 2, three: 1, four: 0}:(row.one === row.two)?{one: 2, two: 1, three: 1, four: 0}:{one: 1, two: 1, three: 1, four: 0},34 axx0x: (row.four === row.two)?{one: 2, two: 2, three: 0, four: 0}:(row.one === row.two)?{one: 2, two: 1, three: 0, four:0}:{one: 1, two: 1, three: 0, four: 0},35 ax0xx: (row.three === row.four)? {one: 2, two: 0, three: 1, four: 0}:(row.one === row.three)?{one: 2, two: 0, three: 0, four: 0}:{one: 1, two: 0, three: 0, four: 0},36 a00xx: (row.three === row.four)? {one: 0, two: 0, three: 1, four: 0}:{one: 0, two: 0, three: 0, four: 0},37 a0x0x: (row.two === row.four)?{one: 0, two: 2, three: 0, four: 0}:{one: 0, two: 1, three: 0, four: 0},38 a0xx0: (row.two === row.three)? {one: 0, two: 2, three: 1, four: 0}: {one: 0, two: 1, three: 1, four: 0},39 a0xxx: (row.three === row.four)?{one: 0, two: 1, three: 1, four: 0}:(row.two === row.three)?{one: 0, two: 1, three: 0, four: 0}:{one: 0, two: 0, three: 0, four: 0},40 axxxx: ((row.one === row.two) && (row.three === row.four))? {one: 2, two: 1, three: 1, four: 0}:(row.three === row.four)?{one: 1, two: 1, three: 1, four: 0}41 :(row.three === row.two)?{one: 1, two: 1, three: 0, four: 0}:(row.two === row.one)?{one: 1, two: 0, three: 0, four: 0}:{one: 0, two: 0, three: 0, four: 0}}4243 for (let variantKey in variant) {44 if (variant[variantKey]){45 thisAnimeRow=correspondenceObject[variantKey]46 return thisAnimeRow47 }48 }4950 return thisAnimeRow51}52// for result state usability53// вÑ
Ð¾Ð´Ð½Ð°Ñ ÑÑÑока OLD !!!54export let shiftRowGetAnimationTwoPhase = (row) => {5556 let thisAnimeRow = {57 one: 0, two: 0, three: 0, four: 058 }59 let variant= {60 ax000 : ((row.one !== 0) && (row.two === 0) && (row.four === 0) && (row.three === 0)),61 a0000 : ((row.one === 0) && (row.two === 0) && (row.four === 0) && (row.three === 0)),62 a000x : ((row.one === 0) && (row.two === 0) && (row.four !== 0) && (row.three === 0)),63 a0x00 : ((row.two !== 0) && (row.one === 0) && (row.three === 0) && (row.four === 0)),64 axx00 : ((row.one !== 0) && (row.two !== 0) && (row.four === 0) && (row.three === 0)),65 ax00x : ((row.one !== 0) && (row.four !== 0) && (row.two === 0) && (row.three === 0)),66 a00x0 : ((row.three !== 0) && (row.one === 0) && (row.two === 0) && (row.four === 0)),67 ax0x0 : ((row.one !== 0) && (row.two === 0) && (row.three !== 0) && (row.four === 0)),68 axxx0 : ((row.one !== 0) && (row.two !== 0) && (row.three !== 0) && (row.four === 0)),69 axx0x : ((row.one !== 0) && (row.two !== 0) && (row.four !== 0) && (row.three === 0)),70 ax0xx : ((row.one !== 0) && (row.three !== 0) && (row.four !== 0) && (row.two === 0)),71 a00xx : (((row.one === 0) && (row.two === 0) && (row.three !== 0) && (row.four !== 0))),72 a0x0x : ((row.one === 0) && (row.two !== 0) && (row.three === 0) && (row.four !== 0)),73 a0xx0 : ((row.one === 0) && (row.two !== 0) && (row.three !== 0) && (row.four === 0)),74 a0xxx : ((row.one === 0) && (row.two !== 0) && (row.three !== 0) && (row.four !== 0)),75 axxxx : ((row.one !== 0) && (row.two !== 0) && (row.three !== 0) && (row.four !== 0))76 }7778 let correspondenceObject={79 a0000: {one: 0, two: 0, three: 0, four: 0},80 ax000: {one: 0, two: 0, three: 0, four: 0},81 a000x: {one: 0, two: 0, three: 0, four: 0},82 a0x00: {one: 0, two: 0, three: 0, four: 0},83 axx00: (row.one === row.two)?{one: 0, two: 0, three: 0, four: 4}:{one: 0, two: 0, three: 0, four: 0},84 ax00x: (row.one === row.four)?{one: 0, two: 0, three: 0, four: 4}:{one: 0, two: 0, three: 0, four: 0},85 a00x0: {one: 0, two: 0, three: 0, four: 0} ,86 ax0x0: (row.one === row.three)?{one: 0, two: 0, three: 0, four: 4}:{one: 0, two: 0, three: 0, four: 0},87 axxx0: (row.two === row.three)?{one: 0, two: 0, three: 0, four: 4}:(row.one === row.two)?{one: 0, two: 0, three: 4, four: 0}:{one: 0, two: 0, three: 0, four: 0},88 axx0x: (row.four === row.two)?{one: 0, two: 0, three: 0, four: 4}:(row.one === row.two)?{one: 0, two: 0, three: 4, four: 0}:{one: 0, two: 0, three: 0, four: 0},89 ax0xx: (row.three === row.four)? {one: 0, two: 0, three: 0, four: 4}:(row.one === row.three)?{one: 0, two: 0, three: 4, four: 0}:{one: 0, two: 0, three: 0, four: 0},90 a00xx: (row.three === row.four)? {one: 0, two: 0, three: 0, four: 4}:{one: 0, two: 0, three: 0, four: 0},91 a0x0x: (row.two === row.four)?{one: 0, two: 0, three: 0, four: 4}:{one: 0, two: 0, three: 0, four: 0},92 a0xx0: (row.two === row.three)?{one: 0, two: 0, three: 0, four: 4}: {one: 0, two: 0, three: 0, four: 0},93 a0xxx: (row.three === row.four)?{one: 0, two: 0, three: 0, four: 4}:(row.two === row.three)?{one: 0, two: 0, three: 4, four: 0}:{one: 0, two: 0, three: 0, four: 0},94 axxxx: ((row.one === row.two) && (row.three === row.four))?{one: 0, two: 0, three: 4, four: 4}:(row.three === row.four)?{one: 0, two: 0, three: 0, four: 4}95 :(row.three === row.two)?{one: 0, two: 0, three: 4, four: 0}:(row.two === row.one)?{one: 0, two: 4, three: 0, four: 0}:{one: 0, two: 0, three: 0, four: 0}}9697 for (let variantKey in variant) {98 if (variant[variantKey]){99 thisAnimeRow=correspondenceObject[variantKey]100 return thisAnimeRow101 }102 }103104 return thisAnimeRow105}
...
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!!