def test_inferReader(self):
     """Verify the correct readers are returned for given files"""
     from serpentTools.parsers import (BumatReader, BranchingReader,
                                       DepletionReader, DetectorReader,
                                       ResultsReader, FissionMatrixReader)
     expectedClasses = {
         'test.bumat99': BumatReader,
         'test.coe': BranchingReader,
         'test_dep.m': DepletionReader,
         'test_det99.m': DetectorReader,
         'test_res.m': ResultsReader,
         'test_fmtx99.m': FissionMatrixReader,
         'test_res': None,
         'test.coe_dep.m': DepletionReader
     }
     for fileP, expectedReader in six.iteritems(expectedClasses):
         if expectedReader is None:
             with self.assertRaises(SerpentToolsException):
                 inferReader(fileP)
         else:
             actual = inferReader(fileP)
             self.assertIs(
                 expectedReader, actual,
                 'File path: {}\nExpected: {}\nActual: {}'.format(
                     fileP, str(expectedReader), str(actual)))
Exemple #2
0
def _toMatlab(args):
    """
    Write contents of a file to matlab.

    Return codes:
        0: all good
        1: need scipy
        3: conversion for file type not supported yet
    """
    inFile = args.file
    outFile = args.output
    if not outFile:
        base = splitext(inFile)[0]
        outFile = base + '.mat'

    # inferReader returns the class, but we need an instance
    reader = inferReader(inFile)(inFile)
    try:
        converter = MatlabConverter(reader, outFile)
    except ImportError:
        error("scipy >= 1.0 required to convert to matlab")
        return 1
    except NotImplementedError:
        error("Conversion not supported for {} reader at this time. ".format(
            reader.__class__.__name__))
        error("Please alert the developers of your need.")
        return 3
    reader.read()
    converter.convert(True,
                      append=args.append,
                      format=args.format,
                      longNames=args.longNames,
                      compress=not args.large,
                      oned=args.oned)
    if not args.q:
        if args.v:
            info("Wrote contents of {} to {}".format(inFile, outFile))
        else:
            print(outFile)

    return 0