def test_config_load_multiple_explicit_configfiles(self): """Test more specific config overrides less specific one, on a key by key basis, in a list of explicitly given files.""" file1 = u""" [alpha] endpoint = alpha solver = DW_2000Q_1 """ file2 = u""" [alpha] solver = DW_2000Q_2 """ with mock.patch('dwave.cloud.config.open', create=True) as m: m.side_effect = [ iterable_mock_open(file1)(), iterable_mock_open(file2)() ] section = load_config(config_file=['file1', 'file2'], profile='alpha') m.assert_has_calls( [mock.call('file1', 'r'), mock.call('file2', 'r')]) self.assertEqual(section['endpoint'], 'alpha') self.assertEqual(section['solver'], 'DW_2000Q_2')
def test_backoff_constant(self): """Constant retry back-off.""" # 1s delay before a retry backoff = 1 with mock.patch('time.sleep') as sleep: @retried(retries=2, backoff=backoff) def f(): raise ValueError with self.assertRaises(ValueError): f() calls = [mock.call(backoff), mock.call(backoff)] sleep.assert_has_calls(calls)
def test_backoff_func(self): """Retry back-off defined via callable.""" def backoff(retry): return 2**retry with mock.patch('time.sleep') as sleep: @retried(retries=3, backoff=backoff) def f(): raise ValueError with self.assertRaises(ValueError): f() calls = [ mock.call(backoff(1)), mock.call(backoff(2)), mock.call(backoff(3)) ] sleep.assert_has_calls(calls)
def test_backoff_seq(self): """Retry back-off defined via list.""" # progressive delay backoff = [1, 2, 3] with mock.patch('time.sleep') as sleep: @retried(retries=3, backoff=backoff) def f(): raise ValueError with self.assertRaises(ValueError): f() calls = [mock.call(b) for b in backoff] sleep.assert_has_calls(calls)