forked from facebookresearch/vissl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_engine_registry.py
42 lines (31 loc) · 1.36 KB
/
test_engine_registry.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
34
35
36
37
38
39
40
41
42
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from vissl.engines.engine_registry import Engine, get_engine, register_engine
class TestEngineRegistry(unittest.TestCase):
"""
Test that the engine registry allows to:
- select the right engine based on the configuration
- deal with the typical error cases (unknowns, duplicates, etc)
"""
def test_valid_engines(self):
engine = get_engine("train")
assert engine is not None
assert isinstance(engine, Engine)
engine = get_engine("extract_features")
assert engine is not None
assert isinstance(engine, Engine)
def test_unknown_engine_raises_error(self):
with self.assertRaises(ValueError) as result:
get_engine("unknown_name")
msg = str(result.exception)
assert msg.startswith("Unknown engine name unknown_name")
def test_duplicate_engine_registration_error(self):
with self.assertRaises(ValueError) as result:
@register_engine("train")
class Duplicate(Engine):
def run_engine(self, *args, **kwargs):
pass
msg = str(result.exception)
assert msg.startswith("Engine (train) already registered at")