def test_laziness(): def crash_after_first_val(): yield 1 raise Exception("oops, iterated past first value") repeated_use = CachedIterable(crash_after_first_val()) assert first(repeated_use) == 1 assert first(repeated_use) == 1
def __init__(self, coinbase: Address, timestamp: int, block_number: int, difficulty: int, gas_limit: int, prev_hashes: Iterable[Hash32]) -> None: self._coinbase = coinbase self._timestamp = timestamp self._block_number = block_number self._difficulty = difficulty self._gas_limit = gas_limit self._prev_hashes = CachedIterable(prev_hashes)
def __init__(self, coinbase: Address, timestamp: int, block_number: BlockNumber, difficulty: int, gas_limit: int, prev_hashes: Iterable[Hash32], chain_id: int, base_fee_per_gas: Optional[int] = None) -> None: self._coinbase = coinbase self._timestamp = timestamp self._block_number = block_number self._difficulty = difficulty self._gas_limit = gas_limit self._prev_hashes = CachedIterable(prev_hashes) self._chain_id = chain_id self._base_fee_per_gas = base_fee_per_gas
def test_cached_generator(): use_once = itertools.count() repeated_use = CachedIterable(use_once) for find_val in [1, 0, 10, 5]: assert find_val == nth(find_val, repeated_use)
def test_cached_generator_iterable(): input_vals = [2] repeated_use = CachedIterable(input_vals) assert list(repeated_use) == input_vals assert list(repeated_use) == input_vals