|
12 | 12 | # permissions and limitations under the License.
|
13 | 13 | from __future__ import absolute_import
|
14 | 14 |
|
| 15 | +import logging |
15 | 16 | import pytest
|
16 | 17 |
|
17 | 18 | from stepfunctions.exceptions import DuplicateStatesInChain
|
@@ -328,12 +329,6 @@ def test_append_states_after_terminal_state_will_fail():
|
328 | 329 | chain.append(Succeed('Succeed'))
|
329 | 330 | chain.append(Pass('Pass2'))
|
330 | 331 |
|
331 |
| - with pytest.raises(ValueError): |
332 |
| - chain = Chain() |
333 |
| - chain.append(Pass('Pass')) |
334 |
| - chain.append(Choice('Choice')) |
335 |
| - chain.append(Pass('Pass2')) |
336 |
| - |
337 | 332 |
|
338 | 333 | def test_chaining_steps():
|
339 | 334 | s1 = Pass('Step - One')
|
@@ -372,6 +367,33 @@ def test_chaining_steps():
|
372 | 367 | assert s1.next_step == s2
|
373 | 368 | assert s2.next_step == s3
|
374 | 369 |
|
| 370 | + |
| 371 | +def test_chaining_choice(caplog): |
| 372 | + s1_pass = Pass('Step - One') |
| 373 | + s2_choice = Choice('Step - Two') |
| 374 | + s3_pass = Pass('Step - Three') |
| 375 | + |
| 376 | + with caplog.at_level(logging.WARNING): |
| 377 | + chain1 = Chain([s1_pass, s2_choice, s3_pass]) |
| 378 | + assert caplog.text == '' # No warning |
| 379 | + assert chain1.steps == [s1_pass, s2_choice, s3_pass] |
| 380 | + assert s1_pass.next_step == s2_choice |
| 381 | + assert s2_choice.default == s3_pass |
| 382 | + assert s2_choice.next_step is None # Choice steps do not have next_step |
| 383 | + assert s3_pass.next_step is None |
| 384 | + |
| 385 | + # Chain s2_choice when default_choice is already set will trigger Warning |
| 386 | + with caplog.at_level(logging.WARNING): |
| 387 | + Chain([s2_choice, s1_pass]) |
| 388 | + log_message = ( |
| 389 | + "Chaining Choice Step: Overwriting %s's current default_choice (%s) with %s" % |
| 390 | + (s2_choice.state_id, s3_pass.state_id, s1_pass.state_id) |
| 391 | + ) |
| 392 | + assert log_message in caplog.text |
| 393 | + assert s2_choice.default == s1_pass |
| 394 | + assert s2_choice.next_step is None # Choice steps do not have next_step |
| 395 | + |
| 396 | + |
375 | 397 | def test_catch_fail_for_unsupported_state():
|
376 | 398 | s1 = Pass('Step - One')
|
377 | 399 |
|
|
0 commit comments