def test_application_spec_invariants(): s = Service(commands=['command'], resources=Resources(memory=1024, vcores=1)) # No services with pytest.raises(ValueError): ApplicationSpec(name='dask', queue='default', services={}) for k, v in [('name', 1), ('queue', 1), ('tags', 1), ('tags', {1, 2, 3}), ('max_attempts', 'foo')]: with pytest.raises(TypeError): ApplicationSpec(services={'service': s}, **{k: v}) with pytest.raises(ValueError): ApplicationSpec(max_attempts=0, services={'service': s}) r = Resources(memory=1024, vcores=1) c = ['commands'] # Unknown dependency name with pytest.raises(ValueError): ApplicationSpec( services={ 'a': s, 'b': Service(resources=r, commands=c, depends=['c', 'd']) }) # Cyclical dependencies with pytest.raises(ValueError): ApplicationSpec( services={ 'a': Service(resources=r, commands=c, depends=['c']), 'b': Service(resources=r, commands=c, depends=['a']), 'c': Service(resources=r, commands=c, depends=['b']) })
def test_application_spec(): r = Resources(memory=1024, vcores=1) c = ['commands'] s1 = Service(resources=r, commands=c, files={'file': File(source='/test/path')}) s2 = Service(resources=r, commands=c, files={'file': File(source='/test/path', size=1024)}) spec1 = ApplicationSpec(services={'service': s1}) spec2 = ApplicationSpec(services={'service': s2}) check_specification_methods(spec1, spec2)
def test_application_spec_from_any(tmpdir): spec = ApplicationSpec.from_yaml(app_spec) spec_path = os.path.join(str(tmpdir), 'test.yaml') spec.to_file(spec_path) spec_dict = spec.to_dict() for obj in [spec, spec_path, spec_dict]: spec2 = ApplicationSpec._from_any(obj) assert spec == spec2 with pytest.raises(TypeError): ApplicationSpec._from_any(None)
def test_application_spec(): r = Resources(memory=1024, vcores=1) s1 = Service(resources=r, script="script", files={'file': File(source='/test/path')}) s2 = Service(resources=r, script="script", files={'file': File(source='/test/path', size=1024)}) spec1 = ApplicationSpec(name='test', queue='testqueue', node_label='testlabel', services={'service': s1}) spec2 = ApplicationSpec(master=Master(script='script', resources=r)) spec3 = ApplicationSpec(services={'service': s2}) check_specification_methods(spec1, spec3) check_specification_methods(spec2, spec3)
def test_to_file_from_file(tmpdir): spec = ApplicationSpec.from_yaml(app_spec) for name, format in [('test.yaml', 'infer'), ('test.json', 'infer'), ('test2.yaml', 'json')]: path = os.path.join(str(tmpdir), name) assert not os.path.exists(path) spec.to_file(path, format=format) assert os.path.exists(path) spec2 = ApplicationSpec.from_file(path, format=format) assert spec == spec2 for name, format in [('bad.yaml', 'invalid'), ('bad.invalid', 'infer')]: path = os.path.join(str(tmpdir), name) with pytest.raises(ValueError): spec.to_file(path, format=format) assert not os.path.exists(path)
def test_application_spec_from_yaml(): spec = ApplicationSpec.from_yaml(app_spec) assert isinstance(spec, ApplicationSpec) assert spec.name == 'test' assert spec.queue == 'default' assert spec.tags == {'tag1', 'tag2'} assert spec.max_attempts == 2 assert isinstance(spec.services, dict) assert isinstance(spec.services['service_1'], Service)
def test_application_spec_from_yaml(): spec = ApplicationSpec.from_yaml(app_spec) assert isinstance(spec, ApplicationSpec) assert spec.name == 'test' assert spec.queue == 'default' assert spec.node_label == 'cpu' assert spec.tags == {'tag1', 'tag2'} assert spec.file_systems == ['hdfs://preprod'] assert spec.max_attempts == 2 assert spec.acls.enable assert spec.acls.view_users == ['*'] assert isinstance(spec.services, dict) assert isinstance(spec.services['service_1'], Service)
def test_application_spec_roundtrip(): spec = ApplicationSpec.from_yaml(app_spec) spec2 = ApplicationSpec.from_yaml(spec.to_yaml()) assert spec == spec2