Commit 6f928a65 authored by admuc's avatar admuc

rearrange more_tests cont. i

parents d5029cbc d7fdf459
#!/usr/bin/env python3
"""produces testcases of current version AsciiDoc3 using multiprocessing.
Writes output to /dev/shm/current/*.* (that means: in memory)
Needs configuration of testcases already pickled; see
'./pickled_data/testconf3pickle.py' and './pickled_data/testconf3pickle.dat'
We have to set 'imagesdir' explicitly.
Sample of testconf-item:
{'options': (('--doctype', 'book'),),
'attributes': (('toc', True),),
'outfile': '/dev/shm/current/lang-it-book-test-html5.html',
'backend': 'html5',
'inputfile': '~/asciidoc3/tests/data/lang-it-test.txt'}
(c) 2018 Berthold Gehrke <berthold.gehrke@gmail.com>
Free use is granted under the terms of GPLv2+
"""
from concurrent import futures
import os.path
import pickle
......@@ -8,42 +25,28 @@ from sys import platform
from shutil import rmtree
import subprocess
"""Produces testcases of current version AsciiDoc3 using multiprocessing,
'current version' uses ../../asciidoc3.py
Output is written to /dev/shm/current/*.* (that means: only in memory and fast).
Needs pickled configuration of testcases, see './pickled_data/testconf3pickle.py'.
"""
def remove_old_files_and_mkdir_dev_shm_current():
"""Removes all remainder (if any) of previous testing in /dev/shm/current,
and creates an empty directory /dev/shm/current."""
def remove_and_mkdir_shm_current():
"""all remainder (if any) of previous testing in /dev/shm/current are removed,
and a new directory is created"""
if os.path.exists("/dev/shm/current") and os.path.isdir("/dev/shm/current"):
rmtree("/dev/shm/current")
os.mkdir("/dev/shm/current")
print("remove_old_files_and_mkdir_dev_shm_current() ... done")
print("remove_and_mkdir_shm_current() ... done")
def reading_testconf():
"""compute tuple(testtuple). Every item in testtuple
is a dict.
Sample of item:
{'options': (('--doctype', 'book'),),
'attributes': (('toc', True),),
'outfile': '/dev/shm/current/lang-it-book-test-html5.html',
'backend': 'html5',
'inputfile': '~/.asciidoc3/tests/data/lang-it-test.txt'}
"""
is a dict. """
testconf3pickle = os.path.abspath('./pickled_data/testconf3pickle.dat')
with open(testconf3pickle, 'rb', 3) as f:
testtuple = tuple(pickle.load(f))
#print(testtuple)
print("unpickle testtuple ... done")
with open(testconf3pickle, 'rb', 3) as test_conf_file:
testtuple = tuple(pickle.load(test_conf_file))
#pprint.print(testtuple)
#print("len(testtuple): ", len(testtuple))
print("unpickle testtuple ... done")
return testtuple
def run_testcases(itemrow):
"""reads one testconf, runs the test, and writes output"""
# compute 'optionslist'
def create_testcases(itemrow):
"""text here"""
inputfile = itemrow['inputfile']
optionslist = list()
optionslist.append('-b')
optionslist.append(itemrow['backend'])
......@@ -55,49 +58,40 @@ def run_testcases(itemrow):
if itemrow['attributes']:
for attrpair in itemrow['attributes']:
optionslist.append('-a')
if attrpair[1] == None:
if attrpair[1] is None:
attr = attrpair[0] + '="None"'
elif attrpair[1] == True:
elif attrpair[1] is True:
attr = attrpair[0] + '="True"'
else:
attr = attrpair[0] + '=' + attrpair[1]
optionslist.append(attr)
outputfile = itemrow['outfile']
optionslist.extend(["-o", outputfile])
#print(optionslist)
# sample of 'optionslist':
# ['-b', 'xhtml11', '--doctype', 'article', '-a', 'toc="True"', \
# '-o', '/dev/shm/current/lang-en-article-test-xhtml11.html']
# compute 'commandline'
#set imagedir
explicit_imagedir = os.path.abspath('../../images')
optionslist.extend(["-a", "imagesdir=" + explicit_imagedir])
commandline = list()
commandline.append("python3")
asciidoc3_executable = os.path.abspath('../../asciidoc3.py')
commandline.append(asciidoc3_executable)
ad3_executable = os.path.abspath("../../asciidoc3.py")
commandline.append(ad3_executable)
commandline.extend(optionslist)
inputfile = itemrow['inputfile']
commandline.append(inputfile)
#print()
#print("subprocess starts with the following commadline: ")
#print(commandline)
# sample of 'commandline':
# ['python3', '~/asciidoc3/asciidoc3.py', '-b', 'docbook', '--doctype', 'article', \
# '-a', 'toc="True"', '-o', '/dev/shm/current/lang-it-article-test-docbook.xml', \
# '/home/bge/gitlabad3/asciidoc3/tests/data/lang-it-test.txt']
# ... produces the test-output
p = subprocess.run(commandline, stderr=subprocess.PIPE)
# If something goes wrong, print warning
if p.returncode:
print("!!! --> WARNING Returncode =", p.returncode, "item:", itemrow['inputfile'])
print()
print(commandline)
subprocess_testcase = subprocess.run(commandline, stderr=subprocess.PIPE)
if subprocess_testcase.returncode:
print("[WARNING] Returncode =", subprocess_testcase.returncode, \
"processing inputfile", itemrow['inputfile'])
print()
if __name__ == "__main__":
# do not start as imported module
# do not run as an imported module or using an IDE like IDLE
if not platform.lower().startswith('linux'):
exit("Sorry, at this time only Linux!")
remove_old_files_and_mkdir_dev_shm_current()
testtuple = reading_testconf()
exit("Sorry, at this time only GNU/Linux!")
remove_and_mkdir_shm_current()
TUPLE_TEST = reading_testconf()
with futures.ProcessPoolExecutor(max_workers=4) as e:
for item in testtuple:
e.submit(run_testcases, item)
for item in TUPLE_TEST:
e.submit(create_testcases, item)
print("writing testcases ... done")
......@@ -163,15 +163,17 @@ LaTeX Filter
% source
../doc/latex-filter.txt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
User Guide
% options
['--section-numbers']
% source
../doc/userguide.txt
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# User Guide only in AsciiDoc3, see README
#User Guide
#
#% options
#['--section-numbers']
#
#
#% source
#../doc/userguide.txt
#
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
UTF-8 Examples
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment