Skip to content

Commit

Permalink
Reinstate integration tests ...
Browse files Browse the repository at this point in the history
respect "highlight=plain" on list command
  • Loading branch information
rocky committed Sep 15, 2024
1 parent 3f0042d commit e715db7
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 166 deletions.
19 changes: 4 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,19 @@ flake8:

#: Run all tests: unit, functional and integration verbosely
# check: test-unit test-functional test-integration # flake8
check: test-unit test-functional
check: test-unit test-functional test-integration

#: Run unit (transparent-box) tests
test-unit:
$(PYTHON) -m pytest test/unit

#: Run functional tests
check-functional test-functional:
(cd test/functional && $(PYTHON) -m pytest .)

#: Run functional tests
test-functional-short:
@echo "Function needs fixup after highlight work"
# (cd test/functional && $(PYTHON) ./setup.py nosetests) | \
# $(PYTHON) ./make-check-filter.py
test-functional check-functional:
$(PYTHON) -m pytest test/functional

#: Run integration (black-box) tests
test-integration:
(cd test/integration && $(PYTHON) ./setup.py nosetests)

#: Run integration (black-box) tests
test-integration-short:
(cd test/integration && $(PYTHON) ./setup.py nosetests) | \
$(PYTHON) ./make-check-filter.py
$(PYTHON) -m pytest test/integration

#: Clean up temporary files
clean:
Expand Down
16 changes: 0 additions & 16 deletions test/functional/Makefile

This file was deleted.

25 changes: 0 additions & 25 deletions test/integration/Makefile

This file was deleted.

73 changes: 45 additions & 28 deletions test/integration/helper.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from xdis import IS_PYPY
import difflib, os, re, sys, time
import difflib
import os
import os.path as osp
import re
import sys
import time

from xdis import IS_PYPY

srcdir = osp.abspath(osp.dirname(__file__))


def run_debugger(testname, python_file, dbgr_opts='', args='',
outfile=None, right_template=None):
datadir = osp.join(srcdir, '..', 'data')
progdir = osp.join(srcdir, '..', 'example')
dbgrdir = osp.join(srcdir, '..', '..', 'trepan')
dbgr_short= "__main__.py"
def run_debugger(
testname, python_file, dbgr_opts="", args="", outfile=None, right_template=None
):
datadir = osp.join(srcdir, "..", "data")
progdir = osp.join(srcdir, "..", "example")
dbgrdir = osp.join(srcdir, "..", "..", "trepan")
dbgr_short = "__main__.py"
dbgr_path = osp.join(dbgrdir, dbgr_short)

if not right_template:
Expand All @@ -20,43 +27,53 @@ def run_debugger(testname, python_file, dbgr_opts='', args='',

rightfile = osp.join(datadir, right_template % testname)

sys.path.insert(0, osp.join(srcdir, '..', '..'))
os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
cmdfile = osp.join(datadir, "%s.cmd" % testname)
outfile = osp.join(srcdir, "%s.out" % testname)
sys.path.insert(0, osp.join(srcdir, "..", ".."))
os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
cmdfile = osp.join(datadir, f"{testname}.cmd")
outfile = osp.join(srcdir, f"{testname}.out")
if python_file:
programfile = osp.join(progdir, python_file)
else:
programfile = ''
programfile = ""
pass

outfile_opt = '--output=%s ' % outfile
outfile_opt = f"--output={outfile} "

if osp.exists(outfile): os.unlink(outfile)
if osp.exists(outfile):
os.unlink(outfile)

cmd = "%s --command %s %s %s %s %s" % \
(dbgr_path, cmdfile, outfile_opt, dbgr_opts, programfile, args)
cmd = "%s --command %s %s %s %s %s" % (
dbgr_path,
cmdfile,
outfile_opt,
dbgr_opts,
programfile,
args,
)

# print(cmd)
print(cmd)
os.system(cmd)
fromfile = rightfile
fromdate = time.ctime(os.stat(fromfile).st_mtime)
tofile = outfile
todate = time.ctime(os.stat(tofile).st_mtime)
with open(fromfile) as f: fromlines = f.readlines()
with open(tofile) as f: tolines = f.readlines()
fromfile = rightfile
fromdate = time.ctime(os.stat(fromfile).st_mtime)
tofile = outfile
todate = time.ctime(os.stat(tofile).st_mtime)
with open(fromfile) as f:
fromlines = f.readlines()
with open(tofile) as f:
tolines = f.readlines()

# Filter out last instruction. For example:
# (gcd.py:11 @6): -> (gcd.py:11)
tolines = [re.sub(' @\d+\):', '):', line) for line in tolines]
tolines = [re.sub(" @\d+\):", "):", line) for line in tolines]

diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
tofile, fromdate, todate))
diff = list(
difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate)
)
if len(diff) == 0:
os.unlink(outfile)
pass
else:
with open(tofile, 'w') as out:
with open(tofile, "w") as out:
out.writelines(tolines)
pass
pass
Expand Down
29 changes: 0 additions & 29 deletions test/integration/test-general.py

