smoke_test.py 1.61 KB
Newer Older
moto's avatar
moto committed
1
#!/usr/bin/env python3
moto's avatar
moto committed
2
"""Run smoke tests"""
3
import argparse
moto's avatar
moto committed
4
5
import logging

6

moto's avatar
moto committed
7
8
9
10
11
12
13
14
15
16
def base_smoke_test():
    import torchaudio  # noqa: F401
    import torchaudio.compliance.kaldi  # noqa: F401
    import torchaudio.datasets  # noqa: F401
    import torchaudio.functional  # noqa: F401
    import torchaudio.models  # noqa: F401
    import torchaudio.pipelines  # noqa: F401
    import torchaudio.sox_effects  # noqa: F401
    import torchaudio.transforms  # noqa: F401
    import torchaudio.utils  # noqa: F401
17
18
19
20
21
22


def ffmpeg_test():
    from torchaudio.io import StreamReader  # noqa: F401


moto's avatar
moto committed
23
24
25
26
27
28
29
30
31
32
33
34
35
def _run_smoke_test(check_ffmpeg):
    base_smoke_test()

    if not check_ffmpeg:
        print("Skipping ffmpeg test.")
    else:
        ffmpeg_test()

    print("Smoke test passed.")


def main(args=None) -> None:
    options = _parse_args(args)
moto's avatar
moto committed
36
37
38
39

    if options.debug:
        logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)

moto's avatar
moto committed
40
41
    _chdir()
    _run_smoke_test(options.ffmpeg)
moto's avatar
moto committed
42
43


moto's avatar
moto committed
44
def _parse_args(args):
45
46
47
48
    parser = argparse.ArgumentParser()

    # Warning: Please note this option should not be widely used, only use it when absolutely necessary
    parser.add_argument("--no-ffmpeg", dest="ffmpeg", action="store_false")
moto's avatar
moto committed
49
    parser.add_argument("--debug", action="store_true", help="Enable debug logging.")
50

moto's avatar
moto committed
51
52
53
54
55
56
57
58
59
60
    return parser.parse_args(args)


def _chdir():
    # smoke test should not be performed on the root directory of checked out source code.
    import os
    from pathlib import Path

    os.chdir(Path(__file__).parent)
    assert "torchaudio" not in os.listdir(os.getcwd())
61
62
63
64


if __name__ == "__main__":
    main()