Ejemplo n.º 1
0
class TestDbfConversionFile(TestCase):
    def setUp(self):
        sih = os.path.join(TEST_RESOURCE_DIR, 'TAB_SIH.zip')
        self.loader = ConversionLoader(ZipFileLoader(sih),
                                       tabsus.DEFAULT_ENCODING)

    def test_index_case_insensitive(self):
        dbf = self.loader.load('DBF/cid10.dbf')

        index1 = dbf.get_index_by('CD_COD')
        self.assertIsNotNone(index1)
        print(index1['A000'])
        self.assertIsNotNone(index1['A000'])
        self.assertEqual('A00.0 Colera dev Vibrio cholerae 01 biot cholerae',
                         index1['A000']['CD_DESCR'])

        index2 = dbf.get_index_by('cd_cod')
        self.assertEqual(index1, index2)

        self.assertEqual(index1, dbf.get_index_by(
            'CD_1234'))  # undefined column, use the first one (CD_COD)
        self.assertNotEqual(index1, dbf.get_index_by('CD_DESCR'))

    def test_mapping_not_found(self):
        dbf = self.loader.load('DBF/cid10.dbf')
        self.assertIsNone(dbf.find_record('CD_COD', '1234'))
        self.assertIsNotNone(dbf.find_record('CD_COD', 'A000'))
        self.assertIsNotNone(dbf.find_record('', 'A000'))
Ejemplo n.º 2
0
    def test_load_dbf_zip(self):
        sih = os.path.join(TEST_RESOURCE_DIR, 'TAB_SIH.zip')

        cnv_loader = ConversionLoader(sih, tabsus.DEFAULT_ENCODING)
        cnv = cnv_loader.load('dbf/cid10.dbf')
        self.assertTrue(isinstance(cnv, DbfConversionFile))

        print(cnv.records)
Ejemplo n.º 3
0
    def test_load_unsupported(self):
        sih = os.path.join(TEST_RESOURCE_DIR, 'TAB_SIH.zip')

        cnv_loader = ConversionLoader(sih, tabsus.DEFAULT_ENCODING)
        with self.assertRaises(NotImplementedError):
            cnv_loader.load('Documentos/LEIAME.pdf')
Ejemplo n.º 4
0
    def test_load_zip(self):
        sih = os.path.join(TEST_RESOURCE_DIR, 'TAB_SIH.zip')

        cnv_loader = ConversionLoader(sih, tabsus.DEFAULT_ENCODING)
        cnv = cnv_loader.load('cnv/regiao.cnv')
        self.assertTrue(isinstance(cnv, CnvConversionFile))
Ejemplo n.º 5
0
 def __init__(self, root, encoding=tabsus.DEFAULT_ENCODING):
     self.root = root
     self.encoding = encoding
     self.file_loader = FileLoader.open(root)
     self.cnv_loader = ConversionLoader(self.file_loader, encoding)
Ejemplo n.º 6
0
 def setUp(self):
     sih = os.path.join(TEST_RESOURCE_DIR, 'TAB_SIH.zip')
     self.loader = ConversionLoader(ZipFileLoader(sih),
                                    tabsus.DEFAULT_ENCODING)