Exemplo n.º 1
0
def command_lookup(ns):
    """
    Command to lookup the given descriptors from command line
    """
    table_group = TableGroupCacheManager.get_table_group(
        ns.tables_root_directory, ns.master_table_number,
        ns.originating_centre, ns.originating_subcentre,
        ns.master_table_version, ns.local_table_version)
    flat_text_render = FlatTextRenderer()
    table_group.B.load_code_and_flag(
    )  # load the code and flag tables for additional details
    descriptors = table_group.descriptors_from_ids(
        *[d.strip() for d in ns.descriptors.split(',')])

    for descriptor in descriptors:
        if isinstance(descriptor, ElementDescriptor):
            print('{}, {}, {}, {}, {}'.format(
                flat_text_render.render(descriptor), descriptor.unit,
                descriptor.scale, descriptor.refval, descriptor.nbits))
            if ns.code_and_flag and descriptor.unit in (
                    UNITS_FLAG_TABLE, UNITS_CODE_TABLE,
                    UNITS_COMMON_CODE_TABLE_C1):
                code_and_flag = table_group.B.code_and_flag_for_descriptor(
                    descriptor)
                if code_and_flag:
                    for v, description in code_and_flag:
                        output = u'{:8d} {}'.format(v, description)
                        # With Python 2, some terminal utilities, e.g. more, redirect to file,
                        # cause errors when unicode string is printed. The fix is to encode
                        # them before print.
                        if six.PY2:
                            output = output.encode('utf-8', 'ignore')
                        print(output)
        else:
            print(flat_text_render.render(descriptor))
Exemplo n.º 2
0
class TablesTests(unittest.TestCase):

    def setUp(self):
        self.table_group = TableGroupCacheManager.get_table_group(master_table_version=29)
        self.flat_text_renderer = FlatTextRenderer()

    def tearDown(self):
        pass

    def test_table_group_01(self):
        template = self.table_group.lookup(340009)
        assert self.flat_text_renderer.render(template) == table_group_01_cmp
        assert flat_member_ids(template) == [
            1007, 1031, 2019, 2020, 4001, 4002, 4003, 4004, 4005, 4006, 5040,
            201136, 5041, 201000, 25071, 5001, 5001, 6001, 6001,
            107064, 106032, 8012, 8013, 8065, 8072, 13039, 40015]

    def test_table_group_02(self):
        template = self.table_group.lookup(340008)
        assert self.flat_text_renderer.render(template) == table_group_02_cmp