Skip to content

Commit

Permalink
Reinstate integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Sep 15, 2024
1 parent 3f0042d commit 44ee4e2
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 147 deletions.
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

0 comments on commit 44ee4e2

Please sign in to comment.