Ejemplo n.º 1
0
 def reify(self, davt):
     specifier = self.specifier_strategy.reify(davt.specifier)
     return DescriptorWithValue(
         specifier=specifier,
         template=davt.template,
         value=self.strategy(specifier).reify(davt.template),
         random=RandomWithSeed(davt.random),
     )
Ejemplo n.º 2
0
    def simplify(self, davt):
        random = RandomWithSeed(davt.random)
        for d in self.specifier_strategy.simplify(davt.specifier):
            new_template = self.strategy(
                self.specifier_strategy.reify(d)).draw_and_produce(
                    BuildContext(random))
            yield DescriptorWithValue(
                specifier=d,
                template=new_template,
                value=None,
                random=davt.random,
            )

        strat = self.strategy(self.specifier_strategy.reify(davt.specifier))

        for v in strat.simplify(davt.template):
            yield DescriptorWithValue(
                specifier=davt.specifier,
                template=v,
                value=None,
                random=davt.random,
            )
Ejemplo n.º 3
0
from .utils import make_random_trie

logger = logging.getLogger()

# produces a branch node with an extention node who's encoding is less than 32
# bytes in length so it is inlined.
EXAMPLE_37968 = 37968

# produces an top level extension node who's encoding is less than 32 bytes in
# length so it gets inlined.
EXAMPLE_809368 = 809368


@given(random=strategies.randoms())
@settings(max_examples=50)
@example(random=RandomWithSeed(EXAMPLE_37968))
@example(random=RandomWithSeed(EXAMPLE_809368))
def test_trie_sync(random):
    src_trie, contents = make_random_trie(random)

    dest_db = {}
    scheduler = HexaryTrieSync(src_trie.root_hash, dest_db, logger)
    requests = scheduler.next_batch()
    while len(requests) > 0:
        results = []
        for request in requests:
            results.append([request.node_key, src_trie.db[request.node_key]])
        scheduler.process(results)
        requests = scheduler.next_batch(10)
    dest_trie = HexaryTrie(dest_db, src_trie.root_hash)
    for key, value in contents.items():
Ejemplo n.º 4
0
 def reify(self, template):
     return RandomWithSeed(template)
Ejemplo n.º 5
0
 def pack(self, i):
     return RandomWithSeed(i)
Ejemplo n.º 6
0
def test_can_draw_from_a_random_with_seed():
    r = RandomWithSeed(0)
    s = one_of(booleans(), lists(booleans()))
    s.draw_and_produce(r)
Ejemplo n.º 7
0
 def produce(self, random, pv):
     return RandomWithSeed(random.getrandbits(128))