@@ -27,7 +27,7 @@ def compute(self):
2727 pass
2828
2929
30- def test_operation_repr_smoke (opname , opneeds , opprovides ):
30+ def test_repr_smoke (opname , opneeds , opprovides ):
3131 # Simply check __repr__() does not crash on partial attributes.
3232 kw = locals ().copy ()
3333 kw = {name [2 :]: arg for name , arg in kw .items ()}
@@ -39,7 +39,7 @@ def test_operation_repr_smoke(opname, opneeds, opprovides):
3939 str (op )
4040
4141
42- def test_operation_repr_returns_dict ():
42+ def test_repr_returns_dict ():
4343 assert (
4444 str (operation (lambda : None , returns_dict = True )())
4545 == "FunctionalOperation(name=None, needs=[], provides=[], fn{}='<lambda>')"
@@ -69,19 +69,47 @@ def test_operation_repr_returns_dict():
6969 (("" , "a" , [()]), ValueError ("All `provides` must be str" )),
7070 ],
7171)
72- def test_operation_validation (opargs , exp ):
72+ def test_validation (opargs , exp ):
7373 if isinstance (exp , Exception ):
7474 with pytest .raises (type (exp ), match = str (exp )):
7575 reparse_operation_data (* opargs )
7676 else :
7777 assert reparse_operation_data (* opargs ) == exp
7878
7979
80- def test_operation_returns_dict ():
80+ def test_returns_dict ():
8181 result = {"a" : 1 }
8282
8383 op = operation (lambda : result , provides = "a" , returns_dict = True )()
8484 assert op .compute ({}) == result
8585
8686 op = operation (lambda : 1 , provides = "a" , returns_dict = False )()
8787 assert op .compute ({}) == result
88+
89+
90+ @pytest .fixture (params = [None , ["a" , "b" ]])
91+ def asked_outputs (request ):
92+ return request .param
93+
94+
95+ @pytest .mark .parametrize (
96+ "result" , [None , 3.14 , (), "" , "foobar" , ["b" , "c" , "e" ], {"f" }]
97+ )
98+ def test_results_validation_iterable_BAD (result , asked_outputs ):
99+ op = operation (lambda : result , provides = ["a" , "b" ], returns_dict = False )()
100+ with pytest .raises (ValueError , match = "Expected x2 ITERABLE results" ):
101+ op .compute ({}, outputs = asked_outputs )
102+
103+
104+ @pytest .mark .parametrize ("result" , [None , 3.14 , [], "foo" , ["b" , "c" , "e" ], {"a" , "b" }])
105+ def test_dict_results_validation_BAD (result , asked_outputs ):
106+ op = operation (lambda : result , provides = ["a" , "b" ], returns_dict = True )()
107+ with pytest .raises (ValueError , match = "Expected dict-results" ):
108+ op .compute ({}, outputs = asked_outputs )
109+
110+
111+ @pytest .mark .parametrize ("result" , [{"a" : 1 }, {"a" : 1 , "b" : 2 , "c" : 3 }])
112+ def test_dict_results_validation_MISMATCH (result , asked_outputs ):
113+ op = operation (lambda : result , provides = ["a" , "b" ], returns_dict = True )()
114+ with pytest .raises (ValueError , match = "mismatched provides" ):
115+ op .compute ({}, outputs = asked_outputs )
0 commit comments