Best Python code snippet using hypothesis
test_random.py
Source:test_random.py
...7from .base_test import BaseTestCase, unittest8from ..random import seed_all9class TestSeedAll(BaseTestCase):10 def test_builtin(self):11 seed_all(0)12 x1 = random.randint(0, 1000000)13 x2 = random.randint(0, 1000000)14 self.assertTrue(x1 != x2)15 seed_all(1)16 x3 = random.randint(0, 1000000)17 self.assertTrue(x1 != x3)18 seed_all(0)19 x4 = random.randint(0, 1000000)20 self.assertTrue(x1 == x4)21 def test_numpy(self):22 seed_all(0)23 x1 = np.random.randint(0, 1000000)24 x2 = np.random.randint(0, 1000000)25 self.assertTrue(x1 != x2)26 seed_all(1)27 x3 = np.random.randint(0, 1000000)28 self.assertTrue(x1 != x3)29 seed_all(0)30 x4 = np.random.randint(0, 1000000)31 self.assertTrue(x1 == x4)32 def test_numpy2(self):33 seed_all(0)34 self.assert_equal(np.random.randint(1000), 684)35 seed_all(4294967295)36 self.assert_equal(np.random.randint(1000), 419)37 def test_torch_cpu(self):38 seed_all(0)39 x1 = torch.randint(0, 1000000, (1,))40 x2 = torch.randint(0, 1000000, (1,))41 self.assertTrue((x1 != x2).item())42 seed_all(1)43 x3 = torch.randint(0, 1000000, (1,))44 self.assertTrue((x1 != x3).item())45 seed_all(0)46 x4 = torch.randint(0, 1000000, (1,))47 self.assert_array_equal(x1, x4)48 def test_seed_none(self):49 seed_all(None)50 random.randint(0, 1000000)51 np.random.randint(0, 1000000)...
seed.py
Source:seed.py
2import numpy as np3import os4import random5import torch6def seed_all(seed=None):7 if seed is None:8 seed = (9 os.getpid()10 + int(datetime.now().strftime("%S%f"))11 + int.from_bytes(os.urandom(2), "big")12 )13 print("Using a generated random seed {}".format(seed))14 torch.manual_seed(seed)15 np.random.seed(seed)16 random.seed(seed)17 os.environ["PYTHONHASHSEED"] = str(seed)18def worker_init_reset_seed(worker_id):19 initial_seed = torch.initial_seed() % 2 ** 31...
__init__.py
Source:__init__.py
...5seed_commands = AppGroup('seed')6# Creates the `flask seed all` command7@seed_commands.command('all')8def seed():9 seed_all()10 # Add other seed functions here11# Creates the `flask seed undo` command12@seed_commands.command('undo')13def undo():14 undo_seed_all()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!