def test_valid_clip_latitudes(self): future = Future() new_value = not future.clip_latitudes msg = "'Future' property 'clip_latitudes' is deprecated" with self.assertWarnsRegexp(msg): future.clip_latitudes = new_value self.assertEqual(future.clip_latitudes, new_value)
def test_invalid_arg(self): future = Future() with self.assertRaises(AttributeError): with future.context(this_does_not_exist=True): # Don't need to do anything here... the context manager # will (assuming it's working!) have already raised the # exception we're looking for. pass
def test_no_args(self): future = Future(cell_datetime_objects=False) self.assertFalse(future.cell_datetime_objects) with future.context(): self.assertFalse(future.cell_datetime_objects) future.cell_datetime_objects = True self.assertTrue(future.cell_datetime_objects) self.assertFalse(future.cell_datetime_objects)
def test_cell_datetime_objects(self): future = Future() new_value = not future.cell_datetime_objects with warnings.catch_warnings(record=True) as warn: warnings.simplefilter('always') future.cell_datetime_objects = new_value self.assertEqual(future.cell_datetime_objects, new_value) exp_wmsg = "'Future' property 'cell_datetime_objects' is deprecated" six.assertRegex(self, str(warn[0]), exp_wmsg)
def patched_future(value=True, error=False): # This ensures that there exists a flag in Future to test against. future = Future() future.__dict__['example_future_flag'] = value if error: future.deprecated_options['example_future_flag'] = 'error' else: future.deprecated_options['example_future_flag'] = 'warning' return future
def test_with_arg(self): # Catch the deprecation when explicitly setting `cell_datetime_objects` # as the test is still useful even though the Future property is # deprecated. with warnings.catch_warnings(): warnings.simplefilter('ignore') future = Future(cell_datetime_objects=False) self.assertFalse(future.cell_datetime_objects) with future.context(cell_datetime_objects=True): self.assertTrue(future.cell_datetime_objects) self.assertFalse(future.cell_datetime_objects)
def test_exception(self): # Check that an interrupted context block restores the initial state. class LocalTestException(Exception): pass future = Future(cell_datetime_objects=False) try: with future.context(cell_datetime_objects=True): raise LocalTestException() except LocalTestException: pass self.assertEqual(future.cell_datetime_objects, False)
def test_exception(self): # Check that an interrupted context block restores the initial state. class LocalTestException(Exception): pass # Catch the deprecation when explicitly setting `cell_datetime_objects` # as the test is still useful even though the Future property is # deprecated. with warnings.catch_warnings(): warnings.simplefilter('ignore') future = Future(cell_datetime_objects=False) try: with future.context(cell_datetime_objects=True): raise LocalTestException() except LocalTestException: pass self.assertEqual(future.cell_datetime_objects, False)
def test_netcdf_promote(self): future = Future() exp_emsg = "'Future' property 'netcdf_promote' is deprecated" with self.assertWarnsRegexp(exp_emsg): future.netcdf_promote = True
def test_invalid_netcdf_promote(self): future = Future() exp_emsg = "'Future' property 'netcdf_promote' has been deprecated" with self.assertRaisesRegexp(AttributeError, exp_emsg): future.netcdf_promote = False
def test_invalid_attribute(self): future = Future() with self.assertRaises(AttributeError): future.numberwang = 7
def test_valid_clip_latitudes(self): future = Future() new_value = not future.clip_latitudes future.clip_latitudes = new_value self.assertEqual(future.clip_latitudes, new_value)
def test_valid_strict_grib_load(self): future = Future() new_value = not future.strict_grib_load future.strict_grib_load = new_value self.assertEqual(future.strict_grib_load, new_value)
def test_valid_cell_datetime_objects(self): future = Future() new_value = not future.cell_datetime_objects future.cell_datetime_objects = new_value self.assertEqual(future.cell_datetime_objects, new_value)
def test_valid_netcdf_no_unlimited(self): future = Future() new_value = not future.netcdf_no_unlimited future.netcdf_no_unlimited = new_value self.assertEqual(future.netcdf_no_unlimited, new_value)
def test_netcdf_no_unlimited(self): future = Future() exp_emsg = "'Future' property 'netcdf_no_unlimited' is deprecated" with self.assertWarnsRegexp(exp_emsg): future.netcdf_no_unlimited = True
def test_invalid_netcdf_no_unlimited(self): future = Future() exp_emsg = \ "'Future' property 'netcdf_no_unlimited' has been deprecated" with self.assertRaisesRegexp(AttributeError, exp_emsg): future.netcdf_no_unlimited = False