forked from asteroid-team/asteroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_test.py
More file actions
46 lines (31 loc) · 1.41 KB
/
Copy pathcli_test.py
File metadata and controls
46 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from asteroid.scripts import asteroid_versions, asteroid_cli
def test_asteroid_versions():
versions = asteroid_versions.asteroid_versions()
assert "Asteroid" in versions
assert "PyTorch" in versions
assert "PyTorch-Lightning" in versions
def test_print_versions():
asteroid_versions.print_versions()
def test_asteroid_versions_without_git(monkeypatch):
monkeypatch.setenv("PATH", "")
asteroid_versions.asteroid_versions()
def test_infer_device(monkeypatch):
"""Test that inference is performed on the PyTorch device given by '--device'.
We can't properly test this in environments with only CPU device available.
As an approximation we test that the '.to()' method of the model is called
with the device given by '--device'.
"""
# We can't use a real model to test this because calling .to() with a fake device
# on a real model will fail.
class FakeModel:
def to(self, device):
self.device = device
fake_model = FakeModel()
# Monkeypatch 'from_pretrained' to load our fake model.
from asteroid.models import BaseModel
monkeypatch.setattr(BaseModel, "from_pretrained", lambda *args, **kwargs: fake_model)
# Note that this will issue a warning about the missing file.
asteroid_cli.infer(
["--device", "cuda:42", "somemodel", "--files", "file_that_does_not_exist.wav"]
)
assert fake_model.device == "cuda:42"