How to use _format_dict method in tempest

Best Python code snippet using tempest_python

test_formats.py

Source:test_formats.py Github

copy

Full Screen

...11class TestFormatDict(unittest.TestCase):12 def test_dict_simple(self):13 from outlib.lib.format_vals import _format_dict14 input_val = {'a': 'b'}15 output = _format_dict(input_val)16 17 assert output['a'] == 'b'18 def test_dict_int_value(self):19 from outlib.lib.format_vals import _format_dict20 input_val = {'a': 1}21 output = _format_dict(input_val)22 23 assert output['a'] == 124 def test_dict_dict_value(self):25 from outlib.lib.format_vals import _format_dict26 input_val = {'a': {'b': 'c'}}27 output = _format_dict(input_val)28 29 assert output['a']['b'] == 'c'30 def test_dict_list_value(self):31 from outlib.lib.format_vals import _format_dict32 input_val = {'a': ['b', 'c']}33 output = _format_dict(input_val)34 35 assert output['a'][0] == 'b'36 def test_dict_object_value(self):37 from outlib.lib.format_vals import _format_dict38 input_val = {'a': TObject(test1='value1')}39 output = _format_dict(input_val)40 41 assert output['a']['test1'] == 'value1'42 def test_dict_row_proxy_value(self):43 from outlib.lib.format_vals import _format_dict44 input_val = {'a': RowProxy(test1='value2')}45 output = _format_dict(input_val)46 47 assert output['a']['test1'] == 'value2'48class TestFormatList(unittest.TestCase):49 def test_list_simple(self):50 from outlib.lib.format_vals import _format_list51 input_val = ['a', 'b']52 output = _format_list(input_val)53 54 assert output[1] == 'b'55 def test_list_int_value(self):56 from outlib.lib.format_vals import _format_list57 input_val = ['a', 1]58 output = _format_list(input_val)59 ...

Full Screen

Full Screen

c6_python_trick.py

Source:c6_python_trick.py Github

copy

Full Screen

...43 def _format_list(k, v):44 if all(isinstance(_, dict) for _ in v):45 v_str = '[\n'46 v_str += '\n'.join(47 f'dict({_format_dict(v_)}),'48 for v_ in v).rstrip(',')49 attr_str = f'{str(k)}={v_str}'50 attr_str = attr_str + ']'51 else:52 attr_str = _format_basic_types(k, v)53 return attr_str54 def _format_dict(input_dict, outest_level=False):55 r = ''56 s = []57 for idx, (k, v) in enumerate(input_dict.items()):58 end = '' if outest_level else ',' # 需要符合pep8格式59 if isinstance(v, dict):60 v_str = '\n' + _format_dict(v) # 递归调用61 attr_str = f'{str(k)}=dict({v_str}'62 attr_str = attr_str + ')' + end63 elif isinstance(v, list):64 attr_str = _format_list(k, v) + end65 else:66 attr_str = _format_basic_types(k, v) + end67 s.append(attr_str)68 r += '\n'.join(s)69 return r70 # outest_level 最外层71 # 仅仅需要把dict按照行排列切割好就行,后面的每行如何格式化采用pep8标准自动执行72 text = _format_dict(src_dict, outest_level=True)73 # 借助yapf库实现的pep8格式化字符串功能实现74 yapf_style = dict(75 based_on_style='pep8',76 blank_line_before_nested_class_or_def=True,77 split_before_expression_after_opening_paren=True)78 text, _ = FormatCode(text, style_config=yapf_style, verify=True)...

Full Screen

Full Screen

requestlog.py

Source:requestlog.py Github

copy

Full Screen

1# coding: utf-82from logging import getLogger, LoggerAdapter3def _format_dict(var, tabindent=1):4 # Do nothing if received non-dict5 if not isinstance(var, dict):6 return var7 dict_ = var # Just a better name8 keys = sorted(dict_.keys())9 lines = ['{']10 for k in keys:11 line = "%s%s: %s," % ('\t' * tabindent, repr(k), repr(dict_[k]))12 lines.append(line)13 lines.append('%s},' % ('\t' * (tabindent - 1)))14 return '\n'.join(lines)15def getRequestLogger(name):16 """Returns a logger aware of HttpRequest attributes"""17 return RequestLoggerAdapter(getLogger(name), {})18class RequestLoggerAdapter(LoggerAdapter):19 message = u'\n\t%(method)s %(path)s\n\tHEADERS: %(META)s\n\tDATA: %(POST)s\n\tCOOKIES: %(COOKIES)s'20 def _requestProperties(self, request):21 properties = {22 u'POST' : _format_dict(request.POST, 2),23 u'COOKIES': _format_dict(request.COOKIES, 2),24 u'META' : _format_dict(request.META, 2),25 u'method' : request.method,26 u'path' : request.path,27 }28 return properties29 def process(self, msg, kwargs):30 request = kwargs.pop('request', {})31 if request:32 params = self._requestProperties(request)33 msg += self.message % params...

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