| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
from __future__ import division, print_function, unicode_literals
|
| 3 |
|
| 4 |
import os
|
| 5 |
import unittest
|
| 6 |
|
| 7 |
import testsupport as ts
|
| 8 |
from pyradlib import lcompare
|
| 9 |
from pyradlib.pyrad_proc import PIPE, Error, ProcMixin
|
| 10 |
|
| 11 |
|
| 12 |
class PhistoTestCase(unittest.TestCase, ProcMixin):
|
| 13 |
|
| 14 |
def _runit(self, cmd, _in=None):
|
| 15 |
failmsg = None
|
| 16 |
proc = None
|
| 17 |
try:
|
| 18 |
proc = self.call_one(cmd, 'test phisto',
|
| 19 |
_in=_in, out=PIPE, universal_newlines=True)
|
| 20 |
raw = proc.stdout.read()
|
| 21 |
except Error as e:
|
| 22 |
#self.fail(failmsg)
|
| 23 |
failmsg = str(e)
|
| 24 |
finally:
|
| 25 |
if proc:
|
| 26 |
res = proc.wait()
|
| 27 |
if res != 0:
|
| 28 |
failmsg = 'Non-zero (%d) exit from %s' % (res, str(cmd))
|
| 29 |
if failmsg:
|
| 30 |
self.fail(failmsg)
|
| 31 |
return lcompare.split_rad(raw)
|
| 32 |
|
| 33 |
def test_phisto(self):
|
| 34 |
if os.name == 'nt': phisto = 'phisto'
|
| 35 |
else: phisto = 'phisto'
|
| 36 |
hgradpic = ts.datafile('gradients', 'h_gradient.hdr')
|
| 37 |
vgradpic = ts.datafile('gradients', 'v_gradient.hdr')
|
| 38 |
datafn = ts.datafile('gradients', 'gradient.histo')
|
| 39 |
with open(datafn, 'r') as df:
|
| 40 |
dtxt = df.read()
|
| 41 |
expect = lcompare.split_rad(dtxt)
|
| 42 |
for picfn in (hgradpic, vgradpic):
|
| 43 |
hcmd = [phisto, picfn]
|
| 44 |
err_msg = None
|
| 45 |
try:
|
| 46 |
result = self._runit(hcmd)
|
| 47 |
lcompare.llcompare(result, expect)
|
| 48 |
except AssertionError as e:
|
| 49 |
with open(picfn, 'rb') as picf:
|
| 50 |
hcmd = [phisto]
|
| 51 |
result = self._runit(hcmd, _in=picf)
|
| 52 |
try:
|
| 53 |
lcompare.llcompare(result, expect)
|
| 54 |
err_msg = 'Phisto fails with spaces in file name paths.'
|
| 55 |
except Exception as e:
|
| 56 |
err_msg = str(e)
|
| 57 |
except Exception as e:
|
| 58 |
err_msg = str(e)
|
| 59 |
if err_msg:
|
| 60 |
self.fail(err_msg)
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
# vi: set ts=4 sw=4 :
|