|
20 | 20 | ArithmeticAddCalculation = CalculationFactory('core.arithmetic.add')
|
21 | 21 |
|
22 | 22 |
|
| 23 | +@pytest.fixture |
| 24 | +def arithmetic_add_builder(aiida_code_installed): |
| 25 | + builder = ArithmeticAddCalculation.get_builder() |
| 26 | + builder.code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash') |
| 27 | + builder.x = orm.Int(1) |
| 28 | + builder.y = orm.Int(1) |
| 29 | + builder.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1}}} |
| 30 | + return builder |
| 31 | + |
| 32 | + |
23 | 33 | @calcfunction
|
24 | 34 | def add(term_a, term_b):
|
25 | 35 | return term_a + term_b
|
@@ -69,18 +79,28 @@ def add(self):
|
69 | 79 |
|
70 | 80 |
|
71 | 81 | @pytest.mark.usefixtures('started_daemon_client')
|
72 |
| -def test_submit_wait(aiida_code_installed): |
| 82 | +def test_submit_wait(arithmetic_add_builder): |
73 | 83 | """Test the ``wait`` argument of :meth:`aiida.engine.launch.submit`."""
|
74 |
| - builder = ArithmeticAddCalculation.get_builder() |
75 |
| - builder.code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash') |
76 |
| - builder.x = orm.Int(1) |
77 |
| - builder.y = orm.Int(1) |
78 |
| - builder.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1}}} |
79 |
| - node = launch.submit(builder, wait=True, wait_interval=0.1) |
| 84 | + node = launch.submit(arithmetic_add_builder, wait=True, wait_interval=0.1) |
80 | 85 | assert node.is_finished, node.process_state
|
81 | 86 | assert node.is_finished_ok, node.exit_code
|
82 | 87 |
|
83 | 88 |
|
| 89 | +def test_submit_no_broker(arithmetic_add_builder, monkeypatch, manager): |
| 90 | + """Test that ``submit`` raises ``InvalidOperation`` if the runner does not have a controller. |
| 91 | +
|
| 92 | + The runner does not have a controller if the runner was not provided a communicator which is the case for profiles |
| 93 | + that do not define a broker. |
| 94 | + """ |
| 95 | + runner = manager.get_runner() |
| 96 | + monkeypatch.setattr(runner, '_controller', None) |
| 97 | + |
| 98 | + with pytest.raises( |
| 99 | + exceptions.InvalidOperation, match=r'Cannot submit because the runner does not have a process controller.*' |
| 100 | + ): |
| 101 | + launch.submit(arithmetic_add_builder) |
| 102 | + |
| 103 | + |
84 | 104 | def test_await_processes_invalid():
|
85 | 105 | """Test :func:`aiida.engine.launch.await_processes` for invalid inputs."""
|
86 | 106 | with pytest.raises(TypeError):
|
|
0 commit comments