import unittest
import yr
class TestInvokeOptions(unittest.TestCase):
def setUp(self):
@yr.invoke
def add(x):
return x + 1
self.add = add
self.opts = yr.InvokeOptions()
def test_option_function_name(self):
self.opts.name = 999
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_preferred_anti_other_labels(self):
self.opts.preferred_anti_other_labels = ''
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_preferred_priority(self):
self.opts.preferred_priority = ''
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_namespace(self):
self.opts.namespace = 11
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_dict(self):
self.opts.env_vars = []
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_namespace_true(self):
self.opts.namespace = "aaa"
result = self.add.options(self.opts)
self.assertIsNotNone(result)
def test_option_function_custom_resources(self):
self.opts.custom_resources = []
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_custom_extensions(self):
self.opts.custom_extensions = []
with self.assertRaises(TypeError):
self.add.options(self.opts)
def test_option_function_recover_retry_times_range(self):
self.opts.recover_retry_times = -1
with self.assertRaises(ValueError):
self.add.options(self.opts)
def test_option_function_max_instances_range(self):
self.opts.max_instances = 9**20
with self.assertRaises(ValueError):
self.add.options(self.opts)
def test_option_function_max_invoke_latency_range(self):
self.opts.max_invoke_latency = 9**20
with self.assertRaises(ValueError):
self.add.options(self.opts)
def test_option_function_min_instances_range(self):
self.opts.min_instances = -1
with self.assertRaises(ValueError):
self.add.options(self.opts)
if __name__ == '__main__':
unittest.main()