Best Python code snippet using molecule_python
test_terminalwriter.py
Source:test_terminalwriter.py
...264 assert not tw.hasmarkup265 tw.line("hello", bold=True)266 s = f.getvalue()267 assert s == "hello\n"268def test_should_do_markup(monkeypatch):269 monkeypatch.delenv("PY_COLORS", raising=False)270 monkeypatch.delenv("NO_COLOR", raising=False)271 should_do_markup = terminalwriter.should_do_markup272 f = py.io.TextIO()273 f.isatty = lambda: True274 assert should_do_markup(f) is True275 # NO_COLOR without PY_COLORS.276 monkeypatch.setenv("NO_COLOR", "0")277 assert should_do_markup(f) is False278 monkeypatch.setenv("NO_COLOR", "1")279 assert should_do_markup(f) is False280 monkeypatch.setenv("NO_COLOR", "any")281 assert should_do_markup(f) is False282 # PY_COLORS overrides NO_COLOR ("0" and "1" only).283 monkeypatch.setenv("PY_COLORS", "1")284 assert should_do_markup(f) is True285 monkeypatch.setenv("PY_COLORS", "0")286 assert should_do_markup(f) is False287 # Uses NO_COLOR.288 monkeypatch.setenv("PY_COLORS", "any")289 assert should_do_markup(f) is False290 monkeypatch.delenv("NO_COLOR")291 assert should_do_markup(f) is True292 # Back to defaults.293 monkeypatch.delenv("PY_COLORS")294 assert should_do_markup(f) is True295 f.isatty = lambda: False...
terminalwriter.py
Source:terminalwriter.py
...13 # The Windows get_terminal_size may be bogus, let's sanify a bit.14 if width < 40:15 width = 8016 return width17def should_do_markup(file: TextIO) -> bool:18 if os.environ.get("PY_COLORS") == "1":19 return True20 if os.environ.get("PY_COLORS") == "0":21 return False22 if "NO_COLOR" in os.environ:23 return False24 if "FORCE_COLOR" in os.environ:25 return True26 return (27 hasattr(file, "isatty") and file.isatty() and os.environ.get("TERM") != "dumb"28 )29@final30class TerminalWriter:31 _esctable = dict(32 black=30,33 red=31,34 green=32,35 yellow=33,36 blue=34,37 purple=35,38 cyan=36,39 white=37,40 Black=40,41 Red=41,42 Green=42,43 Yellow=43,44 Blue=44,45 Purple=45,46 Cyan=46,47 White=47,48 bold=1,49 light=2,50 blink=5,51 invert=7,52 )53 def __init__(self, file: Optional[TextIO] = None) -> None:54 if file is None:55 file = sys.stdout56 if hasattr(file, "isatty") and file.isatty() and sys.platform == "win32":57 try:58 import colorama59 except ImportError:60 pass61 else:62 file = colorama.AnsiToWin32(file).stream63 assert file is not None64 self._file = file65 self.hasmarkup = should_do_markup(file)66 self._current_line = ""67 self._terminal_width: Optional[int] = None68 self.code_highlight = True69 @property70 def fullwidth(self) -> int:71 if self._terminal_width is not None:72 return self._terminal_width73 return get_terminal_width()74 @fullwidth.setter75 def fullwidth(self, value: int) -> None:76 self._terminal_width = value77 @property78 def width_of_current_line(self) -> int:79 """Return an estimate of the width so far in the current line."""...
test_logger.py
Source:test_logger.py
...83 x = '{}{}{}'.format(colorama.Fore.CYAN, 'foo', colorama.Style.RESET_ALL)84 assert x == logger.cyan_text('foo')85def test_markup_detection_pycolors0(monkeypatch):86 monkeypatch.setenv('PY_COLORS', '0')87 assert not logger.should_do_markup()88def test_markup_detection_pycolors1(monkeypatch):89 monkeypatch.setenv('PY_COLORS', '1')90 assert logger.should_do_markup()91def test_markup_detection_tty_yes(mocker):92 mocker.patch('sys.stdout.isatty', return_value=True)93 mocker.patch('os.environ', {'TERM': 'xterm'})94 assert logger.should_do_markup()95 mocker.resetall()96 mocker.stopall()97def test_markup_detection_tty_no(mocker):98 mocker.patch('os.environ', {})99 mocker.patch('sys.stdout.isatty', return_value=False)100 assert not logger.should_do_markup()101 mocker.resetall()...
shell.py
Source:shell.py
...25from molecule import command26from molecule.config import MOLECULE_DEBUG27from molecule.logger import should_do_markup28click_completion.init()29colorama.init(autoreset=True, strip=not should_do_markup())30LOCAL_CONFIG = os.path.expanduser('~/.config/molecule/config.yml')31ENV_FILE = '.env.yml'32@click.group()33@click.option(34 '--debug/--no-debug',35 default=MOLECULE_DEBUG,36 help='Enable or disable debug mode. Default is disabled.')37@click.option(38 '--base-config',39 '-c',40 default=LOCAL_CONFIG,41 help=('Path to a base config. If provided Molecule will load '42 "this config first, and deep merge each scenario's "43 'molecule.yml on top. ({})').format(LOCAL_CONFIG))...
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!!