How to use test_formatting method in Slash

Best Python code snippet using slash

fixtures.py

Source:fixtures.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import division3from __future__ import print_function4from __future__ import absolute_import5from __future__ import unicode_literals6import pretty_traceback.common as com7BASIC_TRACEBACK_STR = """8Traceback (most recent call last):9 File "/home/user/venvs/py38/bin/myproject", line 12, in <module>10 sys.exit(cli())11 File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 829, in __call__12 return self.main(*args, **kwargs)13 File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 782, in main14 rv = self.invoke(ctx)15 File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 1259, in invoke16 return _process_result(sub_ctx.command.invoke(sub_ctx))17 File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 1066, in invoke18 return ctx.invoke(self.callback, **ctx.params)19 File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 610, in invoke20 return callback(*args, **kwargs)21 File "/home/user/foss/myproject/src/myproject/cli.py", line 148, in build22 lp_gen_docs.gen_html(built_ctx, html_dir)23 File "/home/user/foss/myproject/src/myproject/gen_docs.py", line 295, in gen_html24 wrapped_html = wrap_content_html(content_html, 'screen', meta, toc)25 File "/home/user/foss/myproject/src/myproject/gen_docs.py", line 238, in wrap_content_html26 result = tmpl.render(**ctx)27 File "/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render28 self.environment.handle_exception()29 File "/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exce30 reraise(*rewrite_traceback_stack(source=source))31 File "/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise32 raise value.with_traceback(tb)33 File "<template>", line 56, in top-level template code34TypeError: no loader for this environment specified35"""36BASIC_TRACEBACK_ENTRIES = [37 com.Entry(38 module="/home/user/venvs/py38/bin/myproject",39 call="<module>",40 lineno="12",41 src_ctx="sys.exit(cli())",42 ),43 com.Entry(44 module="/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py",45 call="__call__",46 lineno="829",47 src_ctx="return self.main(*args, **kwargs)",48 ),49 com.Entry(50 module="/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py",51 call="main",52 lineno="782",53 src_ctx="rv = self.invoke(ctx)",54 ),55 com.Entry(56 module="/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py",57 call="invoke",58 lineno="1259",59 src_ctx="return _process_result(sub_ctx.command.invoke(sub_ctx))",60 ),61 com.Entry(62 module="/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py",63 call="invoke",64 lineno="1066",65 src_ctx="return ctx.invoke(self.callback, **ctx.params)",66 ),67 com.Entry(68 module="/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py",69 call="invoke",70 lineno="610",71 src_ctx="return callback(*args, **kwargs)",72 ),73 com.Entry(74 module="/home/user/foss/myproject/src/myproject/cli.py",75 call="build",76 lineno="148",77 src_ctx="lp_gen_docs.gen_html(built_ctx, html_dir)",78 ),79 com.Entry(80 module="/home/user/foss/myproject/src/myproject/gen_docs.py",81 call="gen_html",82 lineno="295",83 src_ctx="wrapped_html = wrap_content_html(content_html, 'screen', meta, toc)",84 ),85 com.Entry(86 module="/home/user/foss/myproject/src/myproject/gen_docs.py",87 call="wrap_content_html",88 lineno="238",89 src_ctx="result = tmpl.render(**ctx)",90 ),91 com.Entry(92 module="/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/environment.py",93 call="render",94 lineno="1090",95 src_ctx="self.environment.handle_exception()",96 ),97 com.Entry(98 module="/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/environment.py",99 call="handle_exce",100 lineno="832",101 src_ctx="reraise(*rewrite_traceback_stack(source=source))",102 ),103 com.Entry(104 module="/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/_compat.py",105 call="reraise",106 lineno="28",107 src_ctx="raise value.with_traceback(tb)",108 ),109 com.Entry(110 module="<template>",111 call="top-level template code",112 lineno="56",113 src_ctx="",114 ),115]116BASIC_TRACEBACK = com.Traceback(117 exc_name="TypeError",118 exc_msg="no loader for this environment specified",119 entries=BASIC_TRACEBACK_ENTRIES,120 is_caused=False,121 is_context=False,122)123COMPRESSABLE_TRACEBACK_STR = """124Traceback (most recent call last):125 File "/home/user/venv/lib/python2.7/runpy.py", line 174, in _run_module_as_main126 "__main__", fname, loader, pkg_name)127 File "/home/user/venv/lib/python2.7/runpy.py", line 72, in _run_code128 exec code in run_globals129 File "/home/user/project/serve.py", line 19, in <module>130 import lib.http_util as http131 File "/home/user/venv/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__132 result = _import(*args, **kwargs)133 File "/home/user/project/lib/http_util.py", line 27, in <module>134 import api.plugins135 File "/home/user/venv/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__136 result = _import(*args, **kwargs)137 File "/home/user/project/api/plugins/__init__.py", line 21, in <module>138 from api.query import iter_doc_metrics139 File "/home/user/venv/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__140 result = _import(*args, **kwargs)141 File "/home/user/project/api/query.py", line 25, in <module>142 import submodule143 File "/home/user/venv/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__144 result = _import(*args, **kwargs)145 File "/home/user/project/submodule/__init__.py", line 7, in <module>146 import submodule.cell_calc as cell_calc # noqa147 File "/home/user/venv/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__148 result = _import(*args, **kwargs)149 File "/home/user/project/submodule/cell_calc.py", line 17, in <module>150 import submodule.constants as const151 File "/home/user/venv/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__152 result = _import(*args, **kwargs)153 File "/home/user/project/submodule/constants.py", line 23, in <module>154 for preview_id, preview_cfg in cfg.__init__.BASE_CONFIG.val['preview_config'].items()155 File "/home/user/src/project-common/project_common/lib.py", line 102, in val156 return self.fresh_val157 File "/home/user/src/project-common/project_common/lib.py", line 77, in fresh_val158 self._res = self._process_func(_res)159 File "/home/user/project/cfg/__init__.py", line 1844, in _parse_base_config160 _update_dimension_defs(base_cfg)161 File "/home/user/project/cfg/__init__.py", line 476, in _update_dimension_defs162 _parse_dimension_formula(dim_def, all_dim_ids)163 File "/home/user/project/cfg/__init__.py", line 427, in _parse_dimension_formula164 assert hasattr(api.plugins.common, parse_fn_name), msg165AttributeError: 'module' object has no attribute 'plugins'166"""167CHAINED_TRACEBACK_STR = """168Traceback (most recent call last):169 File "./test/test_formatting.py", line 30, in _ping170 sp.check_output(['command_that', 'doesnt', 'exist'])171 File "/home/user/envs/py38/lib/python3.8/subprocess.py", line 411, in check_output172 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,173 File "/home/user/envs/py38/lib/python3.8/subprocess.py", line 489, in run174 with Popen(*popenargs, **kwargs) as process:175 File "/home/user/envs/py38/lib/python3.8/subprocess.py", line 854, in __init__176 self._execute_child(args, executable, preexec_fn, close_fds,177 File "/home/user/envs/py38/lib/python3.8/subprocess.py", line 1702, in _execute_child178 raise child_exception_type(errno_num, err_msg, err_filename)179FileNotFoundError: [Errno 2] No such file or directory: 'command_that'180During handling of the above exception, another exception occurred:181Traceback (most recent call last):182 File "/home/user/project/test/test_formatting.py", line 35, in _ping183 raise AttributeError()184AttributeError185The above exception was the direct cause of the following exception:186Traceback (most recent call last):187 File "/home/user/project/test/test_formatting.py", line 70, in <module>188 run_pingpong()189 File "/home/user/project/test/test_formatting.py", line 56, in run_pingpong190 sched3.run()191 File "/home/user/envs/py38/lib/python3.8/sched.py", line 151, in run192 action(*argument, **kwargs)193 File "/home/user/envs/py38/lib/python3.8/sched.py", line 151, in run194 action(*argument, **kwargs)195 File "/home/user/envs/py38/lib/python3.8/sched.py", line 151, in run196 action(*argument, **kwargs)197 File "/home/user/project/test/test_formatting.py", line 46, in _ping198 _pong(depth + 1)199 File "/home/user/project/test/test_formatting.py", line 24, in _pong200 _ping(depth + 1)201 File "/home/user/project/test/test_formatting.py", line 42, in _ping202 raise new_ex203 File "/home/user/project/test/test_formatting.py", line 33, in _ping204 raise AttributeError()205KeyError: Wrapping KeyError206"""207CHAINED_TRACEBACK_ENTRIES_0 = [208 com.Entry(209 module="./test/test_formatting.py",210 call="_ping",211 lineno="30",212 src_ctx="sp.check_output(['command_that', 'doesnt', 'exist'])",213 ),214 com.Entry(215 module="/home/user/envs/py38/lib/python3.8/subprocess.py",216 call="check_output",217 lineno="411",218 src_ctx="return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,",219 ),220 com.Entry(221 module="/home/user/envs/py38/lib/python3.8/subprocess.py",222 call="run",223 lineno="489",224 src_ctx="with Popen(*popenargs, **kwargs) as process:",225 ),226 com.Entry(227 module="/home/user/envs/py38/lib/python3.8/subprocess.py",228 call="__init__",229 lineno="854",230 src_ctx="self._execute_child(args, executable, preexec_fn, close_fds,",231 ),232 com.Entry(233 module="/home/user/envs/py38/lib/python3.8/subprocess.py",234 call="_execute_child",235 lineno="1702",236 src_ctx="raise child_exception_type(errno_num, err_msg, err_filename)",237 ),238]239CHAINED_TRACEBACK_ENTRIES_1 = [240 com.Entry(241 module="/home/user/project/test/test_formatting.py",242 call="_ping",243 lineno="35",244 src_ctx="raise AttributeError()",245 ),246]247CHAINED_TRACEBACK_ENTRIES_2 = [248 com.Entry(249 module="/home/user/project/test/test_formatting.py",250 call="<module>",251 lineno="70",252 src_ctx="run_pingpong()",253 ),254 com.Entry(255 module="/home/user/project/test/test_formatting.py",256 call="run_pingpong",257 lineno="56",258 src_ctx="sched3.run()",259 ),260 com.Entry(261 module="/home/user/envs/py38/lib/python3.8/sched.py",262 call="run",263 lineno="151",264 src_ctx="action(*argument, **kwargs)",265 ),266 com.Entry(267 module="/home/user/envs/py38/lib/python3.8/sched.py",268 call="run",269 lineno="151",270 src_ctx="action(*argument, **kwargs)",271 ),272 com.Entry(273 module="/home/user/envs/py38/lib/python3.8/sched.py",274 call="run",275 lineno="151",276 src_ctx="action(*argument, **kwargs)",277 ),278 com.Entry(279 module="/home/user/project/test/test_formatting.py",280 call="_ping",281 lineno="46",282 src_ctx="_pong(depth + 1)",283 ),284 com.Entry(285 module="/home/user/project/test/test_formatting.py",286 call="_pong",287 lineno="24",288 src_ctx="_ping(depth + 1)",289 ),290 com.Entry(291 module="/home/user/project/test/test_formatting.py",292 call="_ping",293 lineno="42",294 src_ctx="raise new_ex",295 ),296 com.Entry(297 module="/home/user/project/test/test_formatting.py",298 call="_ping",299 lineno="33",300 src_ctx="raise AttributeError()",301 ),302]303CHAINED_TRACEBACK = [304 com.Traceback(305 exc_name="FileNotFoundError",306 exc_msg="[Errno 2] No such file or directory: 'command_that'",307 entries=CHAINED_TRACEBACK_ENTRIES_0,308 is_caused=False,309 is_context=False,310 ),311 com.Traceback(312 exc_name="AttributeError",313 exc_msg="",314 entries=CHAINED_TRACEBACK_ENTRIES_1,315 is_caused=False,316 is_context=True,317 ),318 com.Traceback(319 exc_name="KeyError",320 exc_msg="Wrapping KeyError",321 entries=CHAINED_TRACEBACK_ENTRIES_2,322 is_caused=True,323 is_context=False,324 ),325]326ALL_TRACEBACK_STRS = [327 BASIC_TRACEBACK_STR,328 COMPRESSABLE_TRACEBACK_STR,329 CHAINED_TRACEBACK_STR,...

Full Screen

Full Screen

test_formatting.py

Source:test_formatting.py Github

copy

Full Screen

1import re2import pytest3from loguru import logger4@pytest.mark.parametrize(5 "format, validator",6 [7 ("{name}", lambda r: r == "tests.test_formatting"),8 ("{time}", lambda r: re.fullmatch(r"\d+-\d+-\d+T\d+:\d+:\d+[.,]\d+[+-]\d{4}", r)),9 ("{elapsed}", lambda r: re.fullmatch(r"\d:\d{2}:\d{2}\.\d{6}", r)),10 ("{elapsed.seconds}", lambda r: re.fullmatch(r"\d+", r)),11 ("{line}", lambda r: re.fullmatch(r"\d+", r)),12 ("{level}", lambda r: r == "DEBUG"),13 ("{level.name}", lambda r: r == "DEBUG"),14 ("{level.no}", lambda r: r == "10"),15 ("{level.icon}", lambda r: r == "🐞"),16 ("{file}", lambda r: r == "test_formatting.py"),17 ("{file.name}", lambda r: r == "test_formatting.py"),18 ("{file.path}", lambda r: r == __file__),19 ("{function}", lambda r: r == "test_log_formatters"),20 ("{module}", lambda r: r == "test_formatting"),21 ("{thread}", lambda r: re.fullmatch(r"\d+", r)),22 ("{thread.id}", lambda r: re.fullmatch(r"\d+", r)),23 ("{thread.name}", lambda r: isinstance(r, str) and r != ""),24 ("{process}", lambda r: re.fullmatch(r"\d+", r)),25 ("{process.id}", lambda r: re.fullmatch(r"\d+", r)),26 ("{process.name}", lambda r: isinstance(r, str) and r != ""),27 ("{message}", lambda r: r == "Message"),28 ("%s {{a}} 天 {{1}} %d", lambda r: r == "%s {a} 天 {1} %d"),29 ],30)31@pytest.mark.parametrize("use_log_function", [False, True])32def test_log_formatters(format, validator, writer, use_log_function):33 message = "Message"34 logger.add(writer, format=format)35 if use_log_function:36 logger.log("DEBUG", message)37 else:38 logger.debug(message)39 result = writer.read().rstrip("\n")40 assert validator(result)41@pytest.mark.parametrize(42 "format, validator",43 [44 ("{time}.log", lambda r: re.fullmatch(r"\d+-\d+-\d+_\d+-\d+-\d+\_\d+.log", r)),45 ("%s_{{a}}_天_{{1}}_%d", lambda r: r == "%s_{a}_天_{1}_%d"),46 ],47)48@pytest.mark.parametrize("part", ["file", "dir", "both"])49def test_file_formatters(tmpdir, format, validator, part):50 if part == "file":51 file = tmpdir.join(format)52 elif part == "dir":53 file = tmpdir.join(format, "log.log")54 elif part == "both":55 file = tmpdir.join(format, format)56 logger.add(str(file))57 logger.debug("Message")58 files = [f for f in tmpdir.visit() if f.check(file=1)]59 assert len(files) == 160 file = files[0]61 if part == "file":62 assert validator(file.basename)63 elif part == "dir":64 assert file.basename == "log.log"65 assert validator(file.dirpath().basename)66 elif part == "both":67 assert validator(file.basename)68 assert validator(file.dirpath().basename)69@pytest.mark.parametrize(70 "message, args, kwargs, expected",71 [72 ("{1, 2, 3} - {0} - {", [], {}, "{1, 2, 3} - {0} - {"),73 ("{} + {} = {}", [1, 2, 3], {}, "1 + 2 = 3"),74 ("{a} + {b} = {c}", [], dict(a=1, b=2, c=3), "1 + 2 = 3"),75 ("{0} + {two} = {1}", [1, 3], dict(two=2, nope=4), "1 + 2 = 3"),76 (77 "{self} or {message} or {level}",78 [],79 dict(self="a", message="b", level="c"),80 "a or b or c",81 ),82 ("{:.2f}", [1], {}, "1.00"),83 ("{0:0{three}d}", [5], dict(three=3), "005"),84 ("{{nope}} {my_dict} {}", ["{{!}}"], dict(my_dict={"a": 1}), "{nope} {'a': 1} {{!}}"),85 ],86)87@pytest.mark.parametrize("use_log_function", [False, True])88def test_log_formatting(writer, message, args, kwargs, expected, use_log_function):89 logger.add(writer, format="{message}", colorize=False)90 if use_log_function:91 logger.log(10, message, *args, **kwargs)92 else:93 logger.debug(message, *args, **kwargs)94 assert writer.read() == expected + "\n"95def test_f_globals_name_absent(writer, f_globals_name_absent):96 logger.add(writer, format="{name} {message}", colorize=False)97 logger.info("Foobar")98 assert writer.read() == "None Foobar\n"99def test_extra_formatting(writer):100 logger.configure(extra={"test": "my_test", "dict": {"a": 10}})101 logger.add(writer, format="{extra[test]} -> {extra[dict]} -> {message}")102 logger.debug("level: {name}", name="DEBUG")103 assert writer.read() == "my_test -> {'a': 10} -> level: DEBUG\n"104def test_invalid_color_markup(writer):105 with pytest.raises(ValueError):...

Full Screen

Full Screen

task_validate.py

Source:task_validate.py Github

copy

Full Screen

1import credentials2import os3import m4.tasks4from webtask.common import run_task5def main():6 with m4.tasks.ctx():7 gitpath = os.path.join(credentials.GIT_THEMING_PATH_M4, "notes")8 run_task("updaterepo")9 import webtask.test_formatting10 webtask.test_formatting.NOTESPATH = gitpath11 webtask.test_formatting.main()12 import webtask.test_integrity13 webtask.test_integrity.NOTESPATH = gitpath...

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