def test_get_all_invalid(self): # test the case when one of the files is invalid container = { 'a.csv': FileObject('a.csv', ''), 'a.mdata': FileObject('a.mdata', '') } self.assertEqual(list(MemTable.get_all(container)), [])
def test_could_not_extract_fieldnames(self): bad_metadata = '''\ <?xml version="1.0" encoding="utf-8"?> <vulnerabilityModel> <discreteVulnerabilitySet assetCategory="population" lossCategory="fatalities" vulnerabilitySetID="NPAGER" > <IML IMT="MMI"/> <discreteVulnerability probabilisticDistribution="LN" vulnerabilityFunctionID="AA" > <lossRatio /> </discreteVulnerability> </discreteVulnerabilitySet> </vulnerabilityModel> ''' # there is no coefficientsVariation node with self.assertRaises(InvalidFile) as e: MemTable.create('bad', bad_metadata, '') assert isinstance(e, ValueError), e
def test_getitem(self): tbl = MemTable.create('tbl', '<gmfSet/>', '''\ lon,lat,gmv 1.0,2.0,0.1 1.0,2.1,0.1 1.0,2.2,0.2 1.0,2.3,0.2 ''') # test that a Table object support the bracket notation self.assertEqual(tbl[0], {'lon': '1.0', 'lat': '2.0', 'gmv': '0.1'}) self.assertEqual(tbl[1], {'lon': '1.0', 'lat': '2.1', 'gmv': '0.1'}) self.assertEqual(tbl[2:4], [{'lon': '1.0', 'lat': '2.2', 'gmv': '0.2'}, {'lon': '1.0', 'lat': '2.3', 'gmv': '0.2'}])