-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathtest_easy_resource.py
33 lines (26 loc) · 1.17 KB
/
test_easy_resource.py
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
import pytest
from viam.components.generic import Generic
from viam.proto.app.robot import ComponentConfig
from viam.resource.easy_resource import _parse_model, EasyResource
from viam.resource.registry import Registry
from viam.resource.types import Model, ModelFamily
@pytest.fixture
def clear_registry(monkeypatch):
"helper to patch registry global state for duration of test"
monkeypatch.setattr(Registry, '_SUBTYPES', {})
monkeypatch.setattr(Registry, '_RESOURCES', {})
class TestEasyResource:
def test_parse_model(self):
model = Model(ModelFamily('viam', 'type'), 'name')
assert _parse_model('viam:type:name') == model
assert _parse_model(model) == model
with pytest.raises(ValueError):
_parse_model('not parseable')
def test_subclass(self, clear_registry):
class SubclassTest(Generic, EasyResource):
MODEL = "org:type:name"
# did it register correctly:
assert set(Registry._RESOURCES.keys()) == {f'rdk:component:generic/{SubclassTest.MODEL}'}
# can it be instantiated:
resource = SubclassTest.new(ComponentConfig(name="hello"), {})
assert resource.name == "hello"