Example #1
0
 def test_create_and_serialize_index(self):
     """GribIndex can be saved to file, file can be added to index."""
     with GribIndex(TESTGRIB, TEST_KEYS) as idx:
         idx.write(TEST_INDEX)
     with GribIndex(file_index=TEST_INDEX) as idx:
         idx.add(TESTGRIB)
     os.unlink(TEST_INDEX)
Example #2
0
 def test_index_comprehension(self):
     """GribIndex understands underlying GRIB index properly."""
     with GribIndex(TESTGRIB, TEST_KEYS) as idx:
         self.assertEqual(idx.size(TEST_KEYS[1]), 5)
         self.assertSequenceEqual(idx.values(TEST_KEYS[1]), TEST_STEPRANGE)
         with self.assertRaises(IndexNotSelectedError):
             # Note: The following will issue a message to stderr:
             #   ECCODES ERROR   :  please select a value for index key "dataDate"
             # This is expected behaviour
             idx.select({TEST_KEYS[1]: TEST_VALUES[0]})
         # Now it will be OK as we have selected all necessary keys
         idx.select(SELECTION_DICTIONARY)
         self.assertEqual(len(idx.open_messages), 1)
Example #3
0
 def test_memory_management(self):
     """GribIndex closes GribMessages properly."""
     with GribIndex(TESTGRIB, TEST_KEYS) as idx:
         idx.select(SELECTION_DICTIONARY)
         self.assertEqual(len(idx.open_messages), 1)
     self.assertEqual(len(idx.open_messages), 0)