def test_keyword_of_fields(keyword, field_cls): s_f = StringField() n_f = NumberField() i_f = IntField() field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})]) assert field.get_schema() == {keyword: [n_f.get_schema()]} assert field.get_schema(role='role_1') == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert field.get_schema(role='role_2') == { keyword: [n_f.get_schema(), i_f.get_schema()] } field = field_cls( Var( { 'role_1': [n_f, Var({'role_1': s_f}), Var({'role_2': i_f})], 'role_2': [Var({'role_2': i_f})], }, propagate='role_1')) assert field.get_schema() == {keyword: []} assert field.get_schema(role='role_1') == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert field.get_schema(role='role_2') == {keyword: []}
def test_keyword_of_fields(keyword, field_cls): s_f = StringField() n_f = NumberField() i_f = IntField() field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})]) assert s(field.get_schema()) == {keyword: [n_f.get_schema()]} assert s(field.get_schema(role='role_1')) == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert s(field.get_schema(role='role_2')) == { keyword: [n_f.get_schema(), i_f.get_schema()] } field = field_cls( Var( { 'role_1': [n_f, Var({'role_1': s_f}), Var({'role_2': i_f})], 'role_2': [Var({'role_2': i_f})], }, propagate='role_1')) assert s(field.get_schema(role='role_1')) == { keyword: [n_f.get_schema(), s_f.get_schema()] } with pytest.raises(SchemaGenerationException): field.get_schema(role='role_2')
def test_keyword_of_fields(keyword, field_cls): s_f = StringField() n_f = NumberField() i_f = IntField() field = field_cls([n_f, Var(role_1=s_f), Var(role_2=i_f)]) assert field.get_schema() == { keyword: [n_f.get_schema()] } assert field.get_schema(role='role_1') == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert field.get_schema(role='role_2') == { keyword: [n_f.get_schema(), i_f.get_schema()] } field = field_cls(Var( role_1=[n_f, Var(role_1=s_f), Var(role_2=i_f)], role_2=[Var(role_2=i_f)], roles_to_pass_down=['role_1'] )) assert field.get_schema() == {keyword: []} assert field.get_schema(role='role_1') == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert field.get_schema(role='role_2') == {keyword: []}
def test_keyword_of_fields(keyword, field_cls): s_f = StringField() n_f = NumberField() i_f = IntField() field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})]) assert field.get_schema() == { keyword: [n_f.get_schema()] } assert field.get_schema(role='role_1') == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert field.get_schema(role='role_2') == { keyword: [n_f.get_schema(), i_f.get_schema()] } field = field_cls(Var({ 'role_1': [n_f, Var({'role_1': s_f}), Var({'role_2': i_f})], 'role_2': [Var({'role_2': i_f})], }, propagate='role_1')) assert field.get_schema() == {keyword: []} assert field.get_schema(role='role_1') == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert field.get_schema(role='role_2') == {keyword: []}
def test_keyword_of_fields(keyword, field_cls): s_f = StringField() n_f = NumberField() i_f = IntField() field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})]) assert s(field.get_schema()) == { keyword: [n_f.get_schema()] } assert s(field.get_schema(role='role_1')) == { keyword: [n_f.get_schema(), s_f.get_schema()] } assert s(field.get_schema(role='role_2')) == { keyword: [n_f.get_schema(), i_f.get_schema()] } field = field_cls(Var({ 'role_1': [n_f, Var({'role_1': s_f}), Var({'role_2': i_f})], 'role_2': [Var({'role_2': i_f})], }, propagate='role_1')) assert s(field.get_schema(role='role_1')) == { keyword: [n_f.get_schema(), s_f.get_schema()] } with pytest.raises(SchemaGenerationException): field.get_schema(role='role_2')