How to use get_random_number method in pytest-mock

Best Python code snippet using pytest-mock

ml_backend.py

Source:ml_backend.py Github

copy

Full Screen

...23 'Pts5', 'OR1', 'OR2', 'OR3', 'OR4', 'OR5', 'DR1', 'DR2', 'DR3',24 'DR4', 'DR5', 'FG2Pct', 'FG3Pct', 'FTPct', 'BlockPct',25 'OppFG2Pct', 'OppFG3Pct', 'OppFTPct', 'OppBlockPct', 'F3GRate',26 'OppF3GRate', 'ARate', 'OppARate', 'StlRate', 'OppStlRate']27def get_random_number():28 """generate random number between -1 and 1."""29 rand = random.random()30 rand = (rand * 2) - 131 return rand32def prepare_data(year1, team1, year2, team2, mongo):33 """Prepare data for prediction."""34 data = []35 team_year_info = mongo.db.basketball.find_one(36 {'TeamName': str(team1), 'Season': int(year1)})37 for col in cols:38 data.append(team_year_info[col])39 tc1 = team_year_info['color1']40 team_year_info = mongo.db.basketball.find_one(41 {'TeamName': str(team2), 'Season': int(year2)})42 for col in cols:43 data.append(team_year_info[col])44 tc2 = team_year_info['color1']45 data.append(home_court.get(str(team1), 0))46 data = np.array(data)47 return data, tc1, tc248def randomize_data(year1, team1, year2, team2, data):49 """randomize data for bootstrap predictions."""50 data_std = year_team_std[year1].get(team1, year_team_std['all'])51 cols_len = len(cols)52 data_copy = data.copy()53 data_copy[0] += get_random_number() * data_std['Pace']54 data_copy[1] += get_random_number() * data_std['ORtg']55 data_copy[2] += get_random_number() * data_std['DRtg']56 data_copy[3] += get_random_number() * data_std['OeFG%'] * 10057 data_copy[4] += get_random_number() * data_std['DeFG%'] * 10058 data_copy[5] += get_random_number() * data_std['OTOV%']59 data_copy[6] += get_random_number() * data_std['DTOV%']60 data_copy[7] += get_random_number() * data_std['OORB%']61 data_copy[8] += get_random_number() * data_std['DDRB%']62 data_copy[9] += get_random_number() * data_std['OFT/FGA'] * 10063 data_copy[10] += get_random_number() * data_std['DFT/FGA'] * 10064 data_copy[42] += get_random_number() * data_std['h3P%'] * 10065 data_copy[43] += get_random_number() * data_std['hFT%'] * 10066 data_copy[44] += get_random_number() * data_std['BLK%']67 data_copy[51] += get_random_number() * data_std['AST%']68 data_copy[53] += get_random_number() * data_std['STL%'] / 10069 data_std = year_team_std[year2].get(team2, year_team_std['all'])70 data_copy[0 + cols_len] += get_random_number() * data_std['Pace']71 data_copy[1 + cols_len] += get_random_number() * data_std['ORtg']72 data_copy[2 + cols_len] += get_random_number() * data_std['DRtg']73 data_copy[3 + cols_len] += get_random_number() * data_std['OeFG%'] * 10074 data_copy[4 + cols_len] += get_random_number() * data_std['DeFG%'] * 10075 data_copy[5 + cols_len] += get_random_number() * data_std['OTOV%']76 data_copy[6 + cols_len] += get_random_number() * data_std['DTOV%']77 data_copy[7 + cols_len] += get_random_number() * data_std['OORB%']78 data_copy[8 + cols_len] += get_random_number() * data_std['DDRB%']79 data_copy[9 + cols_len] += get_random_number() * data_std['OFT/FGA'] * 10080 data_copy[10 + cols_len] += get_random_number() * data_std['DFT/FGA'] * 10081 data_copy[42 + cols_len] += get_random_number() * data_std['h3P%'] * 10082 data_copy[43 + cols_len] += get_random_number() * data_std['hFT%'] * 10083 data_copy[44 + cols_len] += get_random_number() * data_std['BLK%']84 data_copy[51 + cols_len] += get_random_number() * data_std['AST%']85 data_copy[53 + cols_len] += get_random_number() * data_std['STL%'] / 10086 return data_copy87def bootstrap(year1, team1, year2, team2, mongo):88 """predict 100 random games."""89 output = {}90 data, tc1, tc2 = prepare_data(year1, team1, year2, team2, mongo)91 data_df = pd.DataFrame(data.reshape(1, 111))92 data_copy = data.copy()93 num_trials = 9994 for i in range(num_trials):95 rand_data = randomize_data(year1, team1, year2, team2, data_copy)96 data_df.loc[len(data_df)] = rand_data97 data_df -= ml_stats_mean98 data_df = data_df / ml_stats_std99 global graph...

Full Screen

Full Screen

test_cached.py

Source:test_cached.py Github

copy

Full Screen

2import pytest3import random4import warnings5@cached6def get_random_number(a, b, *args, **kwars):7 print(a, b)8 return random.randint(a, b)9@cached10def get_number(a, b, *args, **kwars):11 return (a + b) // 212class TestCached:13 def initialize(self):14 random.seed(42)15 def test_simple(self):16 self.initialize()17 for i in range(100):18 assert get_random_number(1, 2) == get_random_number(1, 2)19 def test_hashable_types(self):20 self.initialize()21 tpl = (1, 2.0, '123', None, True)22 for i in range(100):23 assert get_random_number(1, 2, tpl) == get_random_number(1, 2, tpl)24 def test_runtime_warning_unhashable_types(self):25 unhashable = {1: 2, 3: 4}26 with pytest.warns(RuntimeWarning):27 get_number(1, 2, unhashable)28 def test_unhashable_types(self):29 warnings.simplefilter("ignore")...

Full Screen

Full Screen

test_fixture.py

Source:test_fixture.py Github

copy

Full Screen

...16# assert os.path.exists(directory), 'dir not exist'171819@pytest.fixture(scope="session")20def get_random_number():21 number = random.randint(1, 100)22 print(number)23 return number242526def test_random_number(get_random_number):27 assert 0 < get_random_number <= 100282930def test_random_number_2(get_random_number):31 assert 0 < get_random_number <= 100323334class TestRandom: ...

Full Screen

Full Screen

test_2.py

Source:test_2.py Github

copy

Full Screen

1import pytest2from proga import get_random_number3def test_get_random_number_1():4 assert isinstance(get_random_number(12), int)5def test_get_random_number_2():6 assert get_random_number(12) <= 127def test_get_random_number_3():8 assert isinstance(get_random_number(20), int)9def test_get_random_number_4():10 assert get_random_number(20) <= 2011def test_get_random_number_5():12 assert isinstance(get_random_number(123), int)13def test_get_random_number_6():...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful