def test_fix_pin_detects_version_conflict():
    """Check that package x can't be locked to versions 1 and 2"""
    env = lock.Environment('', ignore={'x': '1'})
    ignored_pin = env.fix_pin('x==1')
    assert ignored_pin is None
    with pytest.raises(RuntimeError):
        env.fix_pin('x==2')
def test_parse_references(name, refs):
    """Check references are parsed for sample files"""
    env = lock.Environment('')
    result = env.parse_references(
        os.path.join('requirements', name)
    )
    assert result == refs
def test_forbid_post_releases():
    """Test postXXX versions are kept if allow_post=True"""
    pin = 'pycodestyle==2.3.1.post2231  # via flake8'
    env = lock.Environment('', forbid_post=True)
    result = env.fix_pin(pin)
    assert result == PIN
def test_post_releases_are_kept_by_default():
    """Test postXXX versions are truncated to release"""
    pin = 'pycodestyle==2.3.1.post2231  # via flake8'
    env = lock.Environment('')
    result = env.fix_pin(pin)
    assert result == pin
def test_pin_is_ommitted_if_set_to_ignore():
    """Test ignored files won't pass"""
    env = lock.Environment('', ignore={'pycodestyle': '2.3.1'})
    result = env.fix_pin(PIN)
    assert result is None
def test_no_fix_incompatible_pin():
    """Test dependency is left unchanged be default"""
    env = lock.Environment('')
    result = env.fix_pin(PIN)
    assert result == PIN
def test_fix_compatible_pin():
    """Test == is replaced with ~= for compatible dependencies"""
    env = lock.Environment('xxx')
    with mock.patch.dict(lock.OPTIONS, {'compatible_patterns': ['pycode*']}):
        result = env.fix_pin(PIN)
    assert result == CMPT