66 _register_builder_plugin , _register_compiler_plugin ,
77 _sort_user_categories , _CategoryCompilerProxy , _COMPILERS , _ALIASES
88)
9+ from paths_cli .tests .compiling .utils import mock_compiler
910from unittest .mock import Mock , PropertyMock , patch
1011from paths_cli .compiling .core import (
1112 CategoryCompiler , InstanceCompilerPlugin
@@ -21,7 +22,7 @@ def foo_compiler():
2122
2223@pytest .fixture
2324def foo_compiler_plugin ():
24- return CategoryPlugin (Mock (category = 'foo' ), ['bar' ])
25+ return CategoryPlugin (Mock (category = 'foo' , __name__ = 'foo' ), ['bar' ])
2526
2627@pytest .fixture
2728def foo_baz_builder_plugin ():
@@ -73,7 +74,17 @@ def test_named_objs(self):
7374
7475 def test_call (self ):
7576 # the `__call__` method should work in the proxy
76- pytest .skip ()
77+ def _bar_dispatch (dct ):
78+ return dct ['baz' ] * dct ['qux' ]
79+
80+ foo_compiler = mock_compiler (
81+ category = 'foo' ,
82+ type_dispatch = {'bar' : _bar_dispatch },
83+ )
84+ proxy = _CategoryCompilerProxy ('foo' )
85+ user_input = {'type' : 'bar' , 'baz' : 'baz' , 'qux' : 2 }
86+ with patch .dict (COMPILER_LOC , {'foo' : foo_compiler }):
87+ assert proxy (user_input ) == "bazbaz"
7788
7889def test_compiler_for_nonexisting ():
7990 # if nothing is ever registered with the compiler, then compiler_for
@@ -141,7 +152,9 @@ def test_get_registration_names(canonical, aliases, expected):
141152def test_register_compiler_plugin (foo_compiler_plugin ):
142153 # _register_compiler_plugin should register compilers that don't exist
143154 compilers = {}
144- with patch .dict (COMPILER_LOC , compilers ):
155+ aliases = {}
156+ with patch .dict (COMPILER_LOC , compilers ) as _compiler , \
157+ patch .dict (BASE + "_ALIASES" , aliases ) as _alias :
145158 assert 'foo' not in compilers
146159 _register_compiler_plugin (foo_compiler_plugin )
147160 assert 'foo' in _COMPILERS
@@ -199,9 +212,18 @@ def test_register_plugins_unit(foo_compiler_plugin, foo_baz_builder_plugin):
199212 assert builder .called_once_with (foo_baz_builder_plugin )
200213 assert compiler .called_once_with (foo_compiler_plugin )
201214
202- def test_register_plugins_integration ():
215+ def test_register_plugins_integration (foo_compiler_plugin ,
216+ foo_baz_builder_plugin ):
203217 # register_plugins should correctly register plugins
204- pytest .skip ()
218+ compilers = {}
219+ aliases = {}
220+ with patch .dict (COMPILER_LOC , compilers ) as _compiler , \
221+ patch .dict (BASE + "_ALIASES" , aliases ) as _alias :
222+ assert 'foo' not in _COMPILERS
223+ register_plugins ([foo_compiler_plugin , foo_baz_builder_plugin ])
224+ assert 'foo' in _COMPILERS
225+ type_dispatch = _COMPILERS ['foo' ].type_dispatch
226+ assert type_dispatch ['baz' ] is foo_baz_builder_plugin
205227
206228def test_sort_user_categories ():
207229 # sorted user categories should match the expected compile order
0 commit comments