mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 16:07:27 +03:00 
			
		
		
		
	Improved options testing and coverage
This commit is contained in:
		
							parent
							
								
									24b85d318c
								
							
						
					
					
						commit
						e1e24327b0
					
				|  | @ -19,18 +19,18 @@ class Options(object): | |||
|         for attr_name, value in defaults.items(): | ||||
|             if attr_name in meta_attrs: | ||||
|                 value = meta_attrs.pop(attr_name) | ||||
|             elif hasattr(meta, attr_name): | ||||
|                 value = getattr(meta, attr_name) | ||||
|             setattr(self, attr_name, value) | ||||
| 
 | ||||
|         # If meta_attrs is not empty, it implicit means | ||||
|         # If meta_attrs is not empty, it implicitly means | ||||
|         # it received invalid attributes | ||||
|         if meta_attrs: | ||||
|             raise TypeError( | ||||
|                 "Invalid attributes: {}".format( | ||||
|                     ','.join(meta_attrs.keys()) | ||||
|                     ', '.join(sorted(meta_attrs.keys())) | ||||
|                 ) | ||||
|             ) | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         return '<Meta \n{} >'.format(props(self)) | ||||
|         options_props = props(self) | ||||
|         props_as_attrs = ' '.join(['{}={}'.format(key, value) for key, value in options_props.items()]) | ||||
|         return '<Options {}>'.format(props_as_attrs) | ||||
|  |  | |||
							
								
								
									
										30
									
								
								graphene/types/tests/test_options.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								graphene/types/tests/test_options.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,30 @@ | |||
| import pytest | ||||
| 
 | ||||
| from ..options import Options | ||||
| 
 | ||||
| 
 | ||||
| def test_options(): | ||||
|     class BaseOptions: | ||||
|         option_1 = False | ||||
|         name = True | ||||
|     meta = Options(BaseOptions, name=False, option_1=False) | ||||
|     assert meta.name == True | ||||
|     assert meta.option_1 == False | ||||
| 
 | ||||
| 
 | ||||
| def test_options_extra_attrs(): | ||||
|     class BaseOptions: | ||||
|         name = True | ||||
|         type = True | ||||
|      | ||||
|     with pytest.raises(Exception) as exc_info: | ||||
|         meta = Options(BaseOptions) | ||||
| 
 | ||||
|     assert str(exc_info.value) == 'Invalid attributes: name, type' | ||||
| 
 | ||||
| 
 | ||||
| def test_options_repr(): | ||||
|     class BaseOptions: | ||||
|         name = True | ||||
|     meta = Options(BaseOptions, name=False) | ||||
|     assert repr(meta) == '<Options name=True>' | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user