def __reading_table(self, name, attrs):
     if self.__check_item_id("name", name):
         self.__start_reading_data()
     elif self.__check_item_id("description", name):
         self.__start_reading_data()
     elif self.__check_item_id("column", name):
         self.__status = READING_TABLE_COLUMN
         self.__currentColumn = TapColumn()
 def test_table_columns(self):
     table = TapTableMeta()
     c1 = TapColumn()
     c2 = TapColumn()
     table.add_column(c1)
     table.add_column(c2)
     res = table.get_columns()
     assert len(res) == 2, \
         "Num columns, expected: %d, found: %d" % (2, len(res))
Ejemplo n.º 3
0
def test_get_current_column_values_for_update():
    column = TapColumn(None)
    column.name = 'colname'
    column.flags = 0
    column.flag = None
    column.ucd = 'ucd'
    column.utype = 'utype'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert column_name == 'colname'
    assert flags is None
    assert indexed is False
    assert ucd == 'ucd'
    assert utype == 'utype'

    column.flags = '1'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Ra'
    assert indexed is True
    column.flags = '2'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Dec'
    assert indexed is True
    column.flags = '4'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Flux'
    assert indexed is False
    column.flags = '8'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Mag'
    assert indexed is False
    column.flags = '16'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'PK'
    assert indexed is True
    column.flags = '33'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Ra'
    assert indexed is True
    column.flags = '34'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Dec'
    assert indexed is True
    column.flags = '38'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Flux'
    assert indexed is False
    column.flags = '40'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'Mag'
    assert indexed is False
    column.flags = '48'
    column_name, flags, indexed, ucd, utype = \
        TapPlus.get_current_column_values_for_update(column)
    assert flags == 'PK'
    assert indexed is True
class TableSaxParser(xml.sax.ContentHandler):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.__internal_init()

    def __internal_init(self):
        self.__concatData = False
        self.__charBuffer = []
        self.__tables = []
        self.__status = 0
        self.__currentSchemaName = None
        self.__currentTable = None
        self.__currentColumn = None

    def __create_string_from_buffer(self):
        return Utils.util_create_string_from_buffer(self.__charBuffer)

    def __check_item_id(self, itemId, tmpValue):
        if str(itemId).lower() == str(tmpValue).lower():
            return True
        return False

    def __start_reading_data(self):
        self.__concatData = True
        del self.__charBuffer[:]

    def __stop_reading_data(self):
        self.__concatData = False

    def parseData(self, data):
        del self.__tables[:]
        self.__status = READING_SCHEMA
        xml.sax.parse(data, self)
        return self.__tables

    def startElement(self, name, attrs):
        if self.__status == READING_SCHEMA:
            self.__reading_schema(name, attrs)
        elif self.__status == READING_TABLE:
            self.__reading_table(name, attrs)
        elif self.__status == READING_TABLE_COLUMN:
            self.__reading_table_column(name, attrs)

    def endElement(self, name):
        if self.__status == READING_SCHEMA:
            self.__end_schema(name)
        elif self.__status == READING_TABLE:
            self.__end_table(name)
        elif self.__status == READING_TABLE_COLUMN:
            self.__end_table_column(name)

    def characters(self, content):
        if self.__concatData:
            self.__charBuffer.append(content)

    def __reading_schema(self, name, attrs):
        if self.__check_item_id("name", name):
            self.__start_reading_data()
        if self.__check_item_id("table", name):
            self.__status = READING_TABLE
            self.__currentTable = TapTableMeta()
            self.__currentTable.set_schema(self.__currentSchemaName)

    def __end_schema(self, name):
        if self.__check_item_id("name", name):
            self.__currentSchemaName = self.__create_string_from_buffer()
            self.__stop_reading_data()

    def __reading_table(self, name, attrs):
        if self.__check_item_id("name", name):
            self.__start_reading_data()
        elif self.__check_item_id("description", name):
            self.__start_reading_data()
        elif self.__check_item_id("column", name):
            self.__status = READING_TABLE_COLUMN
            self.__currentColumn = TapColumn()

    def __end_table(self, name):
        if self.__check_item_id("name", name):
            self.__stop_reading_data()
            self.__currentTable.set_name(self.__create_string_from_buffer())
        elif self.__check_item_id("description", name):
            self.__stop_reading_data()
            self.__currentTable.set_description(
                self.__create_string_from_buffer())
        elif self.__check_item_id("table", name):
            self.__tables.append(self.__currentTable)
            self.__status = READING_SCHEMA

    def __reading_table_column(self, name, attrs):
        if self.__check_item_id("name", name):
            self.__start_reading_data()
        elif self.__check_item_id("description", name):
            self.__start_reading_data()
        elif self.__check_item_id("unit", name):
            self.__start_reading_data()
        elif self.__check_item_id("ucd", name):
            self.__start_reading_data()
        elif self.__check_item_id("utype", name):
            self.__start_reading_data()
        elif self.__check_item_id("datatype", name):
            self.__start_reading_data()
        elif self.__check_item_id("flag", name):
            self.__start_reading_data()

    def __end_table_column(self, name):
        if self.__check_item_id("name", name):
            self.__currentColumn.set_name(self.__create_string_from_buffer())
            self.__stop_reading_data()
        elif self.__check_item_id("description", name):
            self.__currentColumn.set_description(
                self.__create_string_from_buffer())
            self.__stop_reading_data()
        elif self.__check_item_id("unit", name):
            self.__currentColumn.set_unit(self.__create_string_from_buffer())
            self.__stop_reading_data()
        elif self.__check_item_id("ucd", name):
            self.__currentColumn.set_ucd(self.__create_string_from_buffer())
            self.__stop_reading_data()
        elif self.__check_item_id("utype", name):
            self.__currentColumn.set_utype(self.__create_string_from_buffer())
            self.__stop_reading_data()
        elif self.__check_item_id("datatype", name):
            self.__currentColumn.set_data_type(
                self.__create_string_from_buffer())
            self.__stop_reading_data()
        elif self.__check_item_id("flag", name):
            self.__currentColumn.set_flag(self.__create_string_from_buffer())
            self.__stop_reading_data()
        if self.__check_item_id("column", name):
            self.__status = READING_TABLE
            self.__currentTable.add_column(self.__currentColumn)

    def __nothing(self, name, attrs):
        pass

    def get_table(self):
        if len(self.__tables) < 1:
            return None
        return self.__tables[0]

    def get_tables(self):
        return self.__tables
