Esempio n. 1
0
def main():
    log.begin()

    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    # Add optional command line arguments
    parser.add_argument('--fswtabdict', default=None, required=True)
    parser.add_argument('--tabfile', default=None, required=True)
    parser.add_argument('--binfile', default=None, required=True)
    parser.add_argument('--tabletype', default=None, required=True)
    parser.add_argument('--verbose', action='store_true', default=False)

    # Get command line arguments
    args = parser.parse_args()
    dictpath = args.fswtabdict
    tabfile = args.tabfile
    tabletype = args.tabletype
    verbose = args.verbose

    # Grab default command dictionary
    if dictpath is not None:
        dictCache = table.FSWTabDictCache(filename=dictpath)

        try:
            filename = dictCache.filename
        except IOError, e:
            msg = 'Could not load default table dictionary "%s": %s'
            log.error(msg, filename, str(e))
        fswtabdict = table.FSWTabDict(filename)
Esempio n. 2
0
 def setUpClass(cls):
     with TestFile("test_time_table.yaml", "wt") as temp_test_file:
         with open(temp_test_file, "w") as infile:
             assert infile.write(
                 inspect.cleandoc(
                     """
                 - !FSWTable
                   name: test_type
                   delimiter: ","
                   header:
                     - !FSWColumn
                       name: MAGIC_NUM
                       desc: The first column in our header
                       type:  U8
                       bytes: 0
                     - !FSWColumn
                       name: UPTYPE
                       desc: The second column in our header
                       type:  U8
                       bytes: 1
                     - !FSWColumn
                       name: VERSION
                       desc: The third column in our header
                       type:  U8
                       bytes: 2
                   columns:
                     - !FSWColumn
                       name: COLUMN_ONE
                       desc: First FSW Table Column
                       type:  TIME64
                       bytes: [0,7]
                     - !FSWColumn
                       name: COLUMN_TWO
                       desc: Second FSW Table Column
                       type:  TIME40
                       bytes: [8,12]
                     - !FSWColumn
                       name: COLUMN_THREE
                       desc: Third FSW Table Column
                       type:  TIME32
                       bytes: [13,16]
                 """
                 )
             )
         cls.tabdict = table.FSWTabDict(temp_test_file)
Esempio n. 3
0
def main():
    log.begin()

    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    # Add optional command line arguments
    parser.add_argument('--fswtabdict', default=None, required=True)
    parser.add_argument('--tabfile', default=None, required=True)
    parser.add_argument('--binfile', default=None, required=True)
    parser.add_argument('--tabletype', default=None, required=True)
    parser.add_argument('--verbose', action='store_true', default=False)

    # Get command line arguments
    args = parser.parse_args()
    dictpath      = args.fswtabdict
    tabfile       = args.tabfile
    tabletype     = args.tabletype
    verbose       = args.verbose

    # Grab default command dictionary
    if dictpath is not None:
        dictCache = table.FSWTabDictCache(filename=dictpath)

        try:
            filename = dictCache.filename
        except IOError as e:
            msg = 'Could not load default table dictionary "%s": %s'
            log.error(msg, filename, str(e))
        fswtabdict  = table.FSWTabDict(filename)
    else:
        fswtabdict  = table.getDefaultFSWTabDict()

    # Check if cmddict exists
    if fswtabdict is not None:
        # Write out the table file using the command dictionary
        table.writeToBinary(fswtabdict, tabletype, tabfile, verbose, outbin=args.binfile)

    log.end()
Esempio n. 4
0
    def test_table_duplicate_enum_load(self):
        test_table = """
        - !FSWTable
          name: test_type
          delimiter: ","
          header:
            - !FSWColumn
              name: MAGIC_NUM
              desc: The first column in our header
              format: "%x"
              units: none
              type:  U8
              bytes: 0

          columns:
            - !FSWColumn
              name: COLUMN_THREE
              desc: Third FSW Table Column
              format: "%u"
              units: none
              type:  U8
              bytes: 4
              enum:
                0: TEST_ENUM_0
                1: TEST_ENUM_1
                2: TEST_ENUM_2
                3: TEST_ENUM_3
                4: TEST_ENUM_0
        """

        with TestFile("test_table_dupe_enum.yaml", "wt") as temp_test_file:
            with open(temp_test_file, "w") as infile:
                assert infile.write(test_table)

            with self.assertLogs("ait", level="ERROR") as cm:
                tabdict = table.FSWTabDict(temp_test_file)
                assert len(cm.output) == 1
Esempio n. 5
0
def testTabDefnAndWrite():
    '''Test table definition'''
    coldefn = table.FSWColDefn(
        me='test_col',
        type='U8',
        bytes=4,
        format='%u',
        units='none',
        items=4,
        enum=Season,
    )
    coldefn2 = table.FSWColDefn(
        name='test_col2',
        type='U8',
        bytes=1,
        format='%u',
        units='none',
        items=4,
        enum=Color,
    )
    tabledefn = table.FSWTabDefn(
        name='test_table',
        delimiter='-',
        uptype=1,
        size=8000,
        rows=10,
        fswheaderdefns=None,
        coldefns=[coldefn, coldefn2],
    )
    fileholder = TestTableWriter()
    fileholder.writeTempFile()

    # Test that the table was created properly
    assert tabledefn.name is 'test_table'
    assert tabledefn.delimiter is '-'
    assert tabledefn.uptype is 1
    assert tabledefn.size is 8000
    assert tabledefn.rows is 10
    assert tabledefn.coldefns[0] is coldefn
    assert tabledefn.coldefns[1] is coldefn2

    # Write table to text file
    stream = open(TmpFilename, 'rw')
    outstream = open('tempfile', 'wr')

    # Test that the text file was created and did not exit with error code
    assert tabledefn.toText(stream, outstream, 1, 0.0) is None

    # Close the write to text
    stream.close()
    outstream.close()

    # Write table to binary file
    stream = open(TmpFilename, 'rw')
    outstream = open('tempfileb', 'wr')

    # Version in toBinary does not appear to be handled properly
    #assert tabledefn.toBinary('tempfile', stream, outstream, 1, 0.0) is None

    # Create a new table dictionary
    tabdict = table.FSWTabDict()
    tabdict.add(tabledefn)
    tabdict.create('test', {'colnames': tabledefn.coldefns})

    # Load a table definition to the dictionary
    tabdict.load(
        os.path.join(os.path.dirname(__file__), "testdata", "val",
                     "testCmdValidator6.yaml"))

    # Assert writing to text does not exit with an error code
    assert table.writeToText(tabdict, 'test_table', 'tempfileb', 0,
                             0.0) is None

    #having trouble with getting version from TmpFilename
    #assert table.writeToBinary(tabdict,'test_table',TmpFilename,0) is None

    stream.close()
    outstream.close()

    os.unlink('tempfile')
    os.unlink('tempfileb')
    os.unlink('test_table_table00.txt')
    fileholder.tearDown()
Esempio n. 6
0
 def setUpClass(cls):
     # The TestFile class is in util.py uses tempfile.NamedTemporaryFile() to create
     # a temporary file that will be automatically deleted at the end of the tests
     with TestFile(test_table, "rt") as file_name:
         cls.tabdict = table.FSWTabDict(file_name)
Esempio n. 7
0
 def setUpClass(cls):
     with TestFile(test_table, "rt") as file_name:
         cls.tabdict = table.FSWTabDict(file_name)