Skip to content

Commit

Permalink
conditionally skip unsupported subTest tests for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Dec 31, 2019
1 parent 42ffaf6 commit 878d0b2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 +80,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 +114,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 +156,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 +174,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 +191,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 +214,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 +257,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 878d0b2

Please sign in to comment.