Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_config_pygments(monkeypatch):
import pygments.formatters
assert not hasattr(DefaultConfig, "use_terminal256formatter")
p = Pdb(Config=DefaultConfig)
monkeypatch.delenv("TERM", raising=False)
assert isinstance(
p._get_pygments_formatter(), pygments.formatters.TerminalFormatter
)
monkeypatch.setenv("TERM", "xterm-256color")
assert isinstance(
p._get_pygments_formatter(), pygments.formatters.Terminal256Formatter
)
monkeypatch.setenv("TERM", "xterm-kitty")
assert isinstance(
p._get_pygments_formatter(), pygments.formatters.TerminalTrueColorFormatter
)
monkeypatch.setenv("TERM", "xterm-256color")
assert isinstance(
p._get_pygments_formatter(), pygments.formatters.Terminal256Formatter
)
monkeypatch.setenv("TERM", "xterm-kitty")
assert isinstance(
p._get_pygments_formatter(), pygments.formatters.TerminalTrueColorFormatter
)
class Config(DefaultConfig):
formatter = object()
assert Pdb(Config=Config)._get_pygments_formatter() is Config.formatter
class Config(DefaultConfig):
pygments_formatter_class = "pygments.formatters.TerminalTrueColorFormatter"
assert isinstance(
Pdb(Config=Config)._get_pygments_formatter(),
pygments.formatters.TerminalTrueColorFormatter
)
source = Pdb(Config=Config).format_source("print(42)")
assert source.startswith("\x1b[38;2;0;128;")
assert "print\x1b[39" in source
assert source.endswith("m42\x1b[39m)\n")
class FakeStdin:
def __init__(self, lines):
self.lines = iter(lines)
def readline(self):
try:
line = next(self.lines) + '\n'
sys.stdout.write(line)
return line
except StopIteration:
return ''
class ConfigTest(DefaultConfig):
highlight = False
use_pygments = False
prompt = '# ' # because + has a special meaning in the regexp
editor = 'emacs'
stdin_paste = 'epaste'
disable_pytest_capturing = False
current_line_color = 44
class ConfigWithHighlight(ConfigTest):
highlight = True
class ConfigWithPygments(ConfigTest):
use_pygments = True