Files
Taus e45f6e9b24 Python: Add copy of extractor tests
These get to live next to the existing library and query tests, and are
run as part of both the Python 2 and Python 3 language tests.
2024-04-15 12:22:07 +00:00

36 lines
1.4 KiB
Python

#Contents don't matter but must be the same for both files.
class ExtractorTest(unittest.TestCase):
def __init__(self, name):
unittest.TestCase.__init__(self, name)
self.here = os.path.dirname(__file__)
self.module_path = os.path.abspath(os.path.join(self.here, "data"))
self.trap_path = os.path.abspath(os.path.join(self.here, "traps"))
def setUp(self):
try:
os.makedirs(self.trap_path)
except:
if os.path.exists(self.trap_path):
return
raise
def tearDown(self):
shutil.rmtree(self.trap_path, ignore_errors=True)
def check_exists_only_and_clear(self, *module_names):
for name in module_names:
path = os.path.join(self.trap_path, name.replace('.', os.sep) + ".trap.gz")
self.assertTrue(os.path.exists(path), "No trap file for " + name + " at " + path)
os.remove(path)
for _, _, filenames in os.walk(self.trap_path):
filenames = [ name for name in filenames if not name.startswith("$") and name != "__builtin__.trap.gz"]
self.assertFalse(filenames, "Some trap files remain: " + ", ".join(filenames))
def run_extractor(self, *args):
argv = sys.argv
sys.argv = [ "python_extractor" ] + ["-p", self.module_path, "-o", self.trap_path, "--omit-hash"] + list(args)
semmle.populator.main()
sys.argv = sys