Skip to content

Commit

Permalink
conditionally skip unsupported subTest tests for Python 2 (#386)
Browse files Browse the repository at this point in the history
closes #387
  • Loading branch information
kostmo authored and vincentqb committed Jan 2, 2020
1 parent 479e666 commit cdf5c83
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torchaudio
import math
import os
import sys


class AudioBackendScope:
Expand All @@ -28,6 +29,7 @@ class Test_LoadSave(unittest.TestCase):
test_filepath_wav = os.path.join(test_dirpath, "assets",
"steam-train-whistle-daniel_simon.wav")

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_1_save(self):
for backend in ["sox"]:
with self.subTest():
Expand Down Expand Up @@ -79,6 +81,7 @@ def _test_1_save(self, test_filepath, normalization):
"test.wav")
torchaudio.save(new_filepath, x, sr)

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_1_save_sine(self):
for backend in ["sox", "soundfile"]:
with self.subTest():
Expand Down Expand Up @@ -112,6 +115,7 @@ def _test_1_save_sine(self):
self.assertEqual(si32.precision, new_precision)
os.unlink(new_filepath)

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_2_load(self):
for backend in ["sox"]:
with self.subTest():
Expand Down Expand Up @@ -153,6 +157,7 @@ def _test_2_load(self, test_filepath, length):
os.path.dirname(self.test_dirpath), "torchaudio")
torchaudio.load(tdir)

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_2_load_nonormalization(self):
for backend in ["sox"]:
with self.subTest():
Expand All @@ -170,6 +175,7 @@ def _test_2_load_nonormalization(self, test_filepath, length):
x, _ = torchaudio.load(test_filepath, torch.LongTensor(), normalization=False)
self.assertTrue(isinstance(x, torch.LongTensor))

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_3_load_and_save_is_identity(self):
for backend in ["sox", "soundfile"]:
with self.subTest():
Expand All @@ -186,6 +192,7 @@ def _test_3_load_and_save_is_identity(self):
self.assertEqual(sample_rate, sample_rate2)
os.unlink(output_path)

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_3_load_and_save_is_identity_across_backend(self):
with self.subTest():
self._test_3_load_and_save_is_identity_across_backend("sox", "soundfile")
Expand All @@ -208,6 +215,7 @@ def _test_3_load_and_save_is_identity_across_backend(self, backend1, backend2):
self.assertEqual(sample_rate1, sample_rate2)
os.unlink(output_path)

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_4_load_partial(self):
for backend in ["sox"]:
with self.subTest():
Expand Down Expand Up @@ -250,6 +258,7 @@ def _test_4_load_partial(self):
with self.assertRaises(RuntimeError):
torchaudio.load(input_sine_path, offset=100000)

@unittest.skipIf(sys.version_info < (3, 4), "subTest unavailable for this Python version")
def test_5_get_info(self):
for backend in ["sox", "soundfile"]:
with self.subTest():
Expand Down

0 comments on commit cdf5c83

Please sign in to comment.