Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_streaming_write tests and refactor #105

Merged
merged 2 commits into from
Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 17 additions & 63 deletions six/modules/python/six/tests/runPythonScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,31 @@
#

import os
import subprocess
import sys
from subprocess import call

import utils
from runner import PythonTestRunner


def sicdToSIO(testsDir):
print('Running sicd_to_sio.py')
scriptName = os.path.join(testsDir, 'sicd_to_sio.py')
sampleNITF = os.path.join(utils.findSixHome(), 'regression_files',
'six.sicd', 'sicd_1.2.0(RMA)RMAT.nitf')
schemaPath = os.path.join(utils.installPath(), 'conf',
'schema', 'six')
result = call(['python', scriptName, sampleNITF, schemaPath],
stdout=subprocess.PIPE)
if result == 0:
os.remove(sampleNITF.rstrip('.nitf') + '.sio')
print("sicd_to_sio.py succeeded")
return True
return False

def testCreateSICDXML(testsDir):
print('Running test_create_sicd_xml.py')
scriptName = os.path.join(testsDir, 'test_create_sicd_xml.py')
result = call(['python', scriptName, '-v', '1.2.0'], stdout=subprocess.PIPE)
if result == 0:
os.remove('test_create_sicd.xml')
os.remove('test_create_sicd_rt.xml')
print('test_create_sicd_xml.py succeeded')
return True
return False

def testSixSICD(testsDir):
print('Running test_six_sicd.py')
scriptName = os.path.join(testsDir, 'test_six_sicd.py')
def run():
testsDir = os.path.join(utils.findSixHome(), 'six',
'modules', 'python', 'six.sicd', 'tests')
sampleNITF = os.path.join(utils.findSixHome(), 'regression_files',
'six.sicd', 'sicd_1.2.0(RMA)RMAT.nitf')
result = call(['python', scriptName, sampleNITF],
stdout = subprocess.PIPE)
if result == 0:
os.remove('from_sicd_sicd_1.2.0(RMA)RMAT.nitf.xml')
print('test_six_sicd.py succeeded')
return True
return False
schemaPath = os.path.join(utils.installPath(), 'conf', 'schema', 'six')

def testReadSICDXML(testsDir):
print('Running test_read_sicd_xml.py')
scriptName = os.path.join(testsDir, 'test_read_sicd_xml.py')
sampleNITF = os.path.join(utils.findSixHome(), 'regression_files',
'six.sicd', 'sicd_1.2.0(RMA)RMAT.nitf')
result = call(['python', scriptName, sampleNITF])
if result == 0:
print('test_read_sicd_xml.py succeeded')
return True
return False
sicdRunner = PythonTestRunner(testsDir)
result = (sicdRunner.run('test_streaming_sicd_write.py') and
sicdRunner.run('test_read_region.py') and
sicdRunner.run('test_read_sicd_xml.py', sampleNITF) and
sicdRunner.run('test_six_sicd.py', sampleNITF) and
sicdRunner.run('test_create_sicd_xml.py', '-v', '1.2.0') and
sicdRunner.run('sicd_to_sio.py', sampleNITF, schemaPath))

def testReadRegion(testsDir):
print('Running test_read_region.py')
scriptName = os.path.join(testsDir, 'test_read_region.py')
result = call(['python', scriptName], stdout=subprocess.PIPE)
if result == 0:
print('test_read_region succeeded')
return True
return False
return result

def run():
testsDir = os.path.join(utils.findSixHome(), 'six',
'modules', 'python', 'six.sicd', 'tests')
if __name__ == '__main__':
if run():
sys.exit(0)
sys.exit(1)

result = (sicdToSIO(testsDir) and testCreateSICDXML(testsDir) and
testSixSICD(testsDir) and testReadSICDXML(testsDir) and
testReadRegion(testsDir))
return result
16 changes: 10 additions & 6 deletions six/modules/python/six/tests/runTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import checkNITFs
import utils

from runner import CppTestRunner


def run(sicdDir):
# If we don't run this before setting the paths, we won't be testing
Expand Down Expand Up @@ -81,13 +83,15 @@ def run(sicdDir):
print('Warning: skipping the bulk of the test suite, '
'since Python modules are by default disabled on Solaris')

print("Performing byte swap test")
if subprocess.call([
utils.executableName(os.path.join(utils.installPath(),
'tests', 'six.sidd', 'test_byte_swap'))]) != 0:
print("Failed ByteSwap test in six.sidd/tests/test_byte_swap")
sicdTestDir = os.path.join(utils.installPath(), 'tests', 'six.sicd')
siddTestDir = os.path.join(utils.installPath(), 'tests', 'six.sidd')

sicdTestRunner = CppTestRunner(sicdTestDir)
siddTestRunner = CppTestRunner(siddTestDir)

if not (sicdTestRunner.run('test_streaming_write') and
siddTestRunner.run('test_byte_swap')):
return False
print("Byte swap test succeeded")

if runUnitTests.run() == False:
print("Unit tests failed")
Expand Down
48 changes: 48 additions & 0 deletions six/modules/python/six/tests/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import subprocess
from subprocess import call

import utils

class TestRunner(object):

def __init__(self, testsDir):
self.testsDir = testsDir
self.previousFiles = os.listdir(os.getcwd())

def clean(self):
currentFiles = os.listdir(os.getcwd())
for f in currentFiles:
if f not in self.previousFiles:
os.remove(f)

def createInvocation(self, pathname):
raise NotImplementedError

def run(self, testName, *args):
print('Running {0}'.format(testName))
pathname = os.path.join(self.testsDir, testName)
commandArgs = self.createInvocation(pathname)
commandArgs.extend(args)
result = False
if call(commandArgs, stdout=subprocess.PIPE) == 0:
print("{0} succeeded!".format(testName))
result = True
self.clean()
return result


class PythonTestRunner(TestRunner):
def __init__(self, pathname):
TestRunner.__init__(self, pathname)

def createInvocation(self, pathname):
return ['python', pathname]

class CppTestRunner(TestRunner):
def __init__(self, pathname):
TestRunner.__init__(self, pathname)

def createInvocation(self, pathname):
return [utils.executableName(pathname)]