| 1 |
schorsch |
1.1 |
# -*- coding: utf-8 -*- |
| 2 |
|
|
from __future__ import division, print_function, unicode_literals |
| 3 |
|
|
|
| 4 |
|
|
# We currently only test for output of recno after receiving a |
| 5 |
|
|
# single column list from cnt(). |
| 6 |
|
|
# This serves to uncover the nl eating bug in buffered pipes |
| 7 |
|
|
# in Visual Studio 2015 before update 2. |
| 8 |
|
|
|
| 9 |
|
|
import struct |
| 10 |
|
|
import unittest |
| 11 |
|
|
|
| 12 |
|
|
from pyradlib import lcompare |
| 13 |
|
|
from pyradlib.pyrad_proc import PIPE, Error, ProcMixin |
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
class RcalcTestCase(unittest.TestCase, ProcMixin): |
| 17 |
|
|
|
| 18 |
|
|
def _runit(self, cmd1, cmd2, actstr, nl=False): |
| 19 |
|
|
try: |
| 20 |
|
|
procs = self.call_many((cmd1, cmd2), actstr, out=PIPE, |
| 21 |
|
|
universal_newlines=nl) |
| 22 |
|
|
res, eres = procs[-1].communicate() |
| 23 |
|
|
if eres: print('Errors', eres) # XXX |
| 24 |
|
|
except Error as e: |
| 25 |
|
|
self.fail('%s [%s]' % (str(e), self.qjoin(cmd))) |
| 26 |
|
|
finally: |
| 27 |
|
|
for proc in procs: |
| 28 |
|
|
proc.wait() |
| 29 |
|
|
if nl: return [int(s) for s in res.split()] |
| 30 |
|
|
return res |
| 31 |
|
|
|
| 32 |
|
|
#return lcompare.split_rad(raw) |
| 33 |
|
|
|
| 34 |
|
|
def test_recno_oascii(self): |
| 35 |
|
|
for n in (5, 10, 55, 200,1321, 1328,1329,1330,1331,1332, 2000, 3721, 5000,9876): |
| 36 |
|
|
orig = range(n) |
| 37 |
|
|
exp = [i+1 for i in orig] |
| 38 |
|
|
cntcmd = ['cnt', str(n)] |
| 39 |
|
|
aacmd = ['rcalc', '-e', '$1=recno'] |
| 40 |
|
|
aresl = self._runit(cntcmd, aacmd, 'calculate recno', nl=True) |
| 41 |
|
|
try: lcompare.lcompare(aresl, exp) |
| 42 |
|
|
except lcompare.error as e: |
| 43 |
|
|
self.fail(('recno_oascii n=%d -- ' % n) +str(e)) |
| 44 |
|
|
|
| 45 |
|
|
def test_recno_ofloat(self): |
| 46 |
|
|
for n in (5, 10, 55, 200,1321, 1328,1329,1330,1331,1332, 2000, 3721, 5000): |
| 47 |
|
|
orig = range(n) |
| 48 |
|
|
exp = (i+1 for i in orig) |
| 49 |
|
|
cntcmd = ['cnt', str(n)] |
| 50 |
|
|
afcmd = ['rcalc', '-of', '-e', '$1=recno'] |
| 51 |
|
|
res = self._runit(cntcmd, afcmd, 'calculate recno') |
| 52 |
|
|
if len(res) != n * 4: |
| 53 |
|
|
self.fail(('recno_ofloat n=%d -- Length of resulting data ' |
| 54 |
|
|
'differs from expected (%d != %d)') |
| 55 |
|
|
% (n, len(res), n*4)) |
| 56 |
|
|
iresl = struct.unpack('f'*n, res) |
| 57 |
|
|
try: lcompare.lcompare(iresl, exp) |
| 58 |
|
|
except lcompare.error as e: |
| 59 |
|
|
self.fail(('recno_ofloat n=%d -- ' % n) +str(e)) |
| 60 |
|
|
|
| 61 |
|
|
def test_recno_odouble(self): |
| 62 |
|
|
for n in (5, 10, 55, 200,1321, 1328,1329,1330,1331,1332, 2000, 3721, 5000): |
| 63 |
|
|
orig = range(n) |
| 64 |
|
|
exp = (i+1 for i in orig) |
| 65 |
|
|
cntcmd = ['cnt', str(n)] |
| 66 |
|
|
adcmd = ['rcalc', '-od', '-e', '$1=recno'] |
| 67 |
|
|
res = self._runit(cntcmd, adcmd, 'calculate recno') |
| 68 |
|
|
if len(res) != n * 8: |
| 69 |
|
|
self.fail(('recno_odouble n=%d -- Length of resulting data ' |
| 70 |
|
|
'differs from expected (%d != %d)') |
| 71 |
|
|
% (n, len(res), n*8)) |
| 72 |
|
|
iresl = struct.unpack('d'*n, res) |
| 73 |
|
|
try: lcompare.lcompare(iresl, exp) |
| 74 |
|
|
except lcompare.error as e: |
| 75 |
|
|
self.fail(('recno_odouble n=%d -- ' % n) +str(e)) |
| 76 |
|
|
|
| 77 |
|
|
|
| 78 |
|
|
# vi: set ts=4 sw=4 : |