Skip to content

Commit abd0107

Browse files
authored
Make test scripts runnable without being modules (#188)
1 parent 82df89b commit abd0107

File tree

9 files changed

+18
-15
lines changed

9 files changed

+18
-15
lines changed

build_tools/travis/test_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ run_tests() {
1818
for FILE in $TEST_FILES; do
1919
# run each file on a separate process. if one fails, just keep going and
2020
# return the final exit status.
21-
python -m unittest -v $FILE
21+
python -m pytest -v $FILE
2222
STATUS=$?
2323
EXIT_STATUS="$(($EXIT_STATUS+STATUS))"
2424
done

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ flake8
1212
# Used for comparison of outputs in tests
1313
librosa>=0.4.3
1414
scipy
15+
16+
# Unit tests with pytest
17+
pytest

test/__init__.py

Whitespace-only changes.

test/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import unittest
2-
import test.common_utils
2+
import common_utils
33
import torch
44
import torchaudio
55
import math
66
import os
77

88

99
class Test_LoadSave(unittest.TestCase):
10-
test_dirpath, test_dir = test.common_utils.create_temp_assets_dir()
10+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
1111
test_filepath = os.path.join(test_dirpath, "assets",
1212
"steam-train-whistle-daniel_simon.mp3")
1313

test/test_dataloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
import test.common_utils
2+
import common_utils
33
import torch
44
import torch.nn as nn
55
from torch.utils.data import Dataset, DataLoader
@@ -10,7 +10,7 @@
1010

1111
class TORCHAUDIODS(Dataset):
1212

13-
test_dirpath, test_dir = test.common_utils.create_temp_assets_dir()
13+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
1414

1515
def __init__(self):
1616
self.asset_dirpath = os.path.join(self.test_dirpath, "assets")

test/test_kaldi_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import torch
33
import torchaudio.kaldi_io as kio
44
import unittest
5-
import test.common_utils
5+
import common_utils
66

77

88
class KaldiIOTest(unittest.TestCase):
99
data1 = [[1, 2, 3], [11, 12, 13], [21, 22, 23]]
1010
data2 = [[31, 32, 33], [41, 42, 43], [51, 52, 53]]
11-
test_dirpath, test_dir = test.common_utils.create_temp_assets_dir()
11+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
1212

1313
def _test_helper(self, file_name, expected_data, fn, expected_dtype):
1414
""" Takes a file_name to the input data and a function fn to extract the

test/test_legacy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
import test.common_utils
2+
import common_utils
33
import torch
44
import torchaudio
55
from torchaudio.legacy import save, load
@@ -8,7 +8,7 @@
88

99

1010
class Test_LoadSave(unittest.TestCase):
11-
test_dirpath, test_dir = test.common_utils.create_temp_assets_dir()
11+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
1212
test_filepath = os.path.join(test_dirpath, "assets",
1313
"steam-train-whistle-daniel_simon.mp3")
1414

test/test_sox_effects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import unittest
2-
import test.common_utils
2+
import common_utils
33
import torch
44
import torchaudio
55
import math
66
import os
77

88

99
class Test_SoxEffectsChain(unittest.TestCase):
10-
test_dirpath, test_dir = test.common_utils.create_temp_assets_dir()
10+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
1111
test_filepath = os.path.join(test_dirpath, "assets",
1212
"steam-train-whistle-daniel_simon.mp3")
1313

test/test_transforms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from torchaudio.common_utils import IMPORT_LIBROSA, IMPORT_SCIPY
88
import torchaudio.transforms as transforms
99
import unittest
10-
import test.common_utils
10+
import common_utils
1111

1212
if IMPORT_LIBROSA:
1313
import librosa
@@ -26,9 +26,9 @@ class Tester(unittest.TestCase):
2626
sig.unsqueeze_(1) # (64000, 1)
2727
sig = (sig * volume * 2**31).long()
2828
# file for stereo stft test
29-
test_dirpath, test_dir = test.common_utils.create_temp_assets_dir()
30-
test_filepath = os.path.join(test_dirpath, "assets",
31-
"steam-train-whistle-daniel_simon.mp3")
29+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
30+
test_filepath = os.path.join(test_dirpath, 'assets',
31+
'steam-train-whistle-daniel_simon.mp3')
3232

3333
def test_scale(self):
3434

0 commit comments

Comments
 (0)