Skip to content

Commit

Permalink
added test for validity against XSD, moved definition of out and err …
Browse files Browse the repository at this point in the history
…to processImages function
  • Loading branch information
bitsgalore committed Apr 19, 2022
1 parent 23fc174 commit 38cd9ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
13 changes: 7 additions & 6 deletions isolyzer/isolyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,13 @@ def processImages(images, offset):
"""
Process list of images
"""

global out
global err

out = codecs.getwriter("UTF-8")(sys.stdout.buffer)
err = codecs.getwriter("UTF-8")(sys.stderr.buffer)

# Create output element
root = ET.Element("isolyzer", {'xmlns': nsString,
'xmlns:xsi': xsiNsString,
Expand All @@ -800,12 +807,6 @@ def processImages(images, offset):
def main():
"""Main command line application"""

global out
global err

out = codecs.getwriter("UTF-8")(sys.stdout.buffer)
err = codecs.getwriter("UTF-8")(sys.stderr.buffer)

# Get input from command line
args = parseCommandLine()

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_testfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lxml import etree

from isolyzer.isolyzer import processImage
from isolyzer.isolyzer import processImages

sizeDifferenceSectors = {
"hfs.iso":2.0,
Expand Down Expand Up @@ -53,6 +54,9 @@
# Root dir of isolyzer repo
ISOLYZER_DIR = os.path.split(os.path.split(SCRIPT_DIR)[0])[0]

# XSD file (path resolved from SCRIPT_DIR)
xsdFile = os.path.join(ISOLYZER_DIR, "xsd/isolyzer-v-1-0.xsd")

# Directory with test files
testFilesDir = os.path.join(ISOLYZER_DIR, "testFiles")

Expand Down Expand Up @@ -112,3 +116,21 @@ def test_fileSystems(input):
fsDetected.append(fsType)
# Test if file systems in both lists are identical
assert set(fsKnown) == set(fsDetected)

def test_xml_is_valid(capsys):
"""
Run processImages function on all files in test corpus and
verify resulting XML output validates against XSD schema
"""

processImages(testFiles, 0)

# Capture output from stdout
captured = capsys.readouterr()
xmlOut = captured.out
# Parse XSD schema
xmlschema_doc = etree.parse(xsdFile)
xmlschema = etree.XMLSchema(xmlschema_doc)
# Parse XML
xml_doc = etree.fromstring(xmlOut.encode())
assert xmlschema.validate(xml_doc)

0 comments on commit 38cd9ff

Please sign in to comment.