Ejemplo n.º 1
0
def test_system_info(monkeypatch):
    # Make sure lazy-loading of the system_info works
    mock_system_info = Mock()
    mock_mc = Mock()
    mock_mc.get_system_info.return_value = mock_system_info
    e = Experiment(mock_mc)

    # First time the system info should be fetched
    assert not mock_mc.get_system_info.called
    assert e.system_info is mock_system_info
    assert mock_mc.get_system_info.called
    mock_mc.get_system_info.reset_mock()

    # Next time it shouldn't
    assert e.system_info is mock_system_info
    assert not mock_mc.get_system_info.called

    # It shouldn't if set manually either...
    mock_machine2 = Mock()
    e.system_info = mock_machine2
    assert e.system_info is mock_machine2
    assert not mock_mc.get_system_info.called

    # It should if reset manually
    e.system_info = None
    assert e.system_info is mock_system_info
    assert mock_mc.get_system_info.called
Ejemplo n.º 2
0
def test_system_info(monkeypatch):
    # Make sure lazy-loading of the system_info works
    mock_system_info = Mock()
    mock_mc = Mock()
    mock_mc.get_system_info.return_value = mock_system_info
    e = Experiment(mock_mc)

    # First time the system info should be fetched
    assert not mock_mc.get_system_info.called
    assert e.system_info is mock_system_info
    assert mock_mc.get_system_info.called
    mock_mc.get_system_info.reset_mock()

    # Next time it shouldn't
    assert e.system_info is mock_system_info
    assert not mock_mc.get_system_info.called

    # It shouldn't if set manually either...
    mock_machine2 = Mock()
    e.system_info = mock_machine2
    assert e.system_info is mock_machine2
    assert not mock_mc.get_system_info.called

    # It should if reset manually
    e.system_info = None
    assert e.system_info is mock_system_info
    assert mock_mc.get_system_info.called
Ejemplo n.º 3
0
def test_machine(monkeypatch):
    # Make sure requesting the machine works, is read-only and produces a
    # deprecation warning.
    from network_tester import experiment
    mock_system_info = Mock()
    mock_machine = Mock()
    mock_build_machine = Mock(return_value=mock_machine)
    mock_mc = Mock()
    monkeypatch.setattr(experiment, "build_machine", mock_build_machine)

    e = Experiment(mock_mc)
    e.system_info = mock_system_info

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")

        # Machine object should be returned built from the system info.
        assert not mock_build_machine.called
        assert e.machine is mock_machine
        mock_build_machine.called_once_with(mock_system_info)

        # Should be flagged as deprecated
        assert len(w) == 1
        assert issubclass(w[0].category, DeprecationWarning)

    # Machine should be regenerated every time (i.e. is explicitly read-only)
    mock_build_machine.reset_mock()
    assert e.machine is mock_machine
    mock_build_machine.called_once_with(mock_system_info)
Ejemplo n.º 4
0
def test_machine(monkeypatch):
    # Make sure requesting the machine works, is read-only and produces a
    # deprecation warning.
    from network_tester import experiment
    mock_system_info = Mock()
    mock_machine = Mock()
    mock_build_machine = Mock(return_value=mock_machine)
    mock_mc = Mock()
    monkeypatch.setattr(experiment, "build_machine", mock_build_machine)

    e = Experiment(mock_mc)
    e.system_info = mock_system_info

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")

        # Machine object should be returned built from the system info.
        assert not mock_build_machine.called
        assert e.machine is mock_machine
        mock_build_machine.called_once_with(mock_system_info)

        # Should be flagged as deprecated
        assert len(w) == 1
        assert issubclass(w[0].category, DeprecationWarning)

    # Machine should be regenerated every time (i.e. is explicitly read-only)
    mock_build_machine.reset_mock()
    assert e.machine is mock_machine
    mock_build_machine.called_once_with(mock_system_info)