def process_type(type_str): normalized_type_str = normalize(type_str) abi_type = parse(normalized_type_str) type_str_repr = repr(type_str) if type_str != normalized_type_str: type_str_repr = '{} (normalized to {})'.format( type_str_repr, repr(normalized_type_str), ) if isinstance(abi_type, TupleType): raise ValueError( "Cannot process type {}: tuple types not supported".format( type_str_repr, )) abi_type.validate() sub = abi_type.sub if isinstance(sub, tuple): sub = 'x'.join(map(str, sub)) elif isinstance(sub, int): sub = str(sub) else: sub = '' arrlist = abi_type.arrlist if isinstance(arrlist, tuple): arrlist = list(map(list, arrlist)) else: arrlist = [] return abi_type.base, sub, arrlist
def get_strategy(self, type_str: TypeStr) -> st.SearchStrategy: """ Returns a hypothesis strategy for the given ABI type. :param type_str: The canonical string representation of the ABI type for which a hypothesis strategy should be returned. :returns: A hypothesis strategy for generating Python values that are encodable as values of the given ABI type. """ registration = self._get_registration(self._strategies, type_str) if isinstance(registration, st.SearchStrategy): # If a hypothesis strategy was registered, just return it return registration else: # Otherwise, assume the factory is a callable. Call it with the abi # type to get an appropriate hypothesis strategy. normalized_type_str = normalize(type_str) abi_type = parse(normalized_type_str) strategy = registration(abi_type, self) return strategy
def test_normalizing_and_parsing_works(type_str, expected_type): assert parse(normalize(type_str)) == expected_type
def test_normalize(type_str, normalized): assert normalize(type_str) == normalized
def test_normalizing_and_parsing_works(type_str, expected_type): assert parse(normalize(type_str)) == expected_type
def test_normalize(type_str, normalized): assert normalize(type_str) == normalized