|
| 1 | +import unittest |
| 2 | +import glob |
| 3 | +import openfast_toolbox.io as weio |
| 4 | +import os |
| 5 | +import numpy as np |
| 6 | +from openfast_toolbox.io.tests.helpers_for_test import MyDir, reading_test |
| 7 | + |
| 8 | +class Test(unittest.TestCase): |
| 9 | + def test_000_debug(self): |
| 10 | + #fileformat,F = weio.detectFormat('_tests/FASTIn_ED_bld.dat') |
| 11 | + #F = weio.CSVFile('_tests/CSVComma_Fail.csv') |
| 12 | + #F = weio.FASTInFile('../_tests/FASTIn_ExtPtfm_SubSef.dat') |
| 13 | + #F = weio.FASTLinFile('../_tests/FASTOutLin_New.lin') |
| 14 | + #F = weio.TecplotFile('example_files/TecplotASCII_1.dat') |
| 15 | + #dfs=F.toDataFrame() |
| 16 | + #print(F.toDataFrame()) |
| 17 | + #print(F) |
| 18 | + #return |
| 19 | + #print(fileformat) |
| 20 | + pass |
| 21 | + |
| 22 | + def test_001_read_all(self): |
| 23 | + DEBUG=True |
| 24 | + nError=0 |
| 25 | + for f in glob.glob(os.path.join(MyDir,'*.*')): |
| 26 | + if os.path.splitext(f)[-1] in ['.py','.pyc'] or f.find('_TMP')>0: |
| 27 | + continue |
| 28 | + try: |
| 29 | + fileformat=None |
| 30 | + F=None |
| 31 | + fileformat,F = weio.detectFormat(f) |
| 32 | + #fr=weio.read(f,fileformat) |
| 33 | + dfs = F.toDataFrame() |
| 34 | + ## |
| 35 | + if not isinstance(dfs,dict): |
| 36 | + if dfs is None: |
| 37 | + n = 0 |
| 38 | + elif len(dfs)==0: |
| 39 | + n = 0 |
| 40 | + else: |
| 41 | + n = 1 |
| 42 | + else: |
| 43 | + n=len(dfs) |
| 44 | + ##print(fr.toDataFrame()) |
| 45 | + s=fileformat.name |
| 46 | + s=s.replace('file','')[:20] |
| 47 | + if DEBUG: |
| 48 | + print('[ OK ] {:30s}\t{:20s}\t{}'.format(os.path.basename(f)[:30],s,n)) |
| 49 | + except weio.FormatNotDetectedError: |
| 50 | + nError += 1 |
| 51 | + if DEBUG: |
| 52 | + print('[FAIL] {:30s}\tFormat not detected'.format(os.path.basename(f)[:30])) |
| 53 | + except weio.OptionalImportError: |
| 54 | + nError += 0 # Optional.. |
| 55 | + if DEBUG: |
| 56 | + print('[FAIL] {:30s}\tOptional package missing'.format(os.path.basename(f)[:30])) |
| 57 | + except: |
| 58 | + nError += 1 |
| 59 | + if DEBUG: |
| 60 | + print('[FAIL] {:30s}\tException occurred'.format(os.path.basename(f)[:30])) |
| 61 | + #raise |
| 62 | + |
| 63 | + if nError>0: |
| 64 | + raise Exception('Some tests failed') |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == '__main__': |
| 68 | + #Test().test_000_debug() |
| 69 | + unittest.main() |
0 commit comments