Example #1
0
def test_generate_version_mismatch_warning_mismatched_version_error(get_distribution_mock,
                                                                    warnings_mock):
    """Test the ``generate_version_mismatch_warning`` method with one mismatched version.

    Expect that if we error out when trying to get the current package version for one
    package, we treat that as a mismatch and the proper warning is thrown.

    Setup:
        - Mock ``pkg_resources.get_distribution`` to return the same versions, except for one,
          which errors out.
    Input:
        - package versions mapping
    Side Effect:
        - warning
    """
    # Setup
    dist_mock = Mock()
    get_distribution_mock.side_effect = [dist_mock, pkg_resources.ResolutionError()]
    package_versions = {'sdv': dist_mock.version, 'rdt': 'rdt_version'}
    expected_str = ('The libraries used to create the model have older versions than your '
                    'current setup. This may cause errors when sampling.\nrdt used version '
                    '`rdt_version`; current version is ``')

    # Run
    throw_version_mismatch_warning(package_versions)

    # Assert
    assert get_distribution_mock.hass_calls([call('sdv'), call('rdt')])
    assert warnings_mock.warn.called_once_with(expected_str)
Example #2
0
File: base.py Project: sdv-dev/SDV
    def load(cls, path):
        """Load a model from a given path.

        Args:
            path (str):
                Path from which to load the instance.
        """
        with open(path, 'rb') as f:
            model = pickle.load(f)
            throw_version_mismatch_warning(
                getattr(model, '_package_versions', None))

            return model
Example #3
0
def test_generate_version_mismatch_warning_no_package_versions(warnings_mock):
    """Test the ``generate_version_mismatch_warning`` method with None as input.

    Expect that if the model didn't have a `_package_versions` attribute, we throw
    a generic warning.

    Input:
        - package versions is None
    Side Effect:
        - Generic warning is thrown.
    """
    # Setup
    package_versions = None
    expected_str = ('The libraries used to create the model have older versions than your '
                    'current setup. This may cause errors when sampling.')

    # Run
    throw_version_mismatch_warning(package_versions)

    # Assert
    assert warnings_mock.warn.called_once_with(expected_str)
Example #4
0
def test_throw_version_mismatch_warning_no_mismatches(get_distribution_mock, warnings_mock):
    """Test the ``generate_version_mismatch_warning`` method with no mismatched versions.

    Expect that None is returned.

    Setup:
        - Mock ``pkg_resources.get_distribution`` to return the same versions.
    Input:
        - package versions mapping
    Output:
        - None
    """
    # Setup
    dist_mock = Mock()
    get_distribution_mock.side_effect = [dist_mock, dist_mock]
    package_versions = {'sdv': dist_mock.version, 'rdt': dist_mock.version}

    # Run
    throw_version_mismatch_warning(package_versions)

    # Assert
    assert get_distribution_mock.hass_calls([call('sdv'), call('rdt')])
    assert warnings_mock.warn.call_count == 0