Skip to content

Commit 8904fd3

Browse files
committed
complete skipped tests in compiling/test_core
1 parent 571d283 commit 8904fd3

1 file changed

Lines changed: 56 additions & 6 deletions

File tree

‎paths_cli/tests/compiling/test_core.py‎

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import numpy.testing as npt
77

88
from paths_cli.compiling.core import *
9+
from paths_cli.compiling import compiler_for
10+
from paths_cli.tests.compiling.utils import mock_compiler
911

1012
class MockNamedObject:
1113
# used in the tests for CategoryCompiler._compile_dict and
@@ -187,10 +189,30 @@ def test_compile_attrs(self):
187189
assert compile_attrs(self.input_dict) == expected
188190

189191
def test_compile_attrs_compiler_integration(self):
190-
# compile_attrs gives the same object as already existing in a
191-
# compiler if one of the parameters uses that compiler to load a
192-
# named object
193-
pytest.skip()
192+
# compile_attrs gives the existing named object (is-identity) if one
193+
# of the parameters uses that compiler to load a named object
194+
user_input = {'foo': 'named_foo'}
195+
# full_input = {'foo': {'name': 'named_foo',
196+
# 'type': 'baz',
197+
# 'bar': 'should see this'}}
198+
bar_plugin = InstanceCompilerPlugin(
199+
builder=lambda foo: 'in bar: should not see this',
200+
parameters=[Parameter('foo', compiler_for('foo'))],
201+
)
202+
foo_plugin = InstanceCompilerPlugin(
203+
builder=lambda: 'in foo: should not see this',
204+
parameters=[],
205+
)
206+
named_objs = {'named_foo': 'should see this'}
207+
type_dispatch = {'baz': foo_plugin}
208+
PATCH_LOC = 'paths_cli.compiling.root_compiler._COMPILERS'
209+
compiler = mock_compiler('foo', type_dispatch=type_dispatch,
210+
named_objs=named_objs)
211+
with patch.dict(PATCH_LOC, {'foo': compiler}):
212+
compiled = bar_plugin.compile_attrs(user_input)
213+
214+
# maps attr name 'foo' to the previous existing object
215+
assert compiled == {'foo': 'should see this'}
194216

195217
def test_compile_attrs_missing_required(self):
196218
# an InputError should be raised if a required parameter is missing
@@ -304,16 +326,44 @@ def test_register_builder_identical(self):
304326
orig = self.compiler.type_dispatch['foo']
305327
self.compiler.register_builder(orig, 'foo')
306328

329+
@staticmethod
330+
def _validate_obj(obj, input_type):
331+
if input_type == 'str':
332+
assert obj == 'bar'
333+
elif input_type == 'dict':
334+
assert obj.data == 'qux'
335+
else:
336+
raise RuntimeError("Error in test setup")
337+
307338
@pytest.mark.parametrize('input_type', ['str', 'dict'])
308339
def test_compile(self, input_type):
309340
# the compile method should work whether the input is a dict
310341
# representing an object to be compiled or string name for an
311342
# already-compiled object
312-
pytest.skip()
343+
self._mock_register_obj()
344+
input_data = {
345+
'str': 'foo',
346+
'dict': {'type': 'foo', 'data': 'qux'}
347+
}[input_type]
348+
obj = self.compiler.compile(input_data)
349+
self._validate_obj(obj, input_type)
313350

314351
@pytest.mark.parametrize('input_type', ['str', 'dict'])
315352
@pytest.mark.parametrize('as_list', [True, False])
316353
def test_call(self, input_type, as_list):
317354
# the call method should work whether the input is a single object
318355
# or a list of objects (as well as whether string or dict)
319-
pytest.skip()
356+
self._mock_register_obj()
357+
input_data = {
358+
'str': 'foo',
359+
'dict': {'type': 'foo', 'data': 'qux'}
360+
}[input_type]
361+
if as_list:
362+
input_data = [input_data]
363+
364+
obj = self.compiler(input_data)
365+
if as_list:
366+
assert isinstance(obj, list)
367+
assert len(obj) == 1
368+
obj = obj[0]
369+
self._validate_obj(obj, input_type)

0 commit comments

Comments
 (0)