diff --git a/tests/attacks/evasion/test_laser_attack.py b/tests/attacks/evasion/test_laser_attack.py index 1b5532b540..0b4bdabcc4 100644 --- a/tests/attacks/evasion/test_laser_attack.py +++ b/tests/attacks/evasion/test_laser_attack.py @@ -30,7 +30,7 @@ @pytest.fixture(name="close") def fixture_close() -> Callable: """ - Comparison function + Comparison function. :returns: function that checks if two float arrays are close. """ @@ -51,7 +51,7 @@ def close(x: np.ndarray, y: np.ndarray): @pytest.fixture(name="not_close") def fixture_not_close(close): """ - Comparison function + Comparison function. :returns: function that checks if values of two float arrays are not close. """ @@ -75,7 +75,7 @@ def not_close(x: np.ndarray, y: np.ndarray) -> bool: @pytest.fixture(name="less_or_equal") def fixture_less_or_equal(): """ - Comparison function + Comparison function. :returns: function that checks if first array is less or equal than the second. """ @@ -126,7 +126,7 @@ def fixture_max_laser_beam() -> LaserBeam: @pytest.fixture(name="laser_generator_fixture") def fixture_laser_generator_fixture(min_laser_beam, max_laser_beam) -> Callable: """ - Return a function that returns geneartor of the LaserBeam objects. + Return a function that returns generator of the LaserBeam objects. :param min_laser_beam: LaserBeam object with minimal acceptable properties. :param max_laser_beam: LaserBeam object with maximal acceptable properties. @@ -138,7 +138,7 @@ def fixture_laser_generator_fixture(min_laser_beam, max_laser_beam) -> Callable: @pytest.fixture(name="laser_generator") def fixture_laser_generator(min_laser_beam, max_laser_beam) -> LaserBeamGenerator: """ - Geneartor of the LaserBeam objects. + Generator of the LaserBeam objects. :param min_laser_beam: LaserBeam object with minimal acceptable properties. :param max_laser_beam: LaserBeam object with maximal acceptable properties. diff --git a/tests/attacks/evasion/test_lowprofool.py b/tests/attacks/evasion/test_lowprofool.py index 2bc9c1777d..3fbc1b22cb 100644 --- a/tests/attacks/evasion/test_lowprofool.py +++ b/tests/attacks/evasion/test_lowprofool.py @@ -410,7 +410,7 @@ def test_clipping(iris_dataset): top_custom = 3 clf_slr_custom = ScikitlearnLogisticRegression(model=lr_clf, clip_values=(bottom_custom, top_custom)) - # Setting up LowProFool classes with different hyper-parameters + # Setting up LowProFool classes with different hyperparameters lpf_min_max_default = LowProFool(classifier=clf_slr_min_max, n_steps=45, eta=0.02, lambd=1.5) lpf_min_max_high_eta = LowProFool(classifier=clf_slr_min_max, n_steps=45, eta=100000, lambd=1.5) lpf_custom_default = LowProFool(classifier=clf_slr_custom, n_steps=45, eta=0.02, lambd=1.5) diff --git a/tests/attacks/evasion/test_pe_malware_attack.py b/tests/attacks/evasion/test_pe_malware_attack.py index 57f4c7f1a5..aa47f244cc 100644 --- a/tests/attacks/evasion/test_pe_malware_attack.py +++ b/tests/attacks/evasion/test_pe_malware_attack.py @@ -58,7 +58,7 @@ def fix_make_dummy_model(): def get_prediction_model(param_dic): """ - Model going from embeddings to predictions so we can easily optimise the embedding malware embedding. + Model going from embeddings to predictions, so we can easily optimise the embedding malware embedding. Needs to have the same structure as the target model. Populated here with "standard" parameters. """ @@ -168,7 +168,7 @@ def test_append_attack(art_warning, fix_get_synthetic_data, fix_make_dummy_model # We should only have 2 files as the following cannot be converted to valid adv samples: # 2nd datapoint (file too large to support any modifications) - # 4th datapoint (file to large to support append attacks) + # 4th datapoint (file too large to support append attacks) # 5th datapoint (benign file) assert len(adv_x) == 2 @@ -360,7 +360,7 @@ def test_dos_header_attack(art_warning, fix_get_synthetic_data, fix_make_dummy_m ) # should have 3 files. Samples which are excluded are: - # 2nd datapoint (file to large to support any modifications) + # 2nd datapoint (file too large to support any modifications) # 5th datapoint (benign file) assert len(adv_x) == 3 @@ -511,7 +511,7 @@ def test_do_not_check_for_valid(art_warning, fix_get_synthetic_data, fix_make_du # We expect 2 files to have been made adversarial the following cannot be converted to valid adv samples: # 2nd datapoint (file too large to support any modifications) - # 4th datapoint (file to large to support append attacks) + # 4th datapoint (file too large to support append attacks) # 5th datapoint (benign file) for i, size in enumerate(size_of_files): if i in [0, 2]: diff --git a/tests/attacks/poison/test_audio_perturbations.py b/tests/attacks/poison/test_audio_perturbations.py index 9bce9478d4..ef31669b8f 100644 --- a/tests/attacks/poison/test_audio_perturbations.py +++ b/tests/attacks/poison/test_audio_perturbations.py @@ -39,7 +39,7 @@ def test_insert_tone_trigger(art_warning): assert np.max(audio) != 0 assert np.max(np.abs(audio)) <= 1.0 - # test single example with differet duration, frequency, and scale + # test single example with different duration, frequency, and scale trigger = CacheToneTrigger(sampling_rate=16000, frequency=16000, duration=0.2, scale=0.5) audio = trigger.insert(x=np.zeros(3200)) assert audio.shape == (3200,) @@ -88,7 +88,7 @@ def test_insert_audio_trigger(art_warning): assert np.max(audio) != 0 assert np.max(np.abs(audio)) <= 1.0 - # test single example with differet duration and scale + # test single example with different duration and scale trigger = CacheAudioTrigger( sampling_rate=16000, backdoor_path=file_path, diff --git a/tests/attacks/test_adversarial_patch.py b/tests/attacks/test_adversarial_patch.py index ca850ff2f1..52a7d867b4 100644 --- a/tests/attacks/test_adversarial_patch.py +++ b/tests/attacks/test_adversarial_patch.py @@ -97,7 +97,7 @@ def test_2_tensorflow_numpy(self): x_out = attack_ap.insert_transformed_patch( self.x_train_mnist[0], np.ones((14, 14, 1)), np.asarray([[2, 13], [2, 18], [12, 22], [8, 13]]) ) - x_out_expexted = np.array( + x_out_expected = np.array( [ 0.0, 0.0, @@ -130,7 +130,7 @@ def test_2_tensorflow_numpy(self): ], dtype=np.float32, ) - np.testing.assert_almost_equal(x_out[15, :, 0], x_out_expexted, decimal=3) + np.testing.assert_almost_equal(x_out[15, :, 0], x_out_expected, decimal=3) if sess is not None: sess.close() @@ -166,7 +166,7 @@ def test_3_tensorflow_v2_framework(self): x_out = attack_ap.insert_transformed_patch( self.x_train_mnist[0], np.ones((14, 14, 1)), np.asarray([[2, 13], [2, 18], [12, 22], [8, 13]]) ) - x_out_expexted = np.array( + x_out_expected = np.array( [ 0.0, 0.0, @@ -199,7 +199,7 @@ def test_3_tensorflow_v2_framework(self): ], dtype=np.float32, ) - np.testing.assert_almost_equal(x_out[15, :, 0], x_out_expexted, decimal=3) + np.testing.assert_almost_equal(x_out[15, :, 0], x_out_expected, decimal=3) mask = np.ones((1, 28, 28)).astype(bool) attack_ap.apply_patch(x=self.x_train_mnist, scale=0.1, mask=mask) @@ -240,7 +240,7 @@ def test_6_keras(self): x_out = attack_ap.insert_transformed_patch( self.x_train_mnist[0], np.ones((14, 14, 1)), np.asarray([[2, 13], [2, 18], [12, 22], [8, 13]]) ) - x_out_expexted = np.array( + x_out_expected = np.array( [ 0.0, 0.0, @@ -273,7 +273,7 @@ def test_6_keras(self): ], dtype=np.float32, ) - np.testing.assert_almost_equal(x_out[15, :, 0], x_out_expexted, decimal=3) + np.testing.assert_almost_equal(x_out[15, :, 0], x_out_expected, decimal=3) def test_4_pytorch(self): """ diff --git a/tests/attacks/test_backdoor_attack.py b/tests/attacks/test_backdoor_attack.py index 9192e8ae7d..dd0f53e573 100644 --- a/tests/attacks/test_backdoor_attack.py +++ b/tests/attacks/test_backdoor_attack.py @@ -140,7 +140,7 @@ def test_backdoor_pixel(self): def test_backdoor_image(self): """ - Test the backdoor attack with a image-based perturbation can be trained on classifier + Test the backdoor attack with an image-based perturbation can be trained on classifier """ krc = get_image_classifier_kr() (is_poison_train, x_poisoned_raw, y_poisoned_raw) = self.poison_dataset( diff --git a/tests/attacks/test_targeted_universal_perturbation.py b/tests/attacks/test_targeted_universal_perturbation.py index 39d5e09ada..5c9da96d66 100644 --- a/tests/attacks/test_targeted_universal_perturbation.py +++ b/tests/attacks/test_targeted_universal_perturbation.py @@ -42,7 +42,7 @@ class TestTargetedUniversalPerturbation(TestBase): This module tests the Targeted Universal Perturbation. - | Paper link: https://arxiv.org/abs/1911.06502) + | Paper link: https://arxiv.org/abs/1911.06502 """ @classmethod diff --git a/tests/defences/preprocessor/test_mp3_compression.py b/tests/defences/preprocessor/test_mp3_compression.py index 5f3cda94f9..8d5a44d2fe 100644 --- a/tests/defences/preprocessor/test_mp3_compression.py +++ b/tests/defences/preprocessor/test_mp3_compression.py @@ -84,7 +84,7 @@ def test_non_temporal_data_error(art_warning, image_batch_small): @pytest.mark.parametrize("channels_first", [True, False]) @pytest.mark.skip_framework("keras", "pytorch", "scikitlearn", "mxnet") -def test_mp3_compresssion(art_warning, audio_batch, channels_first): +def test_mp3_compression(art_warning, audio_batch, channels_first): try: test_input, test_output, sample_rate = audio_batch mp3compression = Mp3Compression(sample_rate=sample_rate, channels_first=channels_first) @@ -96,7 +96,7 @@ def test_mp3_compresssion(art_warning, audio_batch, channels_first): @pytest.mark.parametrize("channels_first", [True, False]) @pytest.mark.skip_framework("keras", "pytorch", "scikitlearn", "mxnet") -def test_mp3_compresssion_object(art_warning, audio_batch, channels_first): +def test_mp3_compression_object(art_warning, audio_batch, channels_first): try: test_input, test_output, sample_rate = audio_batch test_input_object = np.array([x for x in test_input], dtype=object) diff --git a/tests/defences/preprocessor/test_mp3_compression_pytorch.py b/tests/defences/preprocessor/test_mp3_compression_pytorch.py index 1b708594ad..b447dfd4ef 100644 --- a/tests/defences/preprocessor/test_mp3_compression_pytorch.py +++ b/tests/defences/preprocessor/test_mp3_compression_pytorch.py @@ -86,7 +86,7 @@ def test_non_temporal_data_error(art_warning, image_batch_small): @pytest.mark.parametrize("channels_first", [True, False]) @pytest.mark.skip_framework("tensorflow", "keras", "scikitlearn", "mxnet", "kerastf") -def test_mp3_compresssion(art_warning, audio_batch, channels_first): +def test_mp3_compression(art_warning, audio_batch, channels_first): try: test_input, test_output, sample_rate = audio_batch mp3compression = Mp3CompressionPyTorch(sample_rate=sample_rate, channels_first=channels_first) diff --git a/tests/defences/preprocessor/test_video_compression.py b/tests/defences/preprocessor/test_video_compression.py index f2188999e3..0f61552f5d 100644 --- a/tests/defences/preprocessor/test_video_compression.py +++ b/tests/defences/preprocessor/test_video_compression.py @@ -44,7 +44,7 @@ def video_batch(channels_first): @pytest.mark.parametrize("channels_first", [True, False]) @pytest.mark.skip_framework("keras", "pytorch", "scikitlearn", "mxnet") -def test_video_compresssion(art_warning, video_batch, channels_first): +def test_video_compression(art_warning, video_batch, channels_first): try: test_input, test_output = video_batch video_compression = VideoCompression(video_format="mp4", constant_rate_factor=0, channels_first=channels_first) diff --git a/tests/defences/preprocessor/test_video_compression_pytorch.py b/tests/defences/preprocessor/test_video_compression_pytorch.py index c8deab0a8d..3be48fd4b8 100644 --- a/tests/defences/preprocessor/test_video_compression_pytorch.py +++ b/tests/defences/preprocessor/test_video_compression_pytorch.py @@ -44,7 +44,7 @@ def video_batch(channels_first): @pytest.mark.parametrize("channels_first", [True, False]) @pytest.mark.skip_framework("tensorflow", "keras", "scikitlearn", "mxnet", "kerastf") -def test_video_compresssion(art_warning, video_batch, channels_first): +def test_video_compression(art_warning, video_batch, channels_first): try: test_input, test_output = video_batch video_compression = VideoCompressionPyTorch( diff --git a/tests/defences/test_adversarial_trainer.py b/tests/defences/test_adversarial_trainer.py index e4ba41ea16..e4820ea88d 100644 --- a/tests/defences/test_adversarial_trainer.py +++ b/tests/defences/test_adversarial_trainer.py @@ -67,7 +67,7 @@ def test_classifier_match(self): self.assertEqual(len(adv_trainer.attacks), 1) self.assertEqual(adv_trainer.attacks[0].estimator, adv_trainer.get_classifier()) - def test_excpetions(self): + def test_exceptions(self): with self.assertRaises(ValueError): _ = AdversarialTrainer(self.classifier, "attack") diff --git a/tests/estimators/certification/test_deepz.py b/tests/estimators/certification/test_deepz.py index 06ca002652..d9310e4346 100644 --- a/tests/estimators/certification/test_deepz.py +++ b/tests/estimators/certification/test_deepz.py @@ -32,7 +32,7 @@ @pytest.fixture() def fix_get_mnist_data(): """ - Get the first 100 samples of the mnist test set with channels first format + Get the first 100 samples of the mnist test set with channels first format. :return: First 100 sample/label pairs of the MNIST test dataset. """ nb_test = 100 diff --git a/tests/estimators/certification/test_derandomized_smoothing.py b/tests/estimators/certification/test_derandomized_smoothing.py index cee00eda4e..40908416fa 100644 --- a/tests/estimators/certification/test_derandomized_smoothing.py +++ b/tests/estimators/certification/test_derandomized_smoothing.py @@ -156,7 +156,7 @@ def build_model(input_shape): img_inputs = tf.keras.Input(shape=(input_shape[0], input_shape[1], input_shape[2] * 2)) x = tf.keras.layers.Conv2D(filters=32, kernel_size=(4, 4), strides=(2, 2), activation="relu")(img_inputs) x = tf.keras.layers.MaxPool2D(pool_size=(2, 2), strides=2)(x) - # tensorflow uses channels last and we are loading weights from an originally trained pytorch model + # tensorflow uses channels last, and we are loading weights from an originally trained pytorch model x = tf.transpose(x, (0, 3, 1, 2)) x = tf.keras.layers.Flatten()(x) x = tf.keras.layers.Dense(100, activation="relu")(x) @@ -295,7 +295,7 @@ def build_model(input_shape): img_inputs = tf.keras.Input(shape=(input_shape[0], input_shape[1], input_shape[2] * 2)) x = tf.keras.layers.Conv2D(filters=32, kernel_size=(4, 4), strides=(2, 2), activation="relu")(img_inputs) x = tf.keras.layers.MaxPool2D(pool_size=(2, 2), strides=2)(x) - # tensorflow uses channels last and we are loading weights from an originally trained pytorch model + # tensorflow uses channels last, and we are loading weights from an originally trained pytorch model x = tf.transpose(x, (0, 3, 1, 2)) x = tf.keras.layers.Flatten()(x) x = tf.keras.layers.Dense(100, activation="relu")(x) diff --git a/tests/estimators/certification/test_interval.py b/tests/estimators/certification/test_interval.py index 9214c6b7dc..2cd66809a5 100644 --- a/tests/estimators/certification/test_interval.py +++ b/tests/estimators/certification/test_interval.py @@ -66,7 +66,7 @@ def forward(self, x): @pytest.fixture() def fix_get_mnist_data(): """ - Get the first 100 samples of the mnist test set with channels first format + Get the first 100 samples of the mnist test set with channels first format. :return: First 100 sample/label pairs of the MNIST test dataset. """ nb_test = 100 diff --git a/tests/metrics/test_metrics.py b/tests/metrics/test_metrics.py index 3e5959b882..d169d70df4 100644 --- a/tests/metrics/test_metrics.py +++ b/tests/metrics/test_metrics.py @@ -113,7 +113,7 @@ def test_loss_sensitivity(self): # (x_train, y_train), (_, _), _, _ = load_mnist() # x_train, y_train = x_train[:NB_TRAIN], y_train[:NB_TRAIN] # - # # Get classifier + # # Get classifier. # classifier = self._cnn_mnist_k([28, 28, 1]) # classifier.fit(x_train, y_train, batch_size=BATCH_SIZE, nb_epochs=2) # diff --git a/tests/utils.py b/tests/utils.py index e5c521f487..c665ff843f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -236,7 +236,7 @@ def get_image_classifier_tf_v1(from_logits=False, load_init=True, sess=None): """ Standard TensorFlow classifier for unit testing. - The following hyper-parameters were used to obtain the weights and biases: + The following hyperparameters were used to obtain the weights and biases: learning_rate: 0.01 batch size: 10 number of epochs: 2 @@ -413,7 +413,7 @@ def discriminator_loss_fct(real_output, generated_output): zeros (since these are the fake images). 3. Calculate the total_loss as the sum of real_loss and generated_loss. """ - # [1,1,...,1] with real output since it is true and we want our generated examples to look like it + # [1,1,...,1] with real output since it is true, and we want our generated examples to look like it real_loss = tf.compat.v1.losses.sigmoid_cross_entropy( multi_class_labels=tf.ones_like(real_output), logits=real_output ) @@ -442,7 +442,7 @@ def get_image_classifier_tf_v2(from_logits=False): """ Standard TensorFlow v2 classifier for unit testing. - The following hyper-parameters were used to obtain the weights and biases: + The following hyperparameters were used to obtain the weights and biases: learning_rate: 0.01 batch size: 10 number of epochs: 2 @@ -1576,7 +1576,7 @@ def get_tabular_classifier_tf_v1(load_init=True, sess=None): """ Standard TensorFlow classifier for unit testing. - The following hyper-parameters were used to obtain the weights and biases: + The following hyperparameters were used to obtain the weights and biases: * learning_rate: 0.01 * batch size: 5 @@ -1663,7 +1663,7 @@ def get_tabular_classifier_tf_v2(): """ Standard TensorFlow v2 classifier for unit testing. - The following hyper-parameters were used to obtain the weights and biases: + The following hyperparameters were used to obtain the weights and biases: * learning_rate: 0.01 * batch size: 5