Beispiel #1
0
class TestIO(unittest.TestCase):
    FILETYPES = 'FRAGILITY VULNERABILITY EXPOSURE GMF'.split()

    def setUp(self):
        # create a temporary directory with different input files
        self.path = tempfile.mkdtemp()
        self.archive = Archive(self.path)

    def writefiles(self, ext):
        with self.archive.open('job.ini', 'w') as ini:
            ini.write('[general]\n')
            for ftype in self.FILETYPES:
                ini.write('%s_file=%s%s\n' % (ftype, ftype, ext))
                with self.archive.open(ftype + ext, 'w') as f:
                    f.write(globals()['TEST_%s' % ftype])

    def test_read_csv_files(self):
        self.writefiles('.csv')
        inp = read_calculator_input(self.path)
        self.assertEqual(len(inp['fragility']), 5)
        self.assertEqual(len(inp['vulnerability']), 2)
        self.assertEqual(len(inp['exposure']), 37)
        self.assertEqual(len(inp['gmf']), 12)

    def test_read_csv_gz_files(self):
        self.writefiles('.csv.gz')
        inp = read_calculator_input(self.path)
        self.assertEqual(len(inp['fragility']), 5)
        self.assertEqual(len(inp['vulnerability']), 2)
        self.assertEqual(len(inp['exposure']), 37)
        self.assertEqual(len(inp['gmf']), 12)

    def test_read_zip_file(self):
        self.writefiles('.csv')
        path = self.path + '.zip'
        zfile = zipfile.ZipFile(path, 'w')
        zfile.write(os.path.join(self.path, 'job.ini'), 'job.ini')
        for ftype in self.FILETYPES:
            zfile.write(os.path.join(self.path, ftype + '.csv'),
                        ftype + '.csv')
        zfile.close()
        inp = read_calculator_input(path)
        self.assertEqual(len(inp['fragility']), 5)
        self.assertEqual(len(inp['vulnerability']), 2)
        self.assertEqual(len(inp['exposure']), 37)
        self.assertEqual(len(inp['gmf']), 12)

    def tearDown(self):
        # remove the directory
        shutil.rmtree(self.path)
Beispiel #2
0
 def setUp(self):
     # create a temporary directory with different input files
     self.path = tempfile.mkdtemp()
     self.archive = Archive(self.path)