How to use run_sequential method in tox

Best Python code snippet using tox_python

test_batching.py

Source:test_batching.py Github

copy

Full Screen

...25 bn_images,26 bn_labels,27 individual_kwargs=[{"epsilons": 900} for _ in bn_images],28 )29 advs1s = run_sequential(30 Attack,31 bn_model,32 bn_criterion,33 bn_images,34 bn_labels,35 individual_kwargs=[{"epsilons": 900} for _ in bn_images],36 )37 advs2 = attack(38 bn_images,39 bn_labels,40 unpack=False,41 individual_kwargs=[{"epsilons": 900} for _ in bn_images],42 max_epsilon=0.99,43 )44 advs2p = run_parallel(45 Attack,46 bn_model,47 bn_criterion,48 bn_images,49 bn_labels,50 individual_kwargs=[{"epsilons": 900} for _ in bn_images],51 max_epsilon=0.99,52 )53 advs2s = run_sequential(54 Attack,55 bn_model,56 bn_criterion,57 bn_images,58 bn_labels,59 individual_kwargs=[{"epsilons": 900} for _ in bn_images],60 max_epsilon=0.99,61 )62 advs3 = attack(bn_images, bn_labels, unpack=False, max_epsilon=0.99)63 advs3p = run_parallel(64 Attack, bn_model, bn_criterion, bn_images, bn_labels, max_epsilon=0.9965 )66 advs3s = run_sequential(67 Attack, bn_model, bn_criterion, bn_images, bn_labels, max_epsilon=0.9968 )69 for i in range(len(bn_images)):70 assert advs1[i].perturbed is not None71 assert advs2[i].perturbed is not None72 assert advs3[i].perturbed is not None73 assert advs1p[i].perturbed is not None74 assert advs2p[i].perturbed is not None75 assert advs3p[i].perturbed is not None76 assert advs1s[i].perturbed is not None77 assert advs2s[i].perturbed is not None78 assert advs3s[i].perturbed is not None79 assert np.allclose(advs1[i].perturbed, advs1p[i].perturbed)80 assert np.allclose(advs1[i].perturbed, advs1s[i].perturbed)81 assert np.allclose(advs2[i].perturbed, advs2p[i].perturbed)82 assert np.allclose(advs2[i].perturbed, advs2s[i].perturbed)83 assert np.allclose(advs3[i].perturbed, advs3p[i].perturbed)84 assert np.allclose(advs3[i].perturbed, advs3s[i].perturbed)85def test_run_parallel_invalid_arguments(bn_model, bn_criterion, bn_images, bn_labels):86 labels_wrong = bn_labels[[0]]87 criteria_wrong = [bn_criterion] * (len(bn_images) + 1)88 distances_wrong = [MSE] * (len(bn_images) + 1)89 individual_kwargs_wrong = [{"max_epsilon": 1}] * (len(bn_images) + 1)90 # test too few labels91 with pytest.raises(AssertionError):92 run_parallel(Attack, bn_model, bn_criterion, bn_images, labels_wrong)93 # test too many criteria94 with pytest.raises(AssertionError):95 run_parallel(Attack, bn_model, criteria_wrong, bn_images, bn_labels)96 # test too many distances97 with pytest.raises(AssertionError):98 run_parallel(99 Attack,100 bn_model,101 bn_criterion,102 bn_images,103 bn_labels,104 distance=distances_wrong,105 )106 # test too many kwargs107 with pytest.raises(AssertionError):108 run_parallel(109 Attack,110 bn_model,111 bn_criterion,112 bn_images,113 bn_labels,114 individual_kwargs=individual_kwargs_wrong,115 )116def test_run_sequential(bn_model, bn_criterion, bn_images, bn_labels):117 attack = Attack(bn_model, bn_criterion)118 advs1 = attack(bn_images, bn_labels)119 advs2 = run_sequential(Attack, bn_model, bn_criterion, bn_images, bn_labels)120 advs2 = np.stack([a.perturbed for a in advs2])121 assert np.all(advs1 == advs2)122def test_run_sequential_invalid_arguments(bn_model, bn_criterion, bn_images, bn_labels):123 labels_wrong = bn_labels[[0]]124 criteria_wrong = [bn_criterion] * (len(bn_images) + 1)125 distances_wrong = [MSE] * (len(bn_images) + 1)126 individual_kwargs_wrong = [{"max_epsilon": 1}] * (len(bn_images) + 1)127 # test too few labels128 with pytest.raises(AssertionError):129 run_sequential(Attack, bn_model, bn_criterion, bn_images, labels_wrong)130 # test too many criteria131 with pytest.raises(AssertionError):132 run_sequential(Attack, bn_model, criteria_wrong, bn_images, bn_labels)133 # test too many distances134 with pytest.raises(AssertionError):135 run_sequential(136 Attack,137 bn_model,138 bn_criterion,139 bn_images,140 bn_labels,141 distance=distances_wrong,142 )143 # test too many kwargs144 with pytest.raises(AssertionError):145 run_sequential(146 Attack,147 bn_model,148 bn_criterion,149 bn_images,150 bn_labels,151 individual_kwargs=individual_kwargs_wrong,...

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 tox 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