Best Python code snippet using tox_python
test_batching.py
Source: test_batching.py
...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,...
Check out the latest blogs from LambdaTest on this topic:
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
JUnit is one of the most popular unit testing frameworks in the Java ecosystem. The JUnit 5 version (also known as Jupiter) contains many exciting innovations, including support for new features in Java 8 and above. However, many developers still prefer to use the JUnit 4 framework since certain features like parallel execution with JUnit 5 are still in the experimental phase.
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!!