Mock relevant calls in visualization.visualize and check that parameters have their expected value.
()
| 31 | |
| 32 | @pytest.fixture |
| 33 | def server(): |
| 34 | """Mock relevant calls in visualization.visualize and check that parameters have their expected value.""" |
| 35 | monkeypatch = pytest.MonkeyPatch() |
| 36 | with monkeypatch.context(): |
| 37 | _called_reuse_server = False |
| 38 | |
| 39 | def mock_set_reuse_server(self): |
| 40 | nonlocal _called_reuse_server |
| 41 | _called_reuse_server = True |
| 42 | |
| 43 | def mock_add_model_from_pytorch(self, name, exported_program, settings): |
| 44 | assert isinstance(exported_program, ExportedProgram) |
| 45 | |
| 46 | def mock_visualize_from_config(cur_config, no_open_in_browser): |
| 47 | pass |
| 48 | |
| 49 | monkeypatch.setattr( |
| 50 | ModelExplorerConfig, "set_reuse_server", mock_set_reuse_server |
| 51 | ) |
| 52 | monkeypatch.setattr( |
| 53 | ModelExplorerConfig, "add_model_from_pytorch", mock_add_model_from_pytorch |
| 54 | ) |
| 55 | monkeypatch.setattr( |
| 56 | visualization_utils, "visualize_from_config", mock_visualize_from_config |
| 57 | ) |
| 58 | yield monkeypatch.context |
| 59 | assert _called_reuse_server, "Did not call reuse_server" |
| 60 | |
| 61 | |
| 62 | class Linear(torch.nn.Module): |
no outgoing calls
no test coverage detected