Ejemplo n.º 5
0
 def test_column(self):
     name = "name"
     arraysize = "arraysize"
     datatype = "datatype"
     flag = "flag"
     ucd = "ucd"
     utype = "utype"
     unit = "unit"
     description = "description"
     c = TapColumn()
     c.set_name(name)
     c.set_array_size(arraysize)
     c.set_data_type(datatype)
     c.set_flag(flag)
     c.set_ucd(ucd)
     c.set_unit(unit)
     c.set_utype(utype)
     c.set_description(description)
     assert c.get_name() == name, \
         "Invalid name, expected: %s, found: %s" % (name,
                                                    c.get_name())
     assert c.get_array_size() == arraysize, \
         "Invalid arraysize, expected: %s, found: %s" % (arraysize,
                                                         c.get_array_size())
     assert c.get_data_type() == datatype, \
         "Invalid datatype, expected: %s, found: %s" % (datatype,
                                                        c.get_data_type())
     assert c.get_flag() == flag, \
         "Invalid flag, expected: %s, found: %s" % (flag,
                                                    c.get_flag())
     assert c.get_ucd() == ucd, \
         "Invalid ucd, expected: %s, found: %s" % (ucd,
                                                   c.get_ucd())
     assert c.get_utype() == utype, \
         "Invalid utype, expected: %s, found: %s" % (utype,
                                                     c.get_utype())
     assert c.get_unit() == unit, \
         "Invalid unit, expected: %s, found: %s" % (unit,
                                                    c.get_unit())
     assert c.get_description() == description, \
         "Invalid description, expected: %s, found: %s" % (description,
                                                           c.get_description())
Ejemplo n.º 6
0
 def test_column(self):
     name = "name"
     arraysize = "arraysize"
     datatype = "datatype"
     flag = "flag"
     ucd = "ucd"
     utype = "utype"
     unit = "unit"
     description = "description"
     c = TapColumn()
     c.set_name(name)
     c.set_array_size(arraysize)
     c.set_data_type(datatype)
     c.set_flag(flag)
     c.set_ucd(ucd)
     c.set_unit(unit)
     c.set_utype(utype)
     c.set_description(description)
     assert c.get_name() == name, \
         "Invalid name, expected: %s, found: %s" % (name,
                                                    c.get_name())
     assert c.get_array_size() == arraysize, \
         "Invalid arraysize, expected: %s, found: %s" % (arraysize,
                                                         c.get_array_size())
     assert c.get_data_type() == datatype, \
         "Invalid datatype, expected: %s, found: %s" % (datatype,
                                                        c.get_data_type())
     assert c.get_flag() == flag, \
         "Invalid flag, expected: %s, found: %s" % (flag,
                                                    c.get_flag())
     assert c.get_ucd() == ucd, \
         "Invalid ucd, expected: %s, found: %s" % (ucd,
                                                   c.get_ucd())
     assert c.get_utype() == utype, \
         "Invalid utype, expected: %s, found: %s" % (utype,
                                                     c.get_utype())
     assert c.get_unit() == unit, \
         "Invalid unit, expected: %s, found: %s" % (unit,
                                                    c.get_unit())
     assert c.get_description() == description, \
         "Invalid description, expected: %s, found: %s" % (description,
                                                           c.get_description())