Skip to content

Commit e8ca5b2

Browse files
committed
Add process_options to options tsting
1 parent 4baa566 commit e8ca5b2

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@ per-file-ignores =
7171
# Ignore undefined name errors in "expectation" test Python code.
7272
# These files get exec'd in an environment that defines the variables.
7373
server/tests/files/expectations/*.py:F821
74+
75+
[tool.pylsp-mypy]
76+
enabled = true
77+
live_mode = true
78+
exclude = ["trepan/version.py", "tests/*"]

test/unit/test_options.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
"""Unit test for trepan.options"""
22

3-
from trepan.options import process_options
3+
from test.unit.cmdhelper import setup_unit_test_debugger
4+
5+
from trepan.options import postprocess_options, process_options
46

57

68
def test_options():
9+
"""
10+
Test trepan.options.process_options() and trepan.options.postprocess.
11+
"""
12+
13+
# Setup.
714
option_key_set = {
815
"annotate",
916
"basename",
@@ -30,19 +37,30 @@ def test_options():
3037
"style",
3138
"target",
3239
}
40+
dbg, _ = setup_unit_test_debugger()
3341
dbg_opts_set = {"proc_opts", "from_ipython"}
3442

43+
# Test with no options. See that we have the some expected
44+
# keys getting set.
3545
opts, dbg_opts, sys_argv = process_options("1.0", [__file__])
3646
diff_set = option_key_set - set(vars(opts).keys())
3747
assert diff_set == set(), "expecting at least these options keys set"
3848
assert (
3949
dbg_opts_set - set(dbg_opts.keys())
4050
) == set(), "expecting at least these processor keys set"
4151

52+
# Try with more than one option, a boolean option and a string option.
4253
arg_str = f"{__file__} --fntrace --cd=/tmp"
4354
opts, dbg_opts, sys_argv = process_options("1.1", arg_str.split())
4455
assert opts.cd == "/tmp"
56+
postprocess_options(dbg, opts)
57+
assert dbg.settings["printset"] == frozenset(
58+
["c_call", "c_return", "call", "return"]
59+
)
4560

46-
arg_str = f"{__file__} --style=emacs"
47-
opts, dbg_opts, sys_argv = process_options("1.2", arg_str.split())
48-
assert opts.style == "emacs"
61+
# Try with an invalid style option and see that it is
62+
# rejected in postprocess option
63+
arg_str = f"{__file__} --style=fafdsaXYZZY"
64+
opts, dbg_opts, sys_argv = process_options("1.3", arg_str.split())
65+
postprocess_options(dbg, opts)
66+
assert dbg.settings["style"] is None

trepan/options.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import sys
2121
from optparse import OptionParser
2222

23+
from pygments.styles import STYLE_MAP
24+
2325
import trepan.api
2426
from trepan.api import debugger_on_post_mortem
2527
from trepan.clifns import path_expanduser_abs
@@ -380,10 +382,16 @@ def postprocess_options(dbg, opts):
380382
else:
381383
dbg.settings["highlight"] = "plain"
382384

385+
dbg.settings["style"] = None
383386
if getattr(opts, "style") and opts.style != "none":
384-
dbg.settings["style"] = opts.style
385-
else:
386-
dbg.settings["style"] = None
387+
style_names = sorted(list(STYLE_MAP.keys()))
388+
if opts.style in style_names:
389+
dbg.settings["style"] = opts.style
390+
else:
391+
sys.stderr.write(
392+
f"""Pygments style "{opts.style}" listed. --style option ignored.\n"""
393+
f"""Use 'set style" to see valid style and change style.\n"""
394+
)
387395

388396
# Normally we want to set trepan.api.debugger_obj so that one can
389397
# put trepan.debugger breakpoints in a program and not have more

0 commit comments

Comments
 (0)