This file was deleted.

29 changes: 0 additions & 29 deletions test/integration/test-highlight.py

This file was deleted.

20 changes: 0 additions & 20 deletions test/integration/test-noscript.py

This file was deleted.

23 changes: 23 additions & 0 deletions test/integration/test_highlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"General integration tests"

from helper import run_debugger
from xdis import PYTHON_VERSION_TRIPLE


def test_highlight():
"""Test set/show highlight"""
if PYTHON_VERSION_TRIPLE >= (3, 8):
right_template = "%s-38.right"
else:
right_template = None
result = run_debugger(
testname="highlight",
dbgr_opts="--basename " + "--highlight=plain --nx",
python_file="gcd.py",
right_template=right_template,
)
assert result, "'highlight' command comparision"
return


pass
9 changes: 9 additions & 0 deletions test/integration/test_noscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"Integration test of invoking debugger without a file name"
from helper import run_debugger


def test_basic():
"""Test invoking debugger without a file name"""
result = run_debugger(testname="noscript", dbgr_opts="--basename", python_file=None)
assert result, "debugger 'step' command comparision"
return
20 changes: 20 additions & 0 deletions test/integration/test_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"Step integration tests"

from helper import run_debugger
from xdis import PYTHON_VERSION_TRIPLE


def test_step():
"""Test stepping, set skip, set trace"""
if PYTHON_VERSION_TRIPLE >= (3, 8):
right_template = "%s-38.right"
else:
right_template = None
result = run_debugger(
testname="step",
dbgr_opts="--basename --highlight=plain",
python_file="gcd.py",
right_template=right_template,
)
assert result, "debugger 'step' command comparision"
return
11 changes: 7 additions & 4 deletions trepan/processor/command/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import linecache
import os.path as osp
import sys
from trepan.processor.cmd_addrlist import INVALID_PARSE_LIST

import pyficache

# Our local modules
from pygments.console import colorize

from trepan.processor.cmd_addrlist import INVALID_PARSE_LIST
from trepan.processor.cmdlist import parse_list_cmd

# Our local modules
Expand Down Expand Up @@ -91,6 +91,7 @@ def run(self, args):
filename, first, last = parse_list_cmd(proc, args, listsize)
if (filename, first, last) == INVALID_PARSE_LIST:
return
assert isinstance(first, int)
curframe = proc.curframe
if filename is None:
return
Expand Down Expand Up @@ -133,7 +134,9 @@ def run(self, args):
}

for field in ("highlight", "style"):
if field in self.settings:
if field == "style" and opts["highlight"] == "plain":
opts["style"] = None
elif field in self.settings:
opts[field] = self.settings[field]

if first <= 0:
Expand Down Expand Up @@ -204,8 +207,8 @@ def doit(cmd, args):
print("--" * 10)
# doit(lcmd, ['list'])

doit(lcmd, ['list', __file__ + ':5'])
print('--' * 10)
doit(lcmd, ["list", __file__ + ":5"])
print("--" * 10)

# doit(lcmd, ['list', 'os:10'])
# print('--' * 10)
Expand Down

0 comments on commit e715db7

Please sign in to comment.