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

Make crop_sicd's method of finding the appropriate directories more reliable. #95

Merged
merged 13 commits into from
Aug 4, 2016
4 changes: 3 additions & 1 deletion six/modules/c++/samples/crop_sicd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ int main(int argc, char** argv)
{
try
{
const sys::Path::StringPair splitName(sys::Path::splitPath(argv[0]));
sys::OS os;
const sys::Path::StringPair splitName(sys::Path::splitPath(
os.getCurrentExecutable(argv[0])));
const sys::Path progDirname(splitName.first);
const sys::Path installPath(progDirname.join("..").getAbsolutePath());

Expand Down
3 changes: 1 addition & 2 deletions six/modules/python/six/tests/checkNITFs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from subprocess import call

print utils.installPath()
binDir = os.path.join(utils.installPath(), 'bin')

def roundTrippedName(pathname):
Expand All @@ -41,7 +40,7 @@ def roundTripSix(pathname):
def validate(pathname):
check_valid_six = utils.executableName(os.path.join(binDir,
'check_valid_six'))

return (call([check_valid_six, pathname], stdout=open(os.devnull, 'w')) and
call([check_valid_six, roundTrippedName(pathname)],
stdout=open(os.devnull, 'w'))) == 0
Expand Down
7 changes: 6 additions & 1 deletion six/modules/python/six/tests/runMiscTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def runSICDTests():
# Make sure plugins installed properly
nitfPluginPath = os.environ['NITF_PLUGIN_PATH_REAL']

if not any(plugin.startswith('PIAIMB') for plugin in os.listdir(nitfPluginPath)):
if (not os.path.exists(nitfPluginPath) or
not any(plugin.startswith('PIAIMB') for plugin in
os.listdir(nitfPluginPath))):
print('Could not find NITF plugins. Please re-install with '
'the following command.')
print('python waf install --target=PIAIMB')
Expand All @@ -70,3 +72,6 @@ def runSICDTests():

def run():
return runSICDTests()

if __name__ == '__main__':
run()
100 changes: 67 additions & 33 deletions six/modules/python/six/tests/runTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,73 @@
import checkNITFs
import utils

utils.setPaths()

if platform.system() != 'SunOS':
if makeRegressionFiles.run() == False:
print("Error generating regression files")
sys.exit(1)

if runPythonScripts.run() == False:
print("Error running a python script")
sys.exit(1)

if checkNITFs.run() == False:
print("test in checkNITFS.py failed")
sys.exit(1)

if runMiscTests.run() == False:
# Tests should report their own errors
sys.exit(1)
else:
print('Warning: skipping the bulk of the test suite, as 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")
sys.exit(1)
print("Byte swap test succeeded")

if runUnitTests.run() == False:
print("Unit tests failed")
sys.exit(1)
def run(sicdDir):
# If we don't run this before setting the paths, we won't be testing
# the right things

if sicdDir != '':
os.environ["PATH"] = (os.environ["PATH"] + os.pathsep +
os.path.join(utils.installPath(), 'bin'))
cropSicds = utils.executableName('crop_sicd')

sicdPathname = os.path.join(sicdDir, os.listdir(sicdDir)[0])

success = subprocess.call([cropSicds,
'--start-row', '0', '--start-col', '0',
'--num-rows', '10', '--num-cols', '10',
sicdPathname, 'cropped.nitf'],
stdout=subprocess.PIPE)

print("Running crop_sicd")
if os.path.exists('cropped.nitf'):
os.remove('cropped.nitf')
if success != 0:
print("Error running crop_sicd")
return False

utils.setPaths()

if platform.system() != 'SunOS':
if makeRegressionFiles.run() == False:
print("Error generating regression files")
return False

print("All passed")
sys.exit(0)
if runPythonScripts.run() == False:
print("Error running a python script")
return False

if checkNITFs.run() == False:
print("test in checkNITFS.py failed")
return False

if runMiscTests.run() == False:
# These tests should report their own errors
return False
else:
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")
return False
print("Byte swap test succeeded")

if runUnitTests.run() == False:
print("Unit tests failed")
return False

print("All passed")
return True

if __name__ == '__main__':
sicdDir = ''
if len(sys.argv) > 1:
sicdDir = sys.argv[1]
if run(sicdDir):
sys.exit(0)
sys.exit(1)

7 changes: 4 additions & 3 deletions six/modules/python/six/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def findSixHome():

return currentPath


def installPath():
home = findSixHome()
children = ['remove_foss.csh', 'README.md', 'six', 'wscript',
Expand All @@ -55,6 +56,7 @@ def installPath():
subdirs = os.listdir(fullChildPath)
if 'tests' in subdirs and 'bin' in subdirs:
return fullChildPath

def findPythonPath():
if platform.system() == 'Linux':
return glob(os.path.join(installPath(), 'lib', 'python*',
Expand Down Expand Up @@ -100,6 +102,5 @@ def executableName(pathname):
if pathname.endswith('.exe'):
return pathname
return pathname + '.exe'
if pathname.startswith('/'):
return pathname
return './' + pathname
return pathname