Changeset 3939


Ignore:
Timestamp:
08/04/21 18:17:16 (20 months ago)
Author:
jennifer@painless-security.com
Message:

Create tests-no-network and clear-cache Makefile targets to support network-free testing. Fixes #561.

Location:
personal/jennifer/3.7.1.dev0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • personal/jennifer/3.7.1.dev0/Makefile

    r3932 r3939  
    1919
    2020export PYTHONHASHSEED = 0
     21
     22IETF_TEST_CACHE_PATH = tests/cache
     23export IETF_TEST_CACHE_PATH
    2124
    2225datetime_regex = [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][T_ ][0-9][0-9]:[0-9][0-9]:[0-9][0-9]
     
    5356pyfiles  = $(wildcard  xml2rfc/*.py) $(wildcard  xml2rfc/writers/*.py)
    5457
    55 
    56 tests: minify test flaketest cachetest drafttest rfctest utf8test v3featuretest elementstest bomtest wiptest mantest
     58.PHONY: tests tests-no-network
     59
     60# All tests
     61tests: minify tests-no-network cachetest
     62
     63# Tests that can run without network access
     64tests-no-network: test flaketest drafttest rfctest utf8test v3featuretest elementstest bomtest wiptest mantest
     65
     66# Clear the cache
     67.PHONY: clear-cache
     68clear-cache: install
     69        @echo -e "\n Clearing cache ..."
     70        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --clear-cache"
    5771
    5872env/bin/python:
     
    99113tests/out/%.txt tests/out/%.raw.txt tests/out/%.nroff tests/out/%.html tests/out/%.txt : tests/input/%.xml install
    100114        @echo -e "\n Processing $<"
    101         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --base tests/out/ --raw --legacy --text --nroff --html --strict $<"
     115        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --base tests/out/ --raw --legacy --text --nroff --html --strict $<"
    102116
    103117tests/out/%.v2v3.xml: tests/input/%.xml install
    104         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --v2v3 --strict --legacy-date-format $< --out $@"
     118        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --v2v3 --strict --legacy-date-format $< --out $@"
    105119        @doc=$(basename $@); printf ' '; xmllint --noout --xinclude --relaxng xml2rfc/data/v3.rng $$doc.xml
    106         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --v2v3 --strict --legacy-date-format --add-xinclude $< --out $@"
     120        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --v2v3 --strict --legacy-date-format --add-xinclude $< --out $@"
    107121
    108122tests/out/%.prepped.xml: tests/input/%.xml tests/out/%.v3.$(py).html tests/out/%.text install
    109         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out $@ --prep $<"
     123        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out $@ --prep $<"
    110124        @echo " Checking generation of .html from prepped .xml"
    111         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out $(basename $@).$(py).html --html --external-css --external-js --legacy-date-format --no-inline-version $@" 2> /dev/null || { err=$$?; echo "Error output when generating .html from prepped .xml"; exit $$err; }
     125        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out $(basename $@).$(py).html --html --external-css --external-js --legacy-date-format --no-inline-version $@" 2> /dev/null || { err=$$?; echo "Error output when generating .html from prepped .xml"; exit $$err; }
    112126        @diff -u -I '$(datetime_regex)' -I '$(version_regex)' -I '$(date_regex)' -I '$(generator_regex)' -I 'rel="alternate"' tests/out/$(notdir $(basename $(basename $@))).v3.$(py).html $(basename $@).$(py).html || { echo "Diff failed for $(basename $@).$(py).html output (2)"; exit 1; }
    113127        @echo " Checking generation of .text from prepped .xml"
    114         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out $(basename $@).text --text --no-pagination --external-css --external-js --legacy-date-format $@" 2> /dev/null || { err=$$?; echo "Error output when generating .text from prepped .xml"; exit $$err; }
     128        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out $(basename $@).text --text --no-pagination --external-css --external-js --legacy-date-format $@" 2> /dev/null || { err=$$?; echo "Error output when generating .text from prepped .xml"; exit $$err; }
    115129        @diff -u -I '$(datetime_regex)' -I '$(version_regex)' -I '$(date_regex)' -I '$(generator_regex)' -I 'rel="alternate"' tests/out/$(notdir $(basename $(basename $@))).text $(basename $@).text || { echo "Diff failed for $(basename $@).text output (3)"; exit 1; }
    116130
    117131tests/out/docfile.xml:
    118         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --doc --out $@"
     132        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --doc --out $@"
    119133
    120134tests/out/docfile.$(py).html: tests/out/docfile.xml
    121         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --html --external-css --external-js --no-inline-version --out $@ $<"
     135        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --html --external-css --external-js --no-inline-version --out $@ $<"
    122136
    123137tests/out/manpage.txt:
    124         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --man > $@"
     138        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --man > $@"
    125139
    126140tests/out/%.text: tests/input/%.xml install
    127         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --text --v3 --strict --no-pagination --legacy-date-format $< --out $@"
     141        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --text --v3 --strict --no-pagination --legacy-date-format $< --out $@"
    128142
    129143tests/out/%.pages.text: tests/input/%.xml install
    130         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --text --v3 --strict --legacy-date-format $< --out $@"
     144        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --text --v3 --strict --legacy-date-format $< --out $@"
    131145
    132146tests/out/%.bom.text: tests/input/%.xml install
    133         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --text --v3 --strict --bom $< --out $@"
     147        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --text --v3 --strict --bom $< --out $@"
    134148
    135149tests/out/%.wip.text: tests/input/%.xml install
    136         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --text --v3 --strict --id-is-work-in-progress $< --out $@"
     150        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --text --v3 --strict --id-is-work-in-progress $< --out $@"
    137151
    138152tests/out/%.v3.$(py).html: tests/input/%.xml install
    139         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --html --v3 --external-css --external-js --strict --legacy-date-format --rfc-reference-base-url https://rfc-editor.org/rfc --id-reference-base-url https://tools.ietf.org/html/ --no-inline-version $< --out $@"
     153        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --html --v3 --external-css --external-js --strict --legacy-date-format --rfc-reference-base-url https://rfc-editor.org/rfc --id-reference-base-url https://tools.ietf.org/html/ --no-inline-version $< --out $@"
    140154
    141155tests/out/%.pdf: tests/input/%.xml install
    142         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --pdf --v3 --legacy-date-format --rfc-reference-base-url https://rfc-editor.org/rfc --id-reference-base-url https://tools.ietf.org/html/ $< --out $@"
     156        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --pdf --v3 --legacy-date-format --rfc-reference-base-url https://rfc-editor.org/rfc --id-reference-base-url https://tools.ietf.org/html/ $< --out $@"
    143157
    144158tests/out/%.plain.xml: tests/out/%.prepped.xml install
    145         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --unprep --v3 --legacy-date-format --rfc-reference-base-url https://rfc-editor.org/rfc --id-reference-base-url https://tools.ietf.org/html/ $< --out $@"
     159        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --unprep --v3 --legacy-date-format --rfc-reference-base-url https://rfc-editor.org/rfc --id-reference-base-url https://tools.ietf.org/html/ $< --out $@"
    146160
    147161tests/out/%.plain.text: tests/out/%.plain.xml install
    148         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --text --v3 --strict --no-pagination --legacy-date-format $< --out $@  --silence='The document date'"
     162        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --text --v3 --strict --no-pagination --legacy-date-format $< --out $@  --silence='The document date'"
    149163
    150164tests/out/%.exp.xml: tests/input/%.xml install
    151         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out $@ --exp --legacy $<"
     165        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out $@ --exp --legacy $<"
    152166
    153167%.prepped.xml: %.v2v3.xml
    154         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out $@ --prep $<"
     168        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out $@ --prep $<"
    155169
    156170%.v2v3.text: %.v2v3.xml
    157         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --utf8 --out $@ --text --v3 $<"
     171        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --utf8 --out $@ --text --v3 $<"
    158172
    159173%.nroff.txt: %.nroff
     
    173187
    174188old-drafttest: cleantmp install
    175         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 tests/input/draft-template.xml"
    176         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out tmp/draft-template.prepped.xml --prep tmp/draft-template.v2v3.xml "
     189        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 tests/input/draft-template.xml"
     190        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out tmp/draft-template.prepped.xml --prep tmp/draft-template.v2v3.xml "
    177191        doc=draft-template ; postnrofffix="sed 1,2d" ; type=ascii; $(CHECKOUTPUT)
    178192
    179193miektest: cleantmp install
    180         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 tests/input/draft-miek-test.xml"
    181         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --out tmp/draft-miek-test.prepped.xml --prep tmp/draft-miek-test.v2v3.xml"
     194        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 tests/input/draft-miek-test.xml"
     195        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --out tmp/draft-miek-test.prepped.xml --prep tmp/draft-miek-test.v2v3.xml"
    182196        doc=draft-miek-test ; postnrofffix="sed 1,2d" ; type=ascii; $(CHECKOUTPUT)
    183197
     
    196210
    197211# rfctest: cleantmp env/bin/python install $(rfctests)
    198 #       @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --utf8tests/input/rfc6787.xml --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 --prep"
     212#       @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --utf8tests/input/rfc6787.xml --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 --prep"
    199213#       doc=rfc6787 ; postnrofffix="cat" ; type=ascii; $(CHECKOUTPUT)
    200 #       @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --utf8tests/input/rfc7754.edited.xml --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 --prep"
     214#       @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --utf8tests/input/rfc7754.edited.xml --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 --prep"
    201215#       doc=rfc7754.edited ; postnrofffix="cat" ; type=ascii; $(CHECKOUTPUT)
    202 #       @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --utf8tests/input/rfc7911.xml --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 --prep"
     216#       @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --utf8tests/input/rfc7911.xml --base tmp/ --raw --legacy --text --nroff --html --exp --v2v3 --prep"
    203217#       doc=rfc7911 ; postnrofffix="cat" ; type=ascii; $(CHECKOUTPUT)
    204218
    205219unicodetest: cleantmp  env/bin/python install
    206         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --base tmp/ --raw --legacy --text --nroff --html --no-inline-version --exp --v2v3 --prep tests/input/unicode.xml "
     220        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --base tmp/ --raw --legacy --text --nroff --html --no-inline-version --exp --v2v3 --prep tests/input/unicode.xml "
    207221        doc=unicode ; postnrofffix="sed 1,2d" ; type=ascii; $(CHECKOUTPUT)
    208222
    209223utf8test: cleantmp  env/bin/python install
    210         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --base tmp/ --raw --legacy --text --nroff --html --no-inline-version --exp --v2v3 --prep -q tests/input/utf8.xml"
     224        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --base tmp/ --raw --legacy --text --nroff --html --no-inline-version --exp --v2v3 --prep -q tests/input/utf8.xml"
    211225        @doc=utf8 ; postnrofffix="cat" ; type=utf8; $(CHECKOUTPUT)
    212226
     
    214228
    215229dateshifttest: cleantmp install
    216         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --date 2013-02-01 --legacy --out tmp/draft-miek-test.dateshift.txt --text tests/input/draft-miek-test.xml"
     230        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --date 2013-02-01 --legacy --out tmp/draft-miek-test.dateshift.txt --text tests/input/draft-miek-test.xml"
    217231        @diff -u -I '$(datetime_regex)' -I '$(version_regex)' -I '$(date_regex)' tests/valid/draft-miek-test.dateshift.txt tmp/draft-miek-test.dateshift.txt || { echo "Diff failed for draft-miek-test.dateshift.txt output"; exit 1; }
    218232
     
    249263
    250264test2:  test
    251         @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache tests/cache --no-network --utf8 tests/input/rfc6635.xml --legacy --text --out tmp/rfc6635.txt     && diff -u -I '$(datetime_regex)' -I '$(version_regex)' -I '$(date_regex)' tests/valid/rfc6635.txt tmp/rfc6635.txt "
     265        @PS4=" " /bin/bash -cx "xml2rfc --skip-config --cache \"$${IETF_TEST_CACHE_PATH}\" --no-network --utf8 tests/input/rfc6635.xml --legacy --text --out tmp/rfc6635.txt    && diff -u -I '$(datetime_regex)' -I '$(version_regex)' -I '$(date_regex)' tests/valid/rfc6635.txt tmp/rfc6635.txt "
    252266
    253267upload: install
  • personal/jennifer/3.7.1.dev0/test.py

    r3387 r3939  
    1818except ImportError:
    1919    pass
     20
     21
     22# Set up options before declaring classes - some are used during class construction.
     23options_for_xmlrfcparser = dict()
     24def _load_environment():
     25    from os import environ
     26    cache_path =  environ.get('IETF_TEST_CACHE_PATH', None)
     27    if cache_path:
     28        options_for_xmlrfcparser['cache_path'] = cache_path
     29
     30
     31_load_environment()
     32
    2033
    2134def arrstrip(arr):
     
    267280    def parse(self, path):
    268281        """ Parse a minimal RFC tree and instantiate a writer """
    269         self.parser = xml2rfc.XmlRfcParser(path, quiet=True)
     282        self.parser = xml2rfc.XmlRfcParser(path, quiet=True, **options_for_xmlrfcparser)
    270283        self.xmlrfc = self.parser.parse()
    271284        self.writer = xml2rfc.PaginatedTextRfcWriter(self.xmlrfc, quiet=True)
     
    454467
    455468
    456 def pdfwriter(path):
    457     """ Parse a minimal RFC tree and instantiate a writer """
    458     parser = xml2rfc.XmlRfcParser(path, quiet=True)
    459     xmlrfc = parser.parse()
    460     writer = xml2rfc.writers.pdf.PdfWriter(xmlrfc, quiet=True, )
    461     return writer
    462 
    463 elements_writer = pdfwriter('tests/input/elements.xml')
    464 try:
    465     elements_pdfdoc = elements_writer.pdf() # has side effects on .root
    466 except Exception as e:
    467     print(e)
    468     raise
    469 elements_root   = elements_writer.root
    470 elements_pdfxml = xmldoc(None, bytes=elements_pdfdoc)
    471 
    472469class PdfWriterTests(unittest.TestCase):
     470    elements_root = None
     471    elements_pdfxml = None
     472
     473    @classmethod
     474    def setUpClass(cls) -> None:
     475        # Putting this in setUpClass() allows this module to be imported even if this
     476        # procedure will fail. This improves some error messages and makes debugging
     477        # a little bit easier. The setUpClass() method is run by unittest during init.
     478        # This happens only once, avoiding repeated execution of slow operations.
     479        def _pdfwriter(path):
     480            """ Parse a minimal RFC tree and instantiate a writer """
     481            parser = xml2rfc.XmlRfcParser(path, quiet=True, **options_for_xmlrfcparser)
     482            xmlrfc = parser.parse()
     483            writer = xml2rfc.writers.pdf.PdfWriter(xmlrfc, quiet=True, )
     484            return writer
     485
     486        elements_writer = _pdfwriter('tests/input/elements.xml')
     487        try:
     488            elements_pdfdoc = elements_writer.pdf() # has side effects on .root
     489        except Exception as e:
     490            print(e)
     491            raise
     492        cls.elements_root   = elements_writer.root
     493        cls.elements_pdfxml = xmldoc(None, bytes=elements_pdfdoc)
    473494
    474495    def setUp(self):
    475496        xml2rfc.log.quiet = True
    476         self.pdfxml = copy.deepcopy(elements_pdfxml)
    477         self.root = copy.deepcopy(elements_root)
    478 
     497        self.pdfxml = copy.deepcopy(self.elements_pdfxml)
     498        self.root = copy.deepcopy(self.elements_root)
    479499
    480500    def test_text_content(self):
Note: See TracChangeset for help on using the changeset viewer.