[libxml2] python/tests: open() relative to test scripts



commit 0137d9879b08a243f8125b764d07f8f86dd3998d
Author: David Seifert <soap gentoo org>
Date:   Wed Mar 30 22:00:50 2022 +0200

    python/tests: open() relative to test scripts

 python/tests/reader2.py | 5 ++++-
 python/tests/reader5.py | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/python/tests/reader2.py b/python/tests/reader2.py
index b50180df..ea8a17fc 100755
--- a/python/tests/reader2.py
+++ b/python/tests/reader2.py
@@ -5,6 +5,7 @@
 #
 import sys
 import glob
+import os
 import string
 import libxml2
 try:
@@ -18,7 +19,8 @@ except:
 libxml2.debugMemory(1)
 
 err = ""
-dir_prefix = "../../test/valid/"
+basedir = os.path.dirname(os.path.realpath(__file__))
+dir_prefix = os.path.join(basedir, "../../test/valid/")
 # This dictionary reflects the contents of the files
 # ../../test/valid/*.xml.err that are not empty, except that
 # the file paths in the messages start with ../../test/
@@ -125,6 +127,7 @@ parsing_error_files = ["766956", "cond_sect2", "t8", "t8a"]
 expect_parsing_error = ["{}{}.xml".format(dir_prefix, f) for f in parsing_error_files]
 
 valid_files = glob.glob(dir_prefix + "*.x*")
+assert valid_files, "found no valid files in '{}'".format(dir_prefix)
 valid_files.sort()
 for file in valid_files:
     err = ""
diff --git a/python/tests/reader5.py b/python/tests/reader5.py
index 82d0daea..da5355ff 100755
--- a/python/tests/reader5.py
+++ b/python/tests/reader5.py
@@ -4,6 +4,7 @@
 # this extract the Dragon bibliography entries from the XML specification
 #
 import libxml2
+import os
 import sys
 
 # Memory debug specific
@@ -14,7 +15,8 @@ Ravi Sethi, and Jeffrey D. Ullman.
 <emph>Compilers:  Principles, Techniques, and Tools</emph>.
 Reading:  Addison-Wesley, 1986, rpt. corr. 1988.</bibl>"""
 
-f = open('../../test/valid/REC-xml-19980210.xml', 'rb')
+basedir = os.path.dirname(os.path.realpath(__file__))
+f = open(os.path.join(basedir, '../../test/valid/REC-xml-19980210.xml'), 'rb')
 input = libxml2.inputBuffer(f)
 reader = input.newTextReader("REC")
 res=""


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]