mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Improved arguments and structures comparison
This commit is contained in:
		
							parent
							
								
									c792923429
								
							
						
					
					
						commit
						bd207b5f06
					
				|  | @ -18,6 +18,14 @@ class Argument(OrderedType): | |||
|         self.default_value = default_value | ||||
|         self.description = description | ||||
| 
 | ||||
|     def __eq__(self, other): | ||||
|         return isinstance(other, Argument) and ( | ||||
|             self.name == other.name, | ||||
|             self.type == other.type, | ||||
|             self.default_value == other.default_value, | ||||
|             self.description == other.description | ||||
|         ) | ||||
| 
 | ||||
| 
 | ||||
| def to_arguments(args, extra_args): | ||||
|     from .unmountedtype import UnmountedType | ||||
|  |  | |||
|  | @ -27,6 +27,13 @@ class List(Structure): | |||
|     def __str__(self): | ||||
|         return '[{}]'.format(self.of_type) | ||||
| 
 | ||||
|     def __eq__(self, other): | ||||
|         return isinstance(other, List) and ( | ||||
|             self.of_type == other.of_type and | ||||
|             self.args == other.args and | ||||
|             self.kwargs == other.kwargs | ||||
|         ) | ||||
| 
 | ||||
| 
 | ||||
| class NonNull(Structure): | ||||
|     ''' | ||||
|  | @ -49,3 +56,10 @@ class NonNull(Structure): | |||
| 
 | ||||
|     def __str__(self): | ||||
|         return '{}!'.format(self.of_type) | ||||
| 
 | ||||
|     def __eq__(self, other): | ||||
|         return isinstance(other, NonNull) and ( | ||||
|             self.of_type == other.of_type and | ||||
|             self.args == other.args and | ||||
|             self.kwargs == other.kwargs | ||||
|         ) | ||||
|  |  | |||
							
								
								
									
										26
									
								
								graphene/types/tests/test_argument.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								graphene/types/tests/test_argument.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| import pytest | ||||
| 
 | ||||
| from ..argument import Argument | ||||
| from ..structures import NonNull | ||||
| from ..scalars import String | ||||
| 
 | ||||
| 
 | ||||
| def test_argument(): | ||||
|     arg = Argument(String, default_value='a', description='desc', name='b') | ||||
|     assert arg.type == String | ||||
|     assert arg.default_value == 'a' | ||||
|     assert arg.description == 'desc' | ||||
|     assert arg.name == 'b' | ||||
| 
 | ||||
| 
 | ||||
| def test_argument_comparasion(): | ||||
|     arg1 = Argument(String, name='Hey', description='Desc', default_value='default') | ||||
|     arg2 = Argument(String, name='Hey', description='Desc', default_value='default') | ||||
| 
 | ||||
|     assert arg1 == arg2 | ||||
|     assert arg1 != String() | ||||
| 
 | ||||
| 
 | ||||
| def test_argument_required(): | ||||
|     arg = Argument(String, required=True) | ||||
|     assert arg.type == NonNull(String) | ||||
							
								
								
									
										44
									
								
								graphene/types/tests/test_structures.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								graphene/types/tests/test_structures.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,44 @@ | |||
| import pytest | ||||
| 
 | ||||
| from ..structures import List, NonNull | ||||
| from ..scalars import String | ||||
| 
 | ||||
| 
 | ||||
| def test_list(): | ||||
|     _list = List(String) | ||||
|     assert _list.of_type == String | ||||
|     assert str(_list) == '[String]' | ||||
| 
 | ||||
| 
 | ||||
| def test_nonnull(): | ||||
|     nonnull = NonNull(String) | ||||
|     assert nonnull.of_type == String | ||||
|     assert str(nonnull) == 'String!' | ||||
| 
 | ||||
| 
 | ||||
| def test_list_comparasion(): | ||||
|     list1 = List(String) | ||||
|     list2 = List(String) | ||||
|     list3 = List(None) | ||||
| 
 | ||||
|     list1_argskwargs = List(String, None, b=True) | ||||
|     list2_argskwargs = List(String, None, b=True) | ||||
| 
 | ||||
|     assert list1 == list2 | ||||
|     assert list1 != list3 | ||||
|     assert list1_argskwargs == list2_argskwargs | ||||
|     assert list1 != list1_argskwargs | ||||
| 
 | ||||
| 
 | ||||
| def test_nonnull_comparasion(): | ||||
|     nonnull1 = NonNull(String) | ||||
|     nonnull2 = NonNull(String) | ||||
|     nonnull3 = NonNull(None) | ||||
| 
 | ||||
|     nonnull1_argskwargs = NonNull(String, None, b=True) | ||||
|     nonnull2_argskwargs = NonNull(String, None, b=True) | ||||
| 
 | ||||
|     assert nonnull1 == nonnull2 | ||||
|     assert nonnull1 != nonnull3 | ||||
|     assert nonnull1_argskwargs == nonnull2_argskwargs | ||||
|     assert nonnull1 != nonnull1_argskwargs | